optarg

Yet another library for parsing command-line options and arguments
0.1.0 released
mosop/optarg
26 4 3
mosop

optarg

Yet another library for parsing command-line options and arguments, written in the Crystal language.

Installation

Add this to your application's shard.yml:

dependencies:
  optarg:
    github: mosop/optarg

Features

  • Easy Access

    class Model < Optarg::Model
      string "--foo"
    end
    
    result = Model.parse(%w(--foo bar))
    result.foo # => "bar"
    
  • Nilable Accessor

    class Model < Optarg::Model
      string "--foo"
    end
    
    result = Model.parse(%w())
    result.foo? # => nil
    result.foo # raises KeyError
    
  • Default Value

    class Model < Optarg::Model
      string "--foo", default: "bar"
    end
    
    result = Model.parse(%w())
    result.foo # => "bar"
    
  • Boolean Value

    class Model < Optarg::Model
      bool "-b"
    end
    
    result = Model.parse(%w(-b))
    result.b? # => true
    
  • Nagation

    class Model < Optarg::Model
      bool "-b", not: "-B"
    end
    
    result = Model.parse(%w(-B))
    result.b? # => false
    
  • Non-option Arguments

    class Model < Optarg::Model
      string "-s"
      bool "-b"
    end
    
    result = Model.parse(%w(-s foo -b bar -- baz))
    result.args # => ["bar"]
    result.unparsed_args # => ["baz"]
    

Usage

require "optarg"

and see Features.

Development

[WIP]

Contributing

  1. Fork it ( https://github.com/mosop/optarg/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • mosop - creator, maintainer
optarg:
  github: mosop/optarg
  version: ~> 0.1.0
License MIT
Crystal none

Authors

  • mosop

Dependencies 0

Development Dependencies 0

Dependents 1

Last synced .
search fire star recently