Skip to content

Commit 6486936

Browse files
committed
Initial commit
0 parents  commit 6486936

30 files changed

+3440
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"editor.formatOnSave": true
3+
}

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Changelog
2+
3+
> - v0.0.1, 26.11.2020 -- Initial release.

CONTRIBUTING.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contributing
2+
3+
There are many ways to contribute:
4+
5+
1. Open a new bug report, feature request or just ask a question by opening a new issue.
6+
2. Participate in the discussions of issues, pull requests and verify/test fixes of new features.
7+
3. Submit your own fixes or features as a pull request.
8+
4. Submit test cases.
9+
10+
When contributing to this repository, please note, that we have a code of conduct. \
11+
Please follow it in all your interactions with the project.
12+
13+
## Code of Conduct
14+
15+
## Versioning
16+
17+
We use `<MAJOR>.<MINOR>.<PATCH>` as versioning policy.
18+
19+
```
20+
<Major> = Breaking Changes
21+
<Minor> = Backwards Compatible / New Features
22+
<Patch> = Backwards Compatible / Bug Fixes
23+
```
24+
25+
For the versions available, see the [tags on this repository](https://github.com/netcloudag/powershell-cli-menu-helpers/tags).
26+
27+
### Coding Convention
28+
29+
- The code is structured according to the Clean Code paradigm
30+
- Code and Documentation is written in English
31+
- At least UnitTests are written
32+
- A useful exception handling is available
33+
- A useful logging is available
34+
- If foreign code is used, no license agreements have been broken.
35+
36+
### Our Responsibilities
37+
38+
Project maintainers are responsible for clarifying the standards of acceptable \
39+
behavior and are expected to take appropriate and fair corrective action in \
40+
response to any instances of unacceptable behavior.

LICENSE.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# License
2+
3+
MIT License
4+
5+
Copyright (c) 2020 Netcloud AG
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in all
15+
copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23+
SOFTWARE.

PSScriptAnalyzerSettings.psd1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@{
2+
ExcludeRules = @('PSAvoidUsingWriteHost')
3+
}

README.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# powershell cli menu helpers
2+
3+
[[_TOC_]]
4+
5+
## Introduction
6+
7+
PowerShell CLI Menu Helpers is a module which offers few helpers functions to:
8+
9+
- Render a menu inside a PowerShell CLI with options (exit and back)
10+
11+
![Example menu](./assets/images/example_menu.jpg)
12+
13+
- Select items from a list witch options (cancel, filter, multiselect, etc.)
14+
15+
![Example menu](./assets/images/example_select-from-list.jpg)
16+
17+
- Select items from a table witch options (cancel, filter, multiselect, etc.)
18+
19+
![Example menu](./assets/images/example_select-from-table.jpg)
20+
21+
## Installation
22+
23+
### From PowerShell Gallery
24+
25+
```powershell
26+
Install-Module -Name 'powershell-cli-menu-helpers'
27+
```
28+
29+
### From Source
30+
31+
- Obtain the source
32+
33+
```
34+
git clone https://github.com/netcloudag/powershell-cli-menu-helpers
35+
```
36+
37+
- Navigate to the source directory
38+
39+
```
40+
cd path\to\powershell-cli-menu-helpers
41+
```
42+
43+
- Test
44+
45+
```
46+
.\test.ps1
47+
```
48+
49+
- Build
50+
51+
```
52+
.\build.ps1
53+
```
54+
55+
- Import the module
56+
57+
```
58+
Import-Module -Name '.\build\powershell-cli-menu-helpers'
59+
```
60+
61+
## Usage
62+
63+
### Menu rendering
64+
65+
Use the function `Select-MenuEntryFromList` to render a menu inside the cli. \
66+
The function provides an `ExitOption` and a `BackOption` option. \
67+
This will allow to perform the needed action based on the returned value. \
68+
Take also a look at `Get-Help -Name Select-MenuEntryFromList -Full` for furhter details.
69+
70+
```powershell
71+
# Render a menu with back and exit option
72+
# Set the menu title and the menu entries
73+
[System.String[]]$MenuEntries = @('Menu 1', 'Menu 2', 'Menu 3')
74+
[System.String]$MenuTitle = "=============== Test Menu ==============="
75+
76+
# Ask user for the menu entry
77+
[PSCustomObject]$SelectedMenuEntry = Select-MenuEntryFromList -MenuTitle $MenuTitle -MenuEntries $MenuEntries -ExitOption -BackOption
78+
79+
# Do the action based on the selection
80+
switch ($SelectedMenuEntry.State)
81+
{
82+
'%OK%'
83+
{
84+
Write-Host -Object "Selected menu entry: $($SelectedMenuEntry.MenuEntry)"
85+
}
86+
87+
'%BACK%'
88+
{
89+
Write-Host -Object "Back option selected"
90+
}
91+
92+
'%EXIT%'
93+
{
94+
Write-Host -Object "Exit option selected"
95+
}
96+
}
97+
```
98+
99+
### List rendering
100+
101+
Use the function `Select-ItemFromList` to render a list inside the cli. \
102+
The function provides various options like `MultiselectOption` or `FilterOption`. \
103+
Take also a look at `Get-Help -Name Select-ItemFromList -Full` for furhter details.
104+
105+
```powershell
106+
# Select multiple processes to get furhter detailes later
107+
$Processes = Select-ItemFromList -ListTitle "Select process, press 'd' if done" -Items (Get-Process | Select-Object -First 10) -PropertyName 'ProcessName' -MultiselectOption -CancelOption -FilterOption
108+
if ($Processes.State -eq '%OK%')
109+
{
110+
foreach ($Process in $Processes.Items)
111+
{
112+
$Process | Select-Object -Property Id, ProcessName
113+
}
114+
}
115+
```
116+
117+
### Table rendering
118+
119+
Use the function `Select-ItemFromTable` to render a table inside the cli. \
120+
The function provides various options like `MultiselectOption` or `FilterOption`. \
121+
Take also a look at `Get-Help -Name Select-ItemFromTable -Full` for furhter details.
122+
123+
```powershell
124+
# Select multiple processes to get furhter detailes later
125+
$Processes = Select-ItemFromTable -TableTitle "Select process, press 'd' if done" -Items (Get-Process | Select-Object -First 10) -PropertyName 'Id', 'Handles', 'ProcessName' -MultiselectOption -CancelOption -FilterOption
126+
if ($Processes.State -eq '%OK%')
127+
{
128+
foreach ($Process in $Processes.Items)
129+
{
130+
$Process
131+
}
132+
}
133+
```
134+
135+
## Example
136+
137+
An example powershell cli menu is provided under `.\example`. \
138+
It shows how to combine the functions to display a powrshell cli menu and perfome actions. \
139+
140+
```powershell
141+
cd .\example\
142+
.\menu_script.ps1
143+
```
144+
145+
![Example menu](./assets/images/example_menu.jpg)
146+
147+
## Contributing
148+
149+
Contributions are welcome, please refere to [CONTRIBUTING.md](https://github.com/netcloudag/powershell-cli-menu-helpers/CONTRIBUTING.md) for details.
150+
151+
## Creating a release
152+
153+
### Requirements
154+
155+
```powershell
156+
Install-Module -Name 'Pester'
157+
Install-Module -Name 'PSScriptAnalyzer'
158+
```
159+
160+
### Steps
161+
162+
- Add / modify the test cases inside the folder `.\tests`
163+
- Run the tests (`.\test.ps1`)
164+
- Update the [CHANGELOG.md](https://github.com/netcloudag/powershell-cli-menu-helpers/CHANGELOG.md)
165+
- Update the `ModuleVersion` inside the [config.json](https://github.com/netcloudag/powershell-cli-menu-helpers/config.json)
166+
- Add release tag on github
167+
- Run the script `.\build.ps1` to create a new build
168+
- Run the scirpt `.\publish.ps1` to publish the build to PowerShell Gallery
169+
170+
## Authors
171+
172+
- **Philipp Knoll** - _Initial idea / Initial work_
173+
- **Patrick Grazioli** - _Implementation_
174+
175+
## License
176+
177+
This project is licensed under MIT with Copyright (c) 2020 Netcloud AG. \
178+
See the [LICENSE.md](https://github.com/netcloudag/powershell-cli-menu-helpers/LICENSE.md) file for details.

assets/images/example_menu.jpg

25.8 KB
Loading
28.6 KB
Loading
43.6 KB
Loading

0 commit comments

Comments
 (0)