An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 5.8% dependent packages on proxy.golang.org
Top 4.7% dependent repos on proxy.golang.org

proxy.golang.org : github.com/jba/cli

Package cli helps to build command-line programs with multiple commands. A command is created by defining a struct with a Run method. The exported fields of the struct are populated with the flags and command-line arguments passed to on the command line, as determined by struct tags. For example, here is a struct that could be used for a "compare" command that takes two files and a "-v" flag: The command's logic is provided in a Run method: Before the Run method is called, the command line flags and arguments are parsed and assigned to the fields of the receiver struct. All commands must be registered, usually at program startup. Begin with a top-level command representing the program itself. Typically no behavior is associated with the top-level command, so the line suffices. The top command uses the default flag set of the standard library's flag package, so global flags can be defined as usual. The value of top is a *cli.Command. Sub-commands are configured by registering a Command struct with an existing Command. Given the compare struct and the top variable shown above, we can register a compare command with or more succinctly, That code can be put in an init method or at the start of main. The Top function takes a Command just like the RegisterCommand function, so you can provide behavior for the top-level command by defining a struct with a Run method, constructing a Command with it, and passing it to Top. The struct associated with a command completely describes the command's flags and positional arguments. Each exported field can have a struct tag with a "cli" key that provides the usage documentation for the argument or flag as well as some options. An exported field without a tag is treated as a positional argument with no documentation. Unexported fields are ignored. A field's type can be any string, bool, integer, floating point or duration type, or a slice of one of those types. If the slice is used for a flag, the flag's value is split on commas to populate the slice. Otherwise, the slice field must represent the last positional argument, and its value is taken from the remaining command-line arguments. The tag syntax is a comma-separated lists of key=value pairs. The keys are: For example, the field and struct tag will display the argument as ENV in documentation along with the string "development environment", and will check that the value on the command line is either "dev" or "prod". See the package examples for more. The Go flag package provides control over the word printed as the flag's value in documentation, by looking for backticks in the usage string. To use this feature, enclose the struct tag in double quotes instead of backticks. As a convenience, this package can interpret bare struct tags that don't have the usual 'key:"value"' format, which makes this cleaner: Once the top-level command has been created and all sub-commands have been registered, call the Main method to invoke the appropriate command and get back an exit code. If the other work has been done with a global "top" variable and init functions, then the entire main function can be For more control, you can call Command.Run with a context and a slice of arguments, and handle the error yourself. Shell completion for common shells is supported with the github.com/posener/complete/v2 package. Completion logic is automatically invoked if your program calls Command.Main. To install completion for a program, run it with the COMP_INSTALL environment variable set to 1.

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/jba/cli
License: MIT
Latest release: over 2 years ago
First release: over 3 years ago
Namespace: github.com/jba
Dependent packages: 1
Dependent repositories: 1
Stars: 0 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 4 days ago

    Loading...
    Readme
    Loading...