Coder Social home page Coder Social logo

docopt.jl's Introduction

DocOpt.jl

Build Status

DocOpt.jl is a port of docopt written in the Julia language.

docopt generates a command-line arguments parser from human-readable usage patterns.

You will find how attractive the idea of docopt is with the example below:

doc = """Naval Fate.

Usage:
  naval_fate.jl ship new <name>...
  naval_fate.jl ship <name> move <x> <y> [--speed=<kn>]
  naval_fate.jl ship shoot <x> <y>
  naval_fate.jl mine (set|remove) <x> <y> [--moored|--drifting]
  naval_fate.jl -h | --help
  naval_fate.jl --version

Options:
  -h --help     Show this screen.
  --version     Show version.
  --speed=<kn>  Speed in knots [default: 10].
  --moored      Moored (anchored) mine.
  --drifting    Drifting mine.

"""

using DocOpt  # import docopt function

arguments = docopt(doc, version=v"2.0.0")
dump(arguments)

The result is:

$ julia naval_fate.jl ship new FOO
Dict{String,Any} len 15
  remove: Bool false
  --help: Bool false
  <name>: Array(UTF8String,(1,)) UTF8String["FOO"]
  --drifting: Bool false
  mine: Bool false
  move: Bool false
  --version: Bool false
  --moored: Bool false
  <x>: Nothing nothing
  ship: Bool true
  new: Bool true
  ...

Julia v0.3.0 or later is now supported.

API

DocOpt module exports just one function (docopt), which takes only few arguments and most of them are optional.

docopt(doc::String, argv=ARGS; help=true, version=nothing, options_first=false, exit_on_error=true)

Parameters

  • doc : Description of your command-line interface. (type: String)
  • argv : Argument vector to be parsed. (type: String or Array{String}, default: ARGS)
  • help : Set to false to disable automatic help on -h or --help options. (type: Bool, default: true)
  • version : If passed, the value will be printed if --version is in argv. (any type, but VersionNumber is recommended, e.g. v"1.0.2")
  • options_first : Set to true to require options precedes positional arguments, i.e. to forbid options and positional arguments intermix. (type: Bool, default: false)
  • exit_on_error : Set to true to print the usage and exit when parsing error happens. This option is for unit testing. (type: Bool, default: true)

doc argument is mandatory, argv argument is automatically set to command-line arguments, and help, version, options_first and exit_on_error are keyword arguments.

Returns

  • parsed arguemnts : An associative collection, where keys are names of command-line elements such as e.g. "--verbose" and "", and values are the parsed values of those elements. (type: Dict{String, Any})

See http://docopt.org/ for more details about the grammar of the usage pattern.

docopt.jl's People

Contributors

bicycle1885 avatar jiahao avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.