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

Top 8.2% on proxy.golang.org

proxy.golang.org : github.com/akutz/gotopt

Package gotopt is a pure-go port of the GNU C getopt library https://goo.gl/cQI7VN. This package also includes functionality built on top of the getopt port, such as: * Parser, a channel-based parser for receiving options as they are parsed along with a navigable, doubly-linked list of the parser state at the time which the option was parsed. * The package "github.com/akutz/gotopt/flag", a drop-in replacement for the golang stdlib "flag" package (https://goo.gl/gKusxh) as well as its de facto replacement package, "pflag" (https://goo.gl/9wvL9j). It is also possible to entirely ignore all of the additional features and use purely the same logic one would with the original getopt functions. The following example parses the command line using the traditional, getopt logic: The following text will be printed to stdout: The above example can be executed locally by executing the following command in a shell from inside a cloned version of this repository: The example uses standard getopt loop to process arguments using an option string until the return value is -1. The OptInd, OptArg, OptOpt, and OptErr fields exist just as they do in the original getopt library. It's also possible to use the NewGetOptParser to create an instance of the GetOptParser type in order to parse multiple argument slices in multiple goroutines instead of the thread-unsafe, package-level GetOpt, GetOptLong, and GetOptLongOnly functions. The GetOptParser type exposed all of the same functions as well as instance-specific versions of the OptInd, OptArg, OptOpt, and OptErr fields. For more information on the way the getopt loop behaves, the option string format, or anything else related to the getopt logic, please see http://goo.gl/uXjKx9. This package introduces new functionality build on top of getopt, starting with the type Parser. Using the NewParser function, a Parser is created that can be used to parse multiple argument slices across multiple goroutines. However, unlike the GetOpt loop, Parser returns a channel from the Parse function that receives options as they are parsed. Specifically, the channel receives ParserState instances, which may indicate an Option has been parsed, an error has occurred, or if there are no more options remaining, and there are any non-option arguments, an array of strings: The following text will be printed to stdout: The above example can be executed locally by executing the following command in a shell from inside a cloned version of this repository: The Parser interface also defines the function ParseAll. Using Parse internally, ParseAll doesn't return until all of the options and their arguments have been parsed. ParseAll returns the last, received ParserState, which can then be used to traverse the list of parsed data: The following text will be printed to stdout: The above example can be executed locally by executing the following command in a shell from inside a cloned version of this repository:

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/akutz/gotopt
License: Apache-2.0
Latest release: over 9 years ago
First release: over 9 years ago
Namespace: github.com/akutz
Stars: 4 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 29 days ago

    Loading...
    Readme
    Loading...