Giter Club home page Giter Club logo

pyminicli's Introduction

This project is deprecated

With (pyrates/minicli#11), pyminicli is obsolete. see https://github.com/pyrates/minicli/, which uses a similar approach and has more features

pyminiCLI

the quickest and simplest way to specify command-line interfaces for python scripts and apps.

how it works

simply call minicli.command on a function in your script, and its positional arguments will be interpereted as command-line positionals, its keywords as command-line options, and its docstring used to supplement the usage in --help

If you provide type-hints for any of the arguments, the command-line inputs will be converted to this type for you.

in example.py:

from minicli import command

def a_function(positional1, a_float: float, *args, keyword_only, kwarg='blarg'):
    """
    A description of the command

    Arguments:
      positional1 (integer): the first positional argument
      a_float (float): e.g. 1.5
      *args: any number of other arguments
      keyword_only: non-optional -- argument (a number)
      kwarg: an option
    """
    print("Hello!")
    print('I recieved positional: ', positional1)
    print("I converted this for you:", a_float, type(a_float))
    print('required keyword: ', keyword_only)
    print('other positionals: ', *args)
    print('my options are: ', kwarg)
    return

command(a_function)
# should have usage, followed by docstring as help
# all positionals should be passed in order
# all options as keywords

the result:

$ python example.py a 1.43 b c d e --keyword_only b --kwarg z
Hello!
I recieved positional:  a
I converted this for you: 1.43 <class 'float'>
required keyword:  b
other positionals:  b c d e
my options are:  z
$ python example.py --help
usage:  positional1  a_float <args... > [--keyword_only <value> (required)]  [--kwarg <value>] 

    A description of the command

    Arguments:
      positional1 (integer): the first positional argument
      a_float (float): e.g. 1.5
      *args: any number of other arguments
      keyword_only: non-optional -- argument (a number)
      kwarg: an option


pyminicli's People

Contributors

hdictus avatar

Stargazers

 avatar

Watchers

 avatar

pyminicli's Issues

Error with argument default types.

Currently if I make a keyword argument with a non-string default, this default is converted to a string, resulting in confusing errors.
There are a couple of options for handling this better.

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.