Skip to content

Commit

Permalink
comment: modified some comments (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Mar 17, 2024
1 parent 683c2b6 commit 842c4c5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
13 changes: 7 additions & 6 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 --.
Expand Down Expand Up @@ -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 }
Expand Down
16 changes: 12 additions & 4 deletions parse-for.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}"
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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}",
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion parse-with.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down

0 comments on commit 842c4c5

Please sign in to comment.