Skip to content

Commit f2e138c

Browse files
authored
Merge pull request akamensky#61 from PeterlitsZo/master
add useful part in README part
2 parents 936811b + 8aabf8f commit f2e138c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,33 @@ You can implement sub-commands in your CLI using `parser.NewCommand()` or go eve
137137
Since parser inherits from command, every command supports exactly same options as parser itself,
138138
thus allowing to add arguments specific to that command or more global arguments added on parser itself!
139139

140+
#### Basic Option Structure
141+
142+
The `Option` structure is declared at `argparse.go`:
143+
```go
144+
type Options struct {
145+
Required bool
146+
Validate func(args []string) error
147+
Help string
148+
Default interface{}
149+
}
150+
```
151+
152+
You can Set `Required` to let it know if it should ask for arguments.
153+
Or you can set `Validate` as a lambda function to make it know while value is valid.
154+
Or you can set `Help` for your beautiful help document.
155+
Or you can set `Default` will set the default value if user does not provide a value.
156+
157+
Example:
158+
```
159+
dirpath := parser.String("d", "dirpath",
160+
&argparse.Options{
161+
Require: false,
162+
Help: "the input files' folder path",
163+
Default: "input",
164+
})
165+
```
166+
140167
#### Caveats
141168

142169
There are a few caveats (or more like design choices) to know about:

0 commit comments

Comments
 (0)