diff --git a/doc.go b/doc.go index 694a978..2d67083 100644 --- a/doc.go +++ b/doc.go @@ -3,8 +3,7 @@ // See the file LICENSE in this distribution for more details. /* -Package github.com/sttk/cliargs is a library to parse command line -arguments. +Package github.com/sttk/cliargs is a library to parse command line arguments. # Parse without configurations @@ -15,8 +14,8 @@ command arguments. Command line arguments starting with - or -- are options, and others are command arguments. -If you want to specify a value to an option, follows "=" after the option like -foo=123. +If you want to specify a value to an option, follows "=" and the value after +the option, like foo=123. All command line arguments after -- are command arguments, even they starts with - or --. @@ -211,8 +210,10 @@ The following help text is generated from the above optCfgs (without Help#Print # Parse command line arguments including sub commands -This library provides the function FindFirstArg which returns an index, an argument, an existent flag. -This function can be used to parse command line arguments including sub commands, as follows: +This library provides the function FindFirstArg which returns an index, an +argument, an existent flag. +This function can be used to parse command line arguments including sub +commands, as follows: i, arg, exists := cliargs.FindFirstArg(osArgs) if !exists { return } diff --git a/parse-for.go b/parse-for.go index 0eb68d6..885c1d1 100644 --- a/parse-for.go +++ b/parse-for.go @@ -17,6 +17,7 @@ import ( // command line arguments, is not a pointer. type OptionStoreIsNotChangeable struct{} +// Error is the method to retrieve the message of this error. func (e OptionStoreIsNotChangeable) Error() string { return "OptionStoreIsNotChangeable{}" } @@ -31,12 +32,14 @@ type FailToParseInt struct { cause error } +// Error is the method to retrieve the message of this error. func (e FailToParseInt) Error() string { return fmt.Sprintf("FailToParseInt{"+ "Option:%s,Field:%s,Input:%s,BitSize:%d,cause:%s}", e.Option, e.Field, e.Input, e.BitSize, e.cause.Error()) } +// Unwrap is the method to retrieve an error that caused this error. func (e FailToParseInt) Unwrap() error { return e.cause } @@ -51,12 +54,14 @@ type FailToParseUint struct { cause error } +// Error is the method to retrieve the message of this error. func (e FailToParseUint) Error() string { return fmt.Sprintf("FailToParseUint{"+ "Option:%s,Field:%s,Input:%s,BitSize:%d,cause:%s}", e.Option, e.Field, e.Input, e.BitSize, e.cause.Error()) } +// Unwrap is the method to retrieve an error that caused this error. func (e FailToParseUint) Unwrap() error { return e.cause } @@ -71,12 +76,14 @@ type FailToParseFloat struct { cause error } +// Error is the method to retrieve the message of this error. func (e FailToParseFloat) Error() string { return fmt.Sprintf("FailToParseFloat{"+ "Option:%s,Field:%s,Input:%s,BitSize:%d,cause:%s}", e.Option, e.Field, e.Input, e.BitSize, e.cause.Error()) } +// Unwrap is the method to retrieve an error that caused this error. func (e FailToParseFloat) Unwrap() error { return e.cause } @@ -90,6 +97,7 @@ type IllegalOptionType struct { Type reflect.Type } +// Error is the method to retrieve the message of this error. func (e IllegalOptionType) Error() string { return fmt.Sprintf("IllegalOptionType{"+ "Option:%s,Field:%s,Type:%s}", @@ -133,10 +141,10 @@ func (e IllegalOptionType) Error() string { // before the open square bracket, like :[elem1:elem2:elem3]. // It's useful when some array elements include commas. // -// NOTE: A default value of a string array option in a struct tag is [], like -// `opt:"name=[]"`, it doesn't represent an array which contains only an empty -// string but an empty array. -// If you want to specify an array which contains only an empty string, write +// NOTE: A default value of an empty string array option in a struct tag is [], +// like `opt:"name=[]"`, it doesn't represent an array which contains only one +// empty string but an empty array. +// If you want to specify an array which contains only one empty string, write // nothing after "=" mark, like `opt:"name="`. func ParseFor(osArgs []string, options any) (Cmd, []OptCfg, error) { optCfgs, err := MakeOptCfgsFor(options) diff --git a/parse-with.go b/parse-with.go index b13e728..2f58579 100644 --- a/parse-with.go +++ b/parse-with.go @@ -100,7 +100,7 @@ func (e OptionIsNotArray) GetOpt() string { const anyOption = "*" -// OptCfg is the structure that represents an option configuration. +// OptCfg is the struct that represents an option configuration. // An option configuration consists of fields: Name, Aliases, HasArg, // IsArray, Defaults, OnParsed, Desc, and ArgHelp. //