9. Usage: docker [OPTIONS] COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/Users/andrii/.docker")
-D, --debug Enable debug mode
-H, --host list Daemon socket(s) to connect to
...
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
checkpoint Manage checkpoints
config Manage Docker configs
container Manage containers
image Manage images
network Manage networks
...
system Manage Docker
trust Manage trust on Docker images
volume Manage volumes
Commands:
attach Attach local standard input, output, and error streams to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders between a container and the local filesystem
create Create a new container
deploy Deploy a new stack or update an existing stack
diff Inspect changes to files or directories on a container's filesystem
events Get real time events from the server
...
inspect Return low-level information on Docker objects
kill Kill one or more running containers
16. func main() {
var la = flag.String("la", "1 flag", "1 flag in golang.")
flag.Parse()
fmt.Println(*la)
}
➜ golang_for_two ./ls -la
flag needs an argument: -la
Usage of ./ls:
-la string
1 flag in golang. (default "1 flag")
28. Task oriented in practise:
helm3 example of purge default flags
`helm delete --purge` is used
more often than not, so I suggest we
should make it the default convention for
Helm 3.
helm/helm/pull/5283
🔀
34. Examples:
var listExample = `
List of youtube videos you would like to print:
$ youtube list <playlist-id>
`
func newListCmd(out io.Writer) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "list top youtube videos.",
Long: "list top youtube videos.",
Example: listExample ,
}
return cmd
}
35. $ ./ytop list -h
list top youtube videos.
Usage:
ytop list [flags]
Examples:
# List of youtube videos you would like to
print:
$ youtube list <playlist-id>
Flags:
-h, --help help for list
36. Ship your CLI tool to
multiply OS:
🐳
https://raw.githubusercontent.com/YOU/YOURAPP/master/godownloader.sh
🏗
38. Aliases tl;dr:
type Command struct {
// Use is the one-line usage message.
Use string
// Aliases is an array of aliases that can be used instead of the first word in Use.
Aliases []string
$ ytop list --help
Usage:
ytop list [flags]
Aliases:
list, ls, l
39. Default to human output:
VIDEO ID LIKE COUNT TITLE
g8BD-0rIRN4 1232 Ricardo Jimenez - Quicksilver How Cloudflare …
op14_lAifQ4 597 Joan López de la Franca Beltran - From Chaos to …
KEUmOomnEqc 435 Roberto Clapis - Tackling Contention: The Monsters…
KUC5WtbBdFA 97 Johan Brandhorst - Writing REST Services for the ..
43. References:
📹 justforfunc #5: Defining a Color Flag in Go
📹 justforfunc #32: CLI tools with Cobra
📹 GopherCon 2019: Carolyn Van Slyck - Design
Command-Line Tools People Love
📖 The Go Programming Language by Alan A. A.
Donovan, Brian W. Kernighan
📖 Go in Practice by Matt Butcher, Matt Farina