Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add useful part in README part #61

Merged
merged 3 commits into from
Apr 22, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,33 @@ You can implement sub-commands in your CLI using `parser.NewCommand()` or go eve
Since parser inherits from command, every command supports exactly same options as parser itself,
thus allowing to add arguments specific to that command or more global arguments added on parser itself!

#### Basic Option Structure

The `Option` structure is declared at `argparse.go`:
```go
type Options struct {
Required bool
Validate func(args []string) error
Help string
Default interface{}
}
```

You can Set `Required` to let it know if it should ask for arguments.
Or you can set `Validata` as a lambda function to make it know while value is valid.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Validate

Or you can set `Help` for your beautiful help document.
Or you can set `Default` will set the default value if user do not give your programme a value.
Copy link
Owner

@akamensky akamensky Apr 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if user does not provide a value


Example:
```
dirpath := parser.String("d", "dirpath",
&argparse.Options{
Require: false,
Help: "the input files' folder path",
Default: "input",
})
```

#### Caveats

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