Clize 3.0b1: An argument parser that draws a CLI from your function sigature

Ethan Furman ethan at stoneleaf.us
Tue Apr 28 01:28:57 EDT 2015


On 04/28, Chris Angelico wrote:

> That's a lot of separate pieces. Here's the docstringargs equivalent:
> 
> https://github.com/Rosuav/snippets/blob/dsa/snippets.py

Just for grins, here's that using Scription:

-- 8< --------------------------------------------------------------------
"""Store and retrieve snippets of text"""
from scription import *
import logging

# Set the log output file, and the log level 
logging.basicConfig(filename="snippets.log", level=logging.DEBUG)

data = {}

@Script()
def main():
    print('Result: {!r}'.format(script_command()))

@Command(
        name=('the name of the snippet', ),
        snippet=('the snippet text', ),
        )
def put(name, snippet):
    "Store a snippet with an associated name."
    logging.info("Storing({!r}, {!r})".format(name, snippet))
    data[name] = snippet
    return name, snippet

@Command(
        name=('the name of the snippet', ),
        )
def get(name):
    "Retrieve the snippet with a given name."
    logging.error("Retrieving({!r})".format(name))
    return data.get(name)

Main()
-- 8< --------------------------------------------------------------------

and a sample run with nothing selected:

-- 8< --------------------------------------------------------------------
$ python snippet
Store and retrieve snippets of text

snippet get NAME

    Retrieve the snippet with a given name.

    NAME   the name of the snippet    

snippet put NAME SNIPPET

    Store a snippet with an associated name.

    NAME      the name of the snippet    
    SNIPPET   the snippet text           
-- 8< --------------------------------------------------------------------


--
~Ethan~



More information about the Python-list mailing list