GithubHelp home page GithubHelp logo

argparser's Introduction

argparser

Features

Supports positional and optional arguments, and more features, like:

  • Arguments can be added with specific attributes:
    • alias (to add short name for argument)
    • required (to make argument compulsory)
    • type (to specify type of value for argument)
    • nvals (to specify number of values for argument)
    • set_value (to specify value to be set on argument use)
  • Multiple values can be passed for argument
  • Values passed on call can be accessed as a dictionary in:
    • Long form (all arguments)
    • Short form (excluding arguments with none value)
  • Values can be printed in JSON format

Usage

  • Import argparser.
  • Create an instance of Parser class.
    • Use add_arg method to add arguments to process.
    • Use make_args_exclusive method to make arguments exclusive.
    • Use print_usage method to print usage of the added arguments.
    • Use parse method to parse the arguments.
    • Use get_values method to get a dict of arguments and values.
    • Use get_non_none_values method to get a dict of only those arguments which have values.
  • Use print_json function to print a json of the non-none values.

Example

>>> import argparser
>>> parser = argparser.Parser()
>>> parser.add_arg('command', type=str)
>>> parser.add_arg('subcommand', type=str)
>>> parser.add_arg('--keys', type=int, nvals=2, required=True)
>>> parser.add_arg('--verbose', '-V', setval=True)
>>> parser.add_arg('--local', setval=True)
>>> parser.add_arg('--remote', setval=True)
>>> parser.make_args_exclusive('--local', '--remote')
>>> parser.parse('alpha beta --keys 1 2 -V')
>>> argparser.print_json(parser)
{"command": "alpha", "subcommand": "beta", "keys": [1, 2], "verbose": true}

This project was created as a part of Project Omega.

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.