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

Top 2.4% on proxy.golang.org
Top 0.3% dependent packages on proxy.golang.org
Top 0.5% dependent repos on proxy.golang.org
Top 5.2% forks on proxy.golang.org
Top 1.7% docker downloads on proxy.golang.org

proxy.golang.org : github.com/pborman/getopt/v2

Package getopt (v2) provides traditional getopt processing for implementing commands that use traditional command lines. The standard Go flag package cannot be used to write a program that parses flags the way ls or ssh does, for example. Version 2 of this package has a simplified API. See the github.com/pborman/options package for a simple structure based interface to this package. Getopt supports functionality found in both the standard BSD getopt as well as (one of the many versions of) the GNU getopt_long. Being a Go package, this package makes common usage easy, but still enables more controlled usage if needed. Typical usage: If you don't want the program to exit on error, use getopt.Getopt: Support is provided for both short (-f) and long (--flag) options. A single option may have both a short and a long name. Each option may be a flag or a value. A value takes an argument. Declaring no long names causes this package to process arguments like the traditional BSD getopt. Short flags may be combined into a single parameter. For example, "-a -b -c" may also be expressed "-abc". Long flags must stand on their own "--alpha --beta" Values require an argument. For short options the argument may either be immediately following the short name or as the next argument. Only one short value may be combined with short flags in a single argument; the short value must be after all short flags. For example, if f is a flag and v is a value, then: For the long value option val: Values with an optional value only set the value if the value is part of the same argument. In any event, the option count is increased and the option is marked as seen. There is no convenience function defined for making the value optional. The SetOptional method must be called on the actual Option. Parsing continues until the first non-option or "--" is encountered. The short name "-" can be used, but it either is specified as "-" or as part of a group of options, for example "-f-". If there are no long options specified then "--f" could also be used. If "-" is not declared as an option then the single "-" will also terminate the option processing but unlike "--", the "-" will be part of the remaining arguments. Normally the parsing is performed by calling the Parse function. If it is important to see the order of the options then the Getopt function should be used. The standard Parse function does the equivalent of: When calling Getopt it is the responsibility of the caller to print any errors. Normally the default option set, CommandLine, is used. Other option sets may be created with New. After parsing, the sets Args will contain the non-option arguments. If an error is encountered then Args will begin with argument that caused the error. It is valid to call a set's Parse a second time to amen flags or values. As an example: If called with set to { "prog", "-a", "cmd", "-b", "arg" } then both and and b would be set, cmd would be set to "cmd", and opts.Args() would return { "arg" }. Unless an option type explicitly prohibits it, an option may appear more than once in the arguments. The last value provided to the option is the value. An option marked as mandatory and not seen when parsing will cause an error to be reported such as: "program: --name is a mandatory option". An option is marked mandatory by using the Mandatory method: Mandatory options have (required) appended to their help message: Options can be marked as part of a mutually exclusive group. When two or more options in a mutually exclusive group are both seen while parsing then an error such as "program: options -a and -b are mutually exclusive" will be reported. Mutually exclusive groups are declared using the SetGroup method: A set can have multiple mutually exclusive groups. Mutually exclusive groups are identified with their group name in {}'s appeneded to their help message: The Flag and FlagLong functions support most standard Go types. For the list, see the description of FlagLong below for a list of supported types. There are also helper routines to allow single line flag declarations. These types are: Bool, Counter, Duration, Enum, Int16, Int32, Int64, Int, List, Signed, String, Uint16, Uint32, Uint64, Uint, and Unsigned. Each comes in a short and long flavor, e.g., Bool and BoolLong and include functions to set the flags on the standard command line or for a specific Set of flags. Except for the Counter, Enum, Signed and Unsigned types, all of these types can be declared using Flag and FlagLong by passing in a pointer to the appropriate type. A pointer to any type that implements the Value interface may be passed to Flag or FlagLong. All non-flag options are created with a "valuehelp" as the last parameter. Valuehelp should be 0, 1, or 2 strings. The first string, if provided, is the usage message for the option. If the second string, if provided, is the name to use for the value when displaying the usage. If not provided the term "value" is assumed. The usage message for the option created with is is

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/pborman/getopt/v2
Keywords: getopt , go
License: BSD-3-Clause
Latest release: over 4 years ago
First release: over 4 years ago
Namespace: github.com/pborman/getopt
Dependent packages: 170
Dependent repositories: 183
Stars: 113 on GitHub
Forks: 17 on GitHub
Docker dependents: 11
Docker downloads: 975
See more repository details: repos.ecosyste.ms
Last synced: 7 days ago

    Loading...
    Readme
    Loading...