- Refactory
- Add a bash auto-complete tool #2
- Document needs a better organization
-
[fix] change auto balance function, fix the issue that won't work for this case:
""" Usage: cp [options] <source>... <target> Options: -R """
- [change] no more
locals
underdocpie
function as it may lead to unexpected behavior
-
[fix] when no
options
section presented, fix the bug thatpython
style can not print properly when no match forargv
:e.g. for doc string:
Usage: test v1 test v2
with no argument given, before 0.4.2 gives:
Usage: test v1 test v2
after this fix, it will give correctly:
Usage: test v1 test v2
-
[fix] #11 error handler. Now
docpie
will print an extra\n
when error occurs, and leave two linebreakers between usage and option section""" `SCRIPT` DESCRIPTION Usage: SCRIPT [options] Options: -h, --help show help """ import docpie arguments = docpie.docpie(__doc__, argv=['prog', '--no-such']) # // now # Unknown option: --no-such. # # Usage: # SCRIPT [options] # // always has one linebreaker here # Options: # -h, --help show help # // only one linebreaker, as many programs do # // before # Unknown option: --no-such. # # Usage: # SCRIPT [options] # Options: // missing linebreaker # -h, --help show help # # // more than one linebreakers
-
[new] breaking change. PEP-257 help message supported. add
helpstyle
for people how need to print raw docsting as help message (the old way)that means, when there is extra returning line, extra indent, they will be trimly. This feature makes
docpie
work as most python doc tool.This is very useful when your doc needs to be written as:
class Test(object): def some_fun(self): """ Usage: prog hello """
and also in this way:
docpie.docpie("\n \n Usage: prog [-h]\n\n\n", ["prog", "-h"]) # will give `Usage: prog [-h]\n` instead of `\n \n Usage: prog [-h]\n\n\n\n`
supported value for
helpstyle
:"python"
(default),"dedent"
,"raw"
- [fix] #12, wrong way to reset repeated Options
- [fix] #12
appearedonly
not works for empty repeated Options
-
[fix] #6:
for
[a | [b | c] | d]
, docpie could not expand nested|
. Now it will be expanded asa b c d
-
[fix] #5:
for
this | or | that
, docpie will expandUsage: (--a=<va> | --b=<vb>) --c=<vc>
as
Usage: --a=<va> --c=<vc> --b=<vv> --c=<vc>
which two c-s are the same object. if
--c
is matched in first situation but--a=<va> --c=<vc>
as a whole fails,--c
should drop its value.TODO: use a deep-copy when expand
|
- [new] BASH tab-completion auto-generate script
- [fix] a logging is not use
docpie
logger - [fix] sometimes it does not print information when sys.argv is not correct
-
[fix] options section titles were not set appropriate when options sections's title was not started with
Options:
""" Usage: prog [options] OpTiOnS: -a Another oPtIoNs: -b """ from docpie import Docpie pie = Docpie(__doc__) print(list(pie.option_sections)) # ['', 'Another']
-
[fix] options parse did not parse indent correctly.
example/cp.py
did not work""" USAGE: cp [options] OPTIONS: -f Descrpition goes here """ from docpie import docpie print(docpie(__doc__)) # should not fail parsing
-
[fix] when argv has
--option=arg
but--option
actually accepts no argument, raiseExceptNoArgumentExit
instead of complaining "Unknown option: -arg" -
[new] New
UnknownOptionExit
,ExceptNoArgumentExit
,ExpectArgumentExit
,ExpectArgumentHitDoubleDashesExit
,AmbiguousPrefixExit
. New exception handling way allowing you to customize any output. See example/customize_output.py for details. -
[fix] when two long options has the same prefix but the shorter one requires argument but the longer one not, it will try to give a wrong value to it
""" Usage: prog --long=<opt> prog --long-opt """ from docopt import docopt print(docopt(__doc__, ['prog', '--long-opt'])) # before 0.3.2: --long requires argument(s) # now: {'--': False, '--long': None, '--long-opt': True}
- [new] Add
namedoptions
feature. Document
-
[fix] can't parse options expecting arguments in usage correctly, due to a previous code changing
""" Usage: prog [options] --color <COLOR> Options: --color=<COLOR> """ from docpie import docpie print(docpie(__doc__), ['prog', '--color', 'red']) # {'--': False, '--color': 'red'}
-
[fix]
optionsfirst
can work as expected (previously it can not recognize the expected arguments of a option and lead to fail):""" Usage: prog [options] -w<val> <arg> """ from docpie import docpie print(docpie(__doc__), ['prog', '-w', 'sth', 'arg'], optionsfirst=True) # {'--': False, '-w': 'sth', '<arg>': 'arg'}
-
[fix] the following situation will not failed now (note: not recommended, not POSIX standard)
""" Usage: prog [options] <arg> Options: --force[=<value>] """ from docpie import docpie docpie(__doc__, ['prog', '--force', '--', 'val']) # {'--': True, '--force': None, '<arg>': 'val'}
- [fix] a typo which will cause failed to throw an error when there is an syntax error in your help message
- [fix] issue #3
-
[new] Now repeatable arguments have a better handling way.
First, the repeatable elements can be more than one argument, and can be nested. But can only be argument (not option, not command)
(<arg1> <arg2>)... <arg3>
Second, the elements after repeatable arguments can be argument and command, and can be groupd
<arg>... <arg2> cmd <arg>... (cmd <arg2>) <arg3>
- [fix] When "Usage" section contains "Options:"
(e.g. "
prog <options:>
"), it won't be parsed as "Option" section
- [fix] Support windows style line separator
/r/n
- [fix] when "Usage" stack as
-a<val>
and "Options" annouced as-a <val> an option
it will raise an error
- [fix] a bug in test that some tests will not report when they fail
- [fix]
help
&version
won't work because of the previous refactor
- [fix] stdopt/attachopt/attachvalue in
set_config
will re-init theDocpie
instance - [fix]
<a|b>
will not be parsed as<a | b>
now.
-
[new]
appearedonly
argument to allow only show use inputted options (only options, won't affect commands/arguments) -
[new] multi options section support. Now you can write several options like:
Usage: git <cmd> [options] [<args>...] Global Options: -h, --help print this message rm Options: # seperate with options by breaking the line -f, --force force remove a file add Options: # seperate with at least one visable line -n, --dry-run Don't actually add the file(s)
-
[change] use "Options" when parsing "Usage" and remove some
fix
methodThough it's not recommended, you can now write:
Usage: prog -iFILE Options: -i FILE input file
It's not clear. You'd better write
-i<file>
instead. -
[new] notice user when a flag is not defined.('Unknown option: ')
-
[fix] handle auto_handler before matching
-
[new]
optionsfirst
argument -
[change] break-change remove
Docpie.option_text
attribute, addDocpie.option_sections
- [fix] merging value bug.
Usage: prog [--repeat=<sth> --repeat=<sth>]
matchingprog
will now give'--repeat=[]'
instead of the old wrong value'--repeat=0'
-
[new] better error information notification.
-
[fix] better
Either
handling. NowEither
will be expanded and throwed away. Which means now forUsage: prog [-v | -vv | -vvv] cmd
can match
-v cmd
,-vv cmd
,-vvv cmd
. The old format also worksUsage: prog [-vvv | -vv | -v] cmd
but the new one is more readable.
-
[fix] remove some old api, remove
save.py
- [fix]
Docpie.tokens.Argv.auto_expand
handles--
in a wrong way
- [new] Now
Docpie
can guess your long options. e.g. when you write both--verbose
&--version
, then the--verb
in argv will be interpreted as--verbose
,--vers
as--version
, the--ver
will raise an error.
- [fix]
Docpie
will try to push all options ahead. It fixedtest.test_docpie.DocpieRunDefaultTest.test_option_unit_stack
- [change] now Docpie.option_text will be exactly the same as the "Option" section (contains "Option" title).
- [change] now Docpie.usage_text will be exactly the same as the "Usage" section (contains "Usage" title).
- [change] Change the data storage to
Docpie
instance, now you can initialize severalDocpie
instances in one program with different configurations. - [change] Allow
pickle
theDocpie
instance directly. Deprecateneed_pickle
&restore_pickle
-
[change] break-change:
[]
means anything in it is optional.Usage: prog [-dir]
equals to
Usage: prog [-d] [-i] [-r]
If you want all elements to appear, use
Usage: prog [(-dir)]
- [fix]
Usage: prog [-v] -- <args>...
failed to matchporg -v -- -v --verb
- [fix] #1 command order bug.