Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1nksm committed Apr 29, 2021
1 parent 47e3877 commit cf39acc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 4 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [3.2.0] - 2021-04-30

### Added

- Added the feature to parse options directly by default parser name

## [3.1.0] - 2021-04-29

### Added
Expand Down Expand Up @@ -145,7 +151,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- First release version

[Unreleased]: https://github.com/ko1nksm/getoptions/compare/v3.1.0...HEAD
[Unreleased]: https://github.com/ko1nksm/getoptions/compare/v3.2.0...HEAD
[3.2.0]: https://github.com/ko1nksm/getoptions/compare/v3.1.0...v3.2.0
[3.1.0]: https://github.com/ko1nksm/getoptions/compare/v3.0.0...v3.1.0
[3.0.0]: https://github.com/ko1nksm/getoptions/compare/v2.5.1...v3.0.0
[2.5.1]: https://github.com/ko1nksm/getoptions/compare/v2.5.0...v2.5.1
Expand Down
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ parser_definition() {
disp VERSION --version
}

eval "$(getoptions parser_definition parse) exit 1"
parse "$@"
eval "set -- $REST"
eval "$(getoptions parser_definition -) exit 1"

echo "FLAG: $FLAG, PARAM: $PARAM, OPTION: $OPTION"
printf '%s\n' "$@" # rest arguments
Expand Down Expand Up @@ -190,6 +188,7 @@ The execution speed is slightly slower than using it as a library. (Approx. 15ms

```sh
parser_definition() {
setup REST help:usage -- "Usage: example.sh [options]... [arguments]..."
...
}

Expand All @@ -201,6 +200,23 @@ eval "set -- $REST"
The above code `exit 1` is the recommended option.
This allows you to exit if the `getoptions` command is not found.

If you use `-` as the option parser name, it will define the default option parser
and parse the arguments directly.

```sh
parser_definition() {
setup REST help:usage -- "Usage: example.sh [options]... [arguments]..."
...
}

eval "$(getoptions parser_definition - "$0") exit 1"

# The above means the same as the following code.
# eval "$(getoptions parser_definition getoptions_parse "$0") exit 1"
# getoptions_parse "$@"
# eval "set -- $REST"
```

HINT: Are you wondering why the external command can call a shell function?

The external command `getoptions` will output the shell function `getoptions`.
Expand Down Expand Up @@ -230,6 +246,7 @@ $ gengetoptions library > getoptions.sh
. ./getoptions.sh # Or include it here

parser_definition() {
setup REST help:usage -- "Usage: example.sh [options]... [arguments]..."
...
}

Expand Down
22 changes: 22 additions & 0 deletions docs/References.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [`getoptions` - Generate a function for option parsing](#getoptions---generate-a-function-for-option-parsing)
- [`getoptions_abbr` - Handle abbreviated long options](#getoptions_abbr---handle-abbreviated-long-options)
- [`getoptions_help` - Generate a function to display help](#getoptions_help---generate-a-function-to-display-help)
- [`getoptions_parse` - Default option parser name](#getoptions_parse---default-option-parser-name)
- [Option parser](#option-parser)
- [Option parser definition function](#option-parser-definition-function)
- [Custom error handler](#custom-error-handler)
Expand Down Expand Up @@ -45,6 +46,23 @@ parse "$@" # Option parsing
eval "set -- $REST" # Exclude options from arguments
```

If you use `-` as the option parser name, it will define the default option parser
and parse the arguments directly.

```sh
parser_definition() {
setup REST ...
...
}

eval "$(getoptions parser_definition - "$0") exit 1"

# The above means the same as the following code.
# eval "$(getoptions parser_definition getoptions_parse "$0") exit 1"
# getoptions_parse "$@"
# eval "set -- $REST"
```

### `getoptions_abbr` - Handle abbreviated long options

This function is called automatically by `getoptions` with the `abbr` attribute,
Expand Down Expand Up @@ -73,6 +91,10 @@ eval "$(getoptions_help parser_definition usage)"
usage
```

### `getoptions_parse` - Default option parser name

This is the default option parser name defined when `-` is specified as the option parser name.

## Option parser

This is a function for parsing options, which is generated by `getoptions`
Expand Down

0 comments on commit cf39acc

Please sign in to comment.