https://github.com/dannyben/clipper
Pure Command Line Arguments Parser
https://github.com/dannyben/clipper
Last synced: over 1 year ago
JSON representation
Pure Command Line Arguments Parser
- Host: GitHub
- URL: https://github.com/dannyben/clipper
- Owner: DannyBen
- License: mit
- Created: 2019-11-14T10:02:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-11-14T12:09:43.000Z (over 6 years ago)
- Last Synced: 2024-10-19T15:59:54.547Z (over 1 year ago)
- Language: Crystal
- Homepage: https://dannyben.github.io/clipper/
- Size: 28.3 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Clipper - Pure Command Line Arguments Parser
[](https://travis-ci.com/DannyBen/clipper)
Clipper is a small wrapper around the standard `OptionParser` with these
conceptual changes:
1. It supports positional arguments (commands or positional parameters).
2. It simply returns a hash of all the expected flags and positional
arguments.
3. It is designed to let you separate the command line parsing from your
actual implementation.
4. It does not concern itself with any help or usage strings - you need to
bring your own.
5. It stays out of your way.
Clipper does not assume anything about how you wish to build your command
line utility, or how you wish to display its usage.
## Installation
Add the dependency to your `shard.yml`:
```yaml
dependencies:
clipper:
github: dannyben/clipper
```
Then run `shards install`
## Usage
Clipper contains three methods only:
- `#flag` - specify which flags are expected.
- `#arg` - specify which positional arguments are expected.
- `#parse` - convert the `ARGV` array to a Hash of all expected and actual
options.
```crystal
require "clipper"
# Create a clipper instance:
clipper = Clipper.new
# Specify which flags are expected, using one of these general patterns:
clipper.flag "--cache", "-c"
clipper.flag "--long-only"
clipper.flag "--port PORT", "-p PORT", default: "3000"
# If you care about any positional arguments, give them a name by using this
# pattern:
clipper.arg "command"
# Finally, parse the options:
options = clipper.parse
# => {"--cache" => false, "--long-only" => false,
# => "--port" => "3000", "command" => false}
options = clipper.parse ["--cache", "-p", "4567"]
# => {"--cache" => true, "--long-only" => false,
# => "--port" => "4567", "command" => false}
options = clipper.parse ["download"]
# => {"--cache" => true, "--long-only" => false,
# => "--port" => "4567", "command" => "download"}
```
For more advanced examples, see the
[examples folder](https://github.com/DannyBen/clipper/tree/master/examples).