Git Product home page Git Product logo

clip.py's People

Contributors

d0ugal avatar juanpabloaj avatar willyg302 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clip.py's Issues

Tree view

It would be a nice to have a way to dump/list all the sub-commands as a tree. My current use has ~50+ leafnodes, my users are getting lost and they'd like some sort of overview.

Rework API to be more intuitive

strap (Nested Subcommands) Example

import clip

def print_version():
    print('Version 0.0.0')
    clip.exit()

@clip.app(description='Make for stupid people')
@clip.flag('--version', callback=print_version, help='Print the version')
@clip.flag('-s', '--silent', global=False)
def app():
    pass

@app.subcommand(help='Clone a project and run its install task')
@app.arg('source', help='The directory or repo to clone from')
@app.opt('-d', '--dest', help='Where to initialize the project')
@app.inherit(['-s'])
def init(source, dest, silent=False):
    # @TODO
    pass

@app.subcommand(help='Run one or more tasks defined in a project\'s strapme file')
@app.arg('tasks', nargs='*', default=['default'], help='The task(s) to run')
@app.opt('-d', '--dir', default=os.getcwd(), help='Optional path to execute the tasks from')
@app.inherit(['-s'])
def run(tasks, dir, silent=False):
    # @TODO
    pass

@app.subcommand(help='Manage strap\'s dependency cache')
def cache(action):
    # @TODO
    pass

@cache.subcommand()
def clean():
    # @TODO
    pass

@cache.subcommand(name='list')
def cache_list():
    # @TODO
    pass

@app.subcommand(name='list', help='List the tasks defined in a project\'s strapme file')
def list_tasks():
    # @TODO
    pass

def main():
    if len(sys.argv) == 1:
        sys.argv.append('run')  # Run default task
    try:
        clip.run()
    except clip.ClipExit:
        pass

if __name__ == '__main__':
    main()

Produces:

$ strap --help
strap: Make for stupid people

Usage: strap [-h] [--version] {subcommand}

Options:
  -h, --help  Show this help message and exit
  --version   Print the version

Subcommands:
  init   Clone a project and run its install task
  run    Run one or more tasks defined in a project's strapme file
  cache  Manage strap's dependency cache
  list   List the tasks defined in a project's strapme file
$ strap init -h
strap init

Usage: init [-h] [-d=DEST] [-s] <source>

Arguments:
  source  The directory or repo to clone from

Options:
  -h, --help       Show this help message and exit
  -d, --dest=DEST  Where to initialize the project
  -s, --silent
$ strap run -h
strap run

Usage: run [-h] [-d=DIR] [-s] [<tasks>...]

Arguments:
  tasks  The task(s) to run

Options:
  -h, --help     Show this help message and exit
  -d, --dir=DIR  Optional path to execute the tasks from (default: ./)
  -s, --silent
$ strap cache -h
strap cache

Usage: cache [-h] {subcommand}

Options:
  -h, --help  Show this help message and exit

Subcommands:
  clean
  list
$ strap list -h
strap list

Usage: list [-h]

Options:
  -h, --help  Show this help message and exit
$ strap cache clean -h
strap cache clean

Usage: clean [-h]

Options:
  -h, --help  Show this help message and exit
$ strap cache list -h
strap cache list

Usage: list [-h]

Options:
  -h, --help  Show this help message and exit

Single-command Program

import clip

@clip.app(description='Echoes words to the command line', epilogue='Have fun echoing!')
@clip.arg('words', nargs='*')
def echo(words):
    print(' '.join(words))

try:
    clip.run()
except clip.ClipExit:
    pass

Produces:

$ python echo.py -h
echo: Echoes words to the command line

Usage: echo [-h] [<words>...]

Arguments:
  words

Options:
  -h, --help  Show this help message and exit

Have fun echoing!
$ python echo.py this is    cool
this is cool

Make directory of "utility" decorators

For example:

import clip

def ab(f):
        f = clip.opt('-b')(f)
        f = clip.arg('a')(f)
        return f


app = clip.App()

@app.main()
@clip.opt('-c')
@ab
@clip.opt('-d')
def main(c, a, b, d):
        print c, a, b, d

if __name__ == '__main__':
        try:
                app.run()
        except clip.ClipExit:
                pass

These utility decorators would take a function, add several clip args/opts to it, and return it. One real-world example is a @time decorator that would apply start, end, and duration arguments to a command. Because composability!

Specifying stdout and stderr for multiple Apps

Hello!

Due to the ClipGlobals class, the stdout and sterr can only be specified once for multiple Apps in the same Python run.

By this, I mean that if you have multiple App objects (a different one for each embedded use, etc) the stdout and stderr are set to value specified by the last instantiated App.

For example, in this code:

first_app = clip.App(stdout=first_stream)

# Later on...
second_app = clip.App(stdout=second_stream)

If I were to clip.echo() in a command in first_app, it would write to second_stream.

It may take some significant refactoring to fix this due to the structure of the project. If too large to fix, any workarounds available?

Invoke help manually

I'd like my top-level (main) command to do nothing, and if called simply output the help text. I didn't find that use case in the docs, and I couldn't intuitively tell from the source how to go about it.

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.