tylertemp / docpie Goto Github PK
View Code? Open in Web Editor NEWAn easy and Pythonic way to create your POSIX command line
License: MIT License
An easy and Pythonic way to create your POSIX command line
License: MIT License
Given below docstring, docpie
does not print an empty line between usage and options:
"""
`SCRIPT` DESCRIPTION
Usage:
SCRIPT [options]
Options:
-h, --help show help
"""
Output:
Unknown option: -n.
Usage:
SCRIPT [options]
Options:
-h, --help show help
Hey man. I was using your package but it does not work as expected. My __doc__
:
Usage: xx --node <url> --image <os_image> [--kick <kicker>]
options:
-n, --node <url>
-i, --image <os_image>
-k, --kick <kicker>
When I specify:
--node node_url --image pu_image
things work fine.
But when I give argv as:
--image pu_image --node node_url
it give the result:
{'--': False,
'--image': True,
'--kick': False,
'--node': True,
'<kicker>': None,
'<os_image>': 'node_url',
'<url>': 'pu_image'}
WTF? <os_image> is now the url and is the image.
docpie
version: 0.4.1 / Sun Jan 28 21:04:33 2018
Here is the online demo
Given below docstring, docpie
does not print the description (just usage and options). In comparison, docopt
prints the full docstring
"""
`SCRIPT` DESCRIPTION
Usage:
SCRIPT [options]
Options:
-h, --help show help
"""
for
Usage: prog [cmd1 cmd2]
docpie
will match prog cmd2 cmd1
, which is not correct.
I'm still working on it.
Hey!
Thanks for a really good package.
We are now using it for one of our internal tools.
This is not a bug report, but some proposals for improvements, that we think would make the package even better.
Add an api option to only allow exact matching of options.
Right now we have an option --compress_lzss. If you type --compress at the command line, it will be interpreted as --compress_lzss, since no other option starts with --compress.
But later on we will also add an option --compress_proprietary. If you then have created scripts to run the CLI, containing --compress, then will then stop to work.
So therefore we would like to only accept options if they are completely right entered.
Give a message "Unknown Command" when an unknown command is entered (Just as for unknown options)
Usage: pie.py get --opt1=O1 --opt2=O2
But when I give argv as:
gett --opt1 ds --opt2 ds
it give the result:
Usage: pie.py get --opt1=O1 --opt2=O2
Usage: pie.py get --opt1=O1 --opt2=O2
And when I give argv as:
get --optt1 ds --opt2 ds
it give the result:
Unknown option: --optt1.
Usage: pie.py get --opt1=O1 --opt2=O2
3. **Give an error message if two or more "this|or|that" parameters are entered at the same time**
Now it is only showing "usage: "
Usage: pie.py create (--opt1=O1 | --opt2=O2)
But when I give argv as:
create --opt1 1 --opt2 2
it give the result:
Usage: pie.py create (--opt1=O1 | --opt2=O2)
Please respond if you think this is something to add or not.
Best Regards, Pernilla
`docpie` version: 0.3.6 / Sat Jul 1 01:54:16 2017
Hi! I was using your package but it does not work as expected. My __doc__
:
Usage: pie.py [--aa=AA|--bb=BB] --cc=CC
But when I give argv as:
--bb B --cc C
it give the result:
Usage: pie.py [--aa=AA|--bb=BB] --cc=CC
Expected result would be to get B for bb parameter and CC for cc parameter.
(It works if -aa is entered with a parameter)
Bug? Or me doing wrong?
docpie
version: 0.3.3 / Tue Jun 7 09:26:44 2016
Here is the online demo
This will randomly fail. I've found the reason and I'm working on it.
"""
Usage: prog [options] --keep
prog [options]
Options:
-k, --keep
"""
from docpie import docpie
import sys
sys.argv = [sys.argv[0], '--keep']
assert docpie(__doc__)['--keep'] == True # randomly fail
Hey man. I was using your package but it does not work as expected. My __doc__
:
naval_fate --ship shipname
But when I give argv as:
naval_fate --ship ship1
it give the result:
Can't convert 'NoneType' object to str implicitly
WTF? What the hell was going on?
docpie
version: 0.3.6 / Sat Jul 1 01:54:16 2017
Here is the online demo
Hey man. I was using your package but it does not work as expected. My __doc__
:
Usage:
create [--vbf_version=VBFVERSION]
[--description=DESCRIPTION]...
[--parameter_settings=(PARAMETER PARAMETERVALUE)]
[([--vbt_sort | --vbt_last] --sign=ADDRESS)]
But when I give argv as:
--sign=0x00 --vbt_last
it give the result:
{'--': False,
'--description': [],
'--sign': '0x00',
'--vbt_last': True}
Why the option '--description' is '[]' in the resulted dictionary when I choose "appearedonly=True"?
From my understanding, it shouldn't appear in the dict because I haven't input it from argv from the command line, or?
docpie
version: 0.3.6 / Sat Jul 1 01:54:16 2017
Here is the online demo
Hello
Is it possible to parse something like that?
'''
Example of program which uses [options] shortcut in pattern.
Usage:
options_shortcut_example.py --help | --version
options_shortcut_example.py [options] (do --after=<float> [--grace])... <port>...
Arguments:
<port> give port
Generic options:
-h --help show this help message and exit
--version show version and exit
-n, --number N use N as a number
-t, --timeout TIMEOUT set timeout TIMEOUT seconds
--apply apply changes to database
-q operate in quiet mode
Commands:
do do smth
Command options:
--after=<float> do smth after <float> time
--grace do smth with grace
'''
Where --after=<float>
is obligatory option for do
sub-command and <port>
can be recurring.
When I set --after=<float>
as optional:
options_shortcut_example.py [options] (do [--after=<float>] [--grace])... <port>...
it is parsed, but not in desired way:
python options_shortcut_example.py -n 6 do --after=4 'a.txt'
{'--': False,
'--after': [],
'--apply': False,
'--grace': 0,
'--help': False,
'--number': ' 6',
'--timeout': None,
'--version': False,
'-h': False,
'-n': ' 6',
'-q': False,
'-t': None,
'<port>': ['--after=4', 'a.txt'],
'do': 1}
In both cases I have used optionsfirst=True
.
Is there any way-around?
The thing that gets me about docopt is that there is nothing like argcomplete for argparse. I know one can use docopt_wordlist
and docopt-wordlist.bash
from docopt.rs
but that is hard to set up and doesn't work in some cases. Another solution is infi.docopt_autocomplete that creates bash and zsh completion files. The drawback with that: the user has to update the completion files by hand, EVERY time, the options change in the original script. I think a command line interface goes hand in hand with auto-completion. So if you feel, you're being bored, a nice mechanism for auto-completing commands would be good that doesn't require installation beyond a simple pip install
. (See Issue discussed in docopt repository for reference).
Desired result:
If I have and the desired feature "docpie auto-completion" installed:
# This is 'prog.py'
"""
Usage:
prog.py --long-option --longer-option <file>...
"""
from docpie import docpie
args = docpie(__doc__ % locals()
print args
And prog.py
is in the current working directory of my shell together with these other files: example1.txt, example2.txt, example3.txt
I want to be able to auto-complete in the shell like this:
shell> ./prog.py --lo[TAB]
--long-option --longer-option
shell> ./prog.py --longer[TAB]
shell> ./prog.py --longer-option
shell> ./prog.py --longer-option ex[TAB]
example1.txt example2.txt example3.txt
Ideally the auto-completion is smart and uses existing built-in completions for things like files, hostnames, ip-adresses, kernel-versions and s.o. In Bash they can be listed with complete -p
.
Would it be possible to make the "usage" and "options" section keywords configurable? Like in
docpie(__doc__, usage = 'Aufruf', options = 'Optionen')
This would make the help text fully translatable (localized). Right now the keywords "Usage:" and "Options:" need to be English, otherwise docpie
won't recognize them.
Hello,
Thank you for making docpie!
I'm coming from docopt/docopt#448 (comment)
I have that exact use case, in that I'm looking for this output:
{
'--': False,
'--flag': ['flag1', 'flag2'],
'-f': ['flag1', 'flag2']
}
Working demo from your link that uses default:
However, how would this actually be called in a real world program?
The only way I can get it to work is use the syntax "-f sflag1 sflag2 sflag3"
or "--flag lflag1 lflag2 lflag3"
(without "="
that's typically used for the long form)
Using "="
(typically used for the long form) fails parsing: "--flag=flag1 flag2"
This fails: Link
Is there a way to get "--flag=flag1 flag2"
syntax to work?
What changes will it takes to get it to accept "--flag=flag1 --flag=flag2"
?
This fails: Link
As you can see, docpie even complains: "--flag/-f requires argument(s)."
which shows that the flag is not being parsed correctly :(
Could you also suggest how to update the usage text so that I can call the command like: "--flag=lflag1 -f lflag1 --flag=lflag2 ... -f sflagn sub_command"
?
The only way I can get this to work is to:
which is: "usage: tool [options] [(--flag=<flag>)...] SUB_COMMAND"
and used as "--flag=flag1 --flag=flag2 --flag=flag3 sub_command"
output:
{
'--': False,
'--flag': ['flag1', 'flag2', 'flag3'],
'SUB_COMMAND': 'sub_command'
}
BUT this unfortunately means that this will not work:
"--flag=lflag1 -f lflag1 --flag=lflag2 ... -f sflagn sub_command"
even if I tried to change usage to: "usage: tool [options] [(--flag=<flag> | -f <flag>)...] SUB_COMMAND"
it fails:
I was expecting the following usage text to work:
usage: tool [options] SUB_COMMAND
Options: -f (<flag>)... --flag=(<flag>)... [default: flag1 flag2]
Error: "DocpieError: `--flag/-f` announced differently ([1, 4, inf], [1, inf])"
... but if you can suggest a variation of the following so I can get it to work, that would be great too
Usage: tool [(--flag=<flag>)...|(-f <flag>)...] SUB_COMMAND
Hi!
I was using your package but it does not work as I expected. My __doc__
:
usage: pie.py [--aa=AA|[--bb=BB | --cc=CC]]
But when I give argv as:
--aa
it give the result:
'Either' object has no attribute 'push_option_ahead'
Do not know if it is a bug or something that should not be supported?
Would be really nice if you could have the option to either choose aa and if you do not want that, you can choose between between bb and cc. Need it for my CLI implementation at least.
Thanks! Also thanks for the last correction you made on the issue I put. Really helped :-)
docpie
version: 0.3.5 / Thu Jun 15 10:41:24 2017
Here is the online demo
Hey,
I am having trouble with docpie
running in the CI. Please have a look at following job: https://gitlab.com/milkpirate/yeet/-/jobs/251075102
______________ test_component_switch_on_off[pwr_state1---host-on] ______________
tests/test_component.py:169: in test_component_switch_on_off
yeet.main(argv=cmd)
src/yeet.py:71: in main
version='yeet 1.0',
venv3/lib/python3.7/site-packages/docpie/__init__.py:131: in docpie
pie = Docpie(**kwargs)
E TypeError: __init__() got an unexpected keyword argument 'kwargs'
Locally everything works as expected, just in the CI it behaves stubborn.
Code to be tested:
def main(
argv: List[str]=sys.argv
):
args = docpie.docpie(
__doc__,
argv=argv,
help=True,
version='yeet 1.0',
)
...
Code to test it (e.g.):
...
cmd = 'yeet.py alarm'
cmd = shlex.split(cmd)
yeet.main(argv=cmd)
...
docpie==0.4.2
python==3.7.3
(local)
python==3.7.0
(CI)
Could you help me sorting this out?
The website, docpie.comes.today, doesn’t work anymore. (Bad gateway)
Can this be fixed?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.