• Stars
    star
    88
  • Rank 362,927 (Top 8 %)
  • Language
    Julia
  • License
    Other
  • Created about 10 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

command line arguments parser

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

args = docopt(doc, version=v"2.0.0")

The result is:

$ julia -qL examples/naval_fate.jl ship new FOO
julia> args
Dict{String,Any} with 15 entries:
  "remove"     => false
  "--help"     => false
  "<name>"     => String["FOO"]
  "--drifting" => false
  "mine"       => false
  "move"       => false
  "--version"  => false
  "--moored"   => false
  "<x>"        => nothing
  "ship"       => true
  "new"        => true
  "shoot"      => false
  "set"        => false
  "<y>"        => nothing
  "--speed"    => "10"

Julia v0.6 is now supported.

API

The DocOpt module exports just one function, docopt, which takes multiple arguments but all of them except the first one are optional.

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

Arguments

  • doc : Description of your command-line interface. (type: AbstractString)
  • argv : Argument vector to be parsed. (type: String or Vector{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.

Return

  • parsed arguments : 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.

More Repositories

1

docopt

This project is no longer maintained. Please see https://github.com/jazzband/docopt-ng
Python
7,893
star
2

docopt.go

A command-line arguments parser that will make you smile.
Go
1,422
star
3

docopt.cpp

C++11 port of docopt
C++
1,028
star
4

docopt.rs

Docopt for Rust (command line argument parser).
Rust
754
star
5

docopts

Shell interpreter for docopt, the command-line interface description language.
Shell
489
star
6

docopt.rb

Parse command line arguments from nothing more than a usage message
Ruby
461
star
7

docopt.net

Port of docopt to .net
C#
348
star
8

docopt.c

C-code generator for docopt language.
Python
316
star
9

docopt.php

Command line argument parser
PHP
298
star
10

docopt.R

Command-line interface description language for R (http://docopt.org)
R
205
star
11

docopt.nim

Command line arguments parser that will make you smile (port of docopt to Nim)
Nim
202
star
12

docopt.java

Java port of docopt
Java
156
star
13

docopt.coffee

docopt - A command line option parser that will make you smile.
CoffeeScript
148
star
14

docopt.hs

A command-line interface description language and parser that will make you smile
Haskell
118
star
15

docopt.clj

Clojure implementation of the docopt language.
Clojure
65
star
16

try.docopt.org

Try out docopt in browser (Flask app running on Heroku)
CSS
61
star
17

docopt.swift

A command-line interface description language and parser that will make you smile http://docopt.org/
Swift
52
star
18

docopt.lua

Lua
37
star
19

docopt.scala

Scala implementation of docopt language
Scala
37
star
20

docopt.fs

Docopt for F#
F#
34
star
21

docopt.d

D
30
star
22

docopt.org

The website
Tcl
25
star
23

docopt.tcl

docopt.org for TCL
Tcl
4
star
24

challenge.docopt.org

Challenge docopt site
Python
3
star
25

docopt.rs-old

New Rust port is here:
Rust
2
star