Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ps-cli/3-help.ps1
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
53 lines (45 sloc)
1.25 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
This script is an example of how any .ps1 script can provide content to `Get-Help`. | |
.DESCRIPTION | |
USAGE | |
.\3-help.ps1 <command> | |
COMMANDS | |
up run `docker-compose up` | |
down run `docker-compose down` | |
build run `dotnet build` | |
test run `dotnet test` | |
ip get your local ip | |
help, -? show this help message | |
.LINK | |
https://kevinareed.com/2021/04/14/creating-a-command-based-cli-in-powershell/ | |
#> | |
param( | |
[Parameter(Position=0)] | |
[ValidateSet("up", "down", "build", "test", "ip", "help")] | |
# The command to run | |
[string]$Command | |
) | |
function Command-Help { Get-Help $PSCommandPath } | |
if (!$Command) { | |
Command-Help | |
exit | |
} | |
function Command-Up { iex "docker compose up" } | |
function Command-Down { iex "docker compose down" } | |
function Command-Build { iex "dotnet build" } | |
function Command-Test { iex "dotnet test" } | |
function Command-Ip { | |
$ip = iwr "https://api.ip.sb/ip" ` | |
| Select-Object -Expand Content | |
Write-Host "Your IP address is: " -N | |
Write-Host $ip -F Green | |
} | |
switch ($Command) { | |
"up" { Command-Up } | |
"down" { Command-Down } | |
"build" { Command-Build } | |
"test" { Command-Test } | |
"ip" { Command-Ip } | |
"help" { Command-Help } | |
} |