Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #89478 > unrolled thread

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

Started byEthan Furman <ethan@stoneleaf.us>
First post2015-04-27 22:28 -0700
Last post2015-04-27 22:28 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Clize 3.0b1: An argument parser that draws a CLI from your function sigature Ethan Furman <ethan@stoneleaf.us> - 2015-04-27 22:28 -0700

#89478 — Re: Clize 3.0b1: An argument parser that draws a CLI from your function sigature

FromEthan Furman <ethan@stoneleaf.us>
Date2015-04-27 22:28 -0700
SubjectRe: Clize 3.0b1: An argument parser that draws a CLI from your function sigature
Message-ID<mailman.53.1430198945.3680.python-list@python.org>
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~

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web