Files
kong/_examples/docker/main.go
T
Alec Thomas 6408010083 Clean up disparity between Context and Kong.
Previously, there was a confusing mix of functionality shared between
the two wherein you would need to use the Kong type for printing errors,
etc. but it did not have access to the context in order to print
context-sensitive usage information. This has been fixed.

Additionally, there are now fuzzy correction suggestions for flags and
commands

Also added a server example which shows how Kong can be used for parsing
in interactive shells. Run with:

    $ go run ./_examples/server/*.go

Then interact with:

    $ ssh -p 6740 127.0.0.1
2018-06-27 09:11:11 +10:00

84 lines
4.4 KiB
Go

// nolint
package main
import (
"github.com/alecthomas/kong"
)
type Globals struct {
Config string `help:"Location of client config files" default:"~/.docker" type:"path"`
Debug bool `short:"D" help:"Enable debug mode"`
Host []string `short:"H" help:"Daemon socket(s) to connect to"`
LogLevel string `short:"l" help:"Set the logging level (debug|info|warn|error|fatal)" default:"info"`
TLS bool `help:"Use TLS; implied by --tls-verify"`
TLSCACert string `name:"tls-ca-cert" help:"Trust certs signed only by this CA" default:"~/.docker/ca.pem" type:"path"`
TLSCert string `help:"Path to TLS certificate file" default:"~/.docker/cert.pem" type:"path"`
TLSKey string `help:"Path to TLS key file" default:"~/.docker/key.pem" type:"path"`
TLSVerify bool `help:"Use TLS and verify the remote"`
}
type CLI struct {
Globals
VersionFlag bool `name:"version" help:"Print version information and quit"`
Attach AttachCmd `cmd help:"Attach local standard input, output, and error streams to a running container"`
Build BuildCmd `cmd help:"Build an image from a Dockerfile"`
Commit CommitCmd `cmd help:"Create a new image from a container's changes"`
Cp CpCmd `cmd help:"Copy files/folders between a container and the local filesystem"`
Create CreateCmd `cmd help:"Create a new container"`
Deploy DeployCmd `cmd help:"Deploy a new stack or update an existing stack"`
Diff DiffCmd `cmd help:"Inspect changes to files or directories on a container's filesystem"`
Events EventsCmd `cmd help:"Get real time events from the server"`
Exec ExecCmd `cmd help:"Run a command in a running container"`
Export ExportCmd `cmd help:"Export a container's filesystem as a tar archive"`
History HistoryCmd `cmd help:"Show the history of an image"`
Images ImagesCmd `cmd help:"List images"`
Import ImportCmd `cmd help:"Import the contents from a tarball to create a filesystem image"`
Info InfoCmd `cmd help:"Display system-wide information"`
Inspect InspectCmd `cmd help:"Return low-level information on Docker objects"`
Kill KillCmd `cmd help:"Kill one or more running containers"`
Load LoadCmd `cmd help:"Load an image from a tar archive or STDIN"`
Login LoginCmd `cmd help:"Log in to a Docker registry"`
Logout LogoutCmd `cmd help:"Log out from a Docker registry"`
Logs LogsCmd `cmd help:"Fetch the logs of a container"`
Pause PauseCmd `cmd help:"Pause all processes within one or more containers"`
Port PortCmd `cmd help:"List port mappings or a specific mapping for the container"`
Ps PsCmd `cmd help:"List containers"`
Pull PullCmd `cmd help:"Pull an image or a repository from a registry"`
Push PushCmd `cmd help:"Push an image or a repository to a registry"`
Rename RenameCmd `cmd help:"Rename a container"`
Restart RestartCmd `cmd help:"Restart one or more containers"`
Rm RmCmd `cmd help:"Remove one or more containers"`
Rmi RmiCmd `cmd help:"Remove one or more images"`
Run RunCmd `cmd help:"Run a command in a new container"`
Save SaveCmd `cmd help:"Save one or more images to a tar archive (streamed to STDOUT by default)"`
Search SearchCmd `cmd help:"Search the Docker Hub for images"`
Start StartCmd `cmd help:"Start one or more stopped containers"`
Stats StatsCmd `cmd help:"Display a live stream of container(s) resource usage statistics"`
Stop StopCmd `cmd help:"Stop one or more running containers"`
Tag TagCmd `cmd help:"Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE"`
Top TopCmd `cmd help:"Display the running processes of a container"`
Unpause UnpauseCmd `cmd help:"Unpause all processes within one or more containers"`
Update UpdateCmd `cmd help:"Update configuration of one or more containers"`
Version VersionCmd `cmd help:"Show the Docker version information"`
Wait WaitCmd `cmd help:"Block until one or more containers stop, then print their exit codes"`
}
func main() {
cli := CLI{}
ctx := kong.Parse(&cli,
kong.Name("docker"),
kong.Description("A self-sufficient runtime for containers"),
kong.UsageOnError(),
kong.ConfigureHelp(kong.HelpOptions{
Compact: true,
}),
//
kong.Hook(&cli.VersionFlag, func(ctx *kong.Context, path *kong.Path) error {
ctx.Printf("1.0.0").Exit(0)
return nil
}))
err := ctx.Run(&cli.Globals)
ctx.FatalIfErrorf(err)
}