Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/cliPublic

🖥 Wrap the standard flag package for a cleaner CLI

License

NotificationsYou must be signed in to change notification settings

gowww/cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gowww cliGoDocBuildCoverageGo ReportStatus Testing

Packagecli wraps the standardflag package for a cleaner command line interface.

Installing

  1. Get package:

    go get -u github.com/gowww/cli
  2. Import it in your code:

    import"github.com/gowww/cli"

Usage

Henceforth, by "command" we mean "subcommand" (like thebuild part ingo build)…

The order in which you define commands and flags is important!
When you define a main flag, it will be added to the top-level flag set but also to all commands already defined.

Obviously, each command can also define its own flags.

For the sake of clarity for the developer and ease of use for the final user, the usage pattern is simple and always the same :program [command] [flags]. No flags before command, and no commands of commands.

Example

package mainimport"github.com/gowww/cli"var (flagForMainstring// Flag "-m"flagForCommandstring// Flag "-c"flagForAllstring// Flag "-a")funcmain() {cli.SetUsageText("Command line interface example.")cli.String(&flagForMain,"m","","Example flag for main function.")cli.Command("command",command,"Example command.").String(&flagForCommand,"c","",`Example flag for this command only.`)cli.String(&flagForAll,"a","","Example flag for main function and all commands defined previously.")cli.Parse()}funccommand() {// Do the command job.}

Usage output

Forexample -help
Command line interface example.Usage:example [command] [flags]Commands:command  Example command.Flags:-a  Example flag for main function and all commands defined previously.-m  Example flag for main function.
Forexample command -help
Example command.Usage:example command [flags]Flags:-a  Example flag for main function and all commands defined previously.-c  Example flag for this command only.

About

🖥 Wrap the standard flag package for a cleaner CLI

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp