File tree 1 file changed +27
-0
lines changed 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -137,6 +137,33 @@ You can implement sub-commands in your CLI using `parser.NewCommand()` or go eve
137
137
Since parser inherits from command, every command supports exactly same options as parser itself,
138
138
thus allowing to add arguments specific to that command or more global arguments added on parser itself!
139
139
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
+
140
167
#### Caveats
141
168
142
169
There are a few caveats (or more like design choices) to know about:
You can’t perform that action at this time.
0 commit comments