Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/woodruffw/dreck
A stupid parser for trailing arguments.
https://github.com/woodruffw/dreck
argument-parser option-parser ruby type-checking
Last synced: 13 days ago
JSON representation
A stupid parser for trailing arguments.
- Host: GitHub
- URL: https://github.com/woodruffw/dreck
- Owner: woodruffw
- License: other
- Created: 2017-06-22T05:17:48.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-09T00:46:35.000Z (about 4 years ago)
- Last Synced: 2024-12-19T10:17:29.043Z (15 days ago)
- Topics: argument-parser, option-parser, ruby, type-checking
- Language: Ruby
- Homepage: https://rubygems.org/gems/dreck
- Size: 38.1 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
dreck
=====![license](https://raster.shields.io/badge/license-MIT%20with%20restrictions-green.png)
[![Build Status](https://img.shields.io/github/workflow/status/woodruffw/dreck/CI/master)](https://github.com/woodruffw/dreck/actions?query=workflow%3ACI)
[![Gem Version](https://badge.fury.io/rb/dreck.svg)](https://badge.fury.io/rb/dreck)A stupid parser for trailing arguments.
### Motivation
There are lots of good argument parsers for Ruby:
[OptionParser](https://ruby-doc.org/stdlib/libdoc/optparse/rdoc/OptionParser.html),
[Slop](https://github.com/leejarvis/slop), [trollop](https://manageiq.github.io/trollop/),
[cocaine](https://github.com/thoughtbot/cocaine), etc.Most of these are great for parsing and typechecking options, but none provide a good
interface to the arguments that often *trail* the options.Dreck does exactly that. Give it a specification of arguments (and their
types) to expect, and it will give you a nicely typechecked result.### Installation
```bash
$ gem install dreck
```### Usage
Dreck is best used in conjunction with an option parser like
[Slop](https://github.com/leejarvis/slop), which can provide an array of
arguments with options already filtered out:```ruby
opts = Slop.parse do |s|
# ...
endopts.args # => [ "/dev/urandom", "/dev/sda", "512" ]
results = Dreck.parse opts.args, strict: true do
file :input
symbol :output
int :blocksize
endresults[:input] # => "/dev/urandom"
results[:output] # => :"/dev/sda"
results[:blocksize] # => 512
```Lists are also supported:
```ruby
result = Dreck.parse opts.args do
string :uuid
list :file, :inputs, count: 2
list :int, :nums
endresult[:uuid] # => "01aa84ab-5b2c-4861-adc9-fcc6990a5ca5"
result[:inputs] # => ["/tmp/foo", "/tmp/bar"]
result[:nums] # => [1, 2, 3, 4, 5]
```### TODO
* Guarding against multiple unbound lists/unbound list before scalar types
* Custom types?