Giter Site home page Giter Site logo

argy-bargy's Introduction

Argy-Bargy

Build Status

Argy-Bargy is a fancy argument parsing library for Janet.

Features

Argy-Bargy has the following features:

  • parses options (arguments that begin with a -- or -)
    • supports four option types (flags, counts, single values and multiple values)
    • supports user-defined conversions from text input
    • support parsing of combined short options (e.g. -lah)
    • support the use of = and white space between long options and values
  • parses parameters (arguments that are not options)
    • supports positional parameters and catch-all parameters
    • supports user-defined conversions from text
    • supports required parameters and default values
  • parses subcommands
    • supports arbitrary number of subcommands
    • supports per-subcommand options and parameters
  • generates documentation
    • generates usage help based on parsing rules
    • supports user-defined usage examples
    • indents usage instructions automatically

Installation

Add the dependency to your project.janet file:

(declare-project
  :dependencies ["https://github.com/pyrmont/argy-bargy"])

Usage

Argy-Bargy can be used like this:

Without Subcommands

(import argy-bargy)

(def rules
  ["--foo" {:kind :single
            :help "The option foo takes a single value."}
   "--bar" {:kind :flag
            :help "The option bar is a flag."}
   :srcs   {:help  "The source files for the program."
            :rest? true}])

(def info
  {:about "A program that does something to the 'srcs' parameters."
   :rider "For more information, visit our website at example.com/program."})

(def config {:rules rules :info info})

(argy-bargy/parse-args "program" config)

If the argument is --help, the following will be printed to stdout:

usage: program [--foo <foo>] [--bar] srcs...

A program that does something to the 'srcs' parameters.

Parameters:

 srcs    The source files for the program.

Options:

     --foo <foo>    The option foo takes a single value.
     --bar          The option bar is a flag.
 -h, --help         Show this help message.

For more information, visit our website at example.com/program.

With Subcommands

(import argy-bargy)

(def subcommands
  ["foo" {:rules {:kind :single
                  :help "The option foo takes a single value."}
          :help  "Run the foo command."}
   "bar" {:rules {:kind :flag
                  :help "The option bar is a flag."}
          :help  "Run the bar command."}])

(def info
  {:about "A program that provides subcommands that do something."
   :rider "For more information, visit our website at example.com/program."})

(def config {:info info :subs subcommands})

(argy-bargy/parse-args "program" config)

If the argument is --help, the following will be printed to stdout:

usage: program <subcommand> [<args>]

A program that provides subcommands that do something.

Options:

 -h, --help    Show this help message.

Subcommands:

 foo    Run the foo command.
 bar    Run the bar command.

For more information on each subcommand, type 'program help <subcommand>'.

For more information, visit our website at example.com/program.

API

Documentation for Argy-Bargy's API is in api.md.

Bugs

Found a bug? I'd love to know about it. The best way is to report your bug in the Issues section on GitHub.

Licence

Argy-Bargy is licensed under the MIT Licence. See LICENSE for more details.

argy-bargy's People

Contributors

pyrmont avatar sogaiu 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.