mirror of
https://github.com/spaam/svtplay-dl.git
synced 2024-11-27 13:44:14 +01:00
utils.parser: Allow direct access to argparse object before use
The svtplay_dl.util.parser.parser() function builds an argparse object and applies it to sys.argv. This change splits this to two functions: a gen_parser() that generates the argparse object and the parser() function that still implements the old behavior (by itself calling gen_parser()). By being able to intercept the generated argparse object before it has consumed the command line arguments, we can do things like generating manpages directly from the argument definitions (kudos to the argparse-manpage project). Such a tool can either be integrated in the release process of svtplay-dl (affecting the set of dependencies for everybody), or integrated as part of the distribution building process (limiting the dependency to opt-in usage from distributions --- or opening up for other solutions). This change will allow for either, but does not introduce any new dependencies. Whereas svtplay-dl supplies its version number as input to the argparse generation, the argparse-manpage tool requires the function to be callable without arguments; hence the "unknown" default value for the version parameter to gen_parser(). It is overriden when used by svtplay-dl and does not end up in the manpage when used with argparse-manpage. This change is backwards compatible; the interface or behavior of parser() does not change.
This commit is contained in:
parent
04a510e65c
commit
0e4fc4899c
@ -53,7 +53,7 @@ class Options:
|
||||
self.default = value
|
||||
|
||||
|
||||
def parser(version):
|
||||
def gen_parser(version="unknown"):
|
||||
parser = argparse.ArgumentParser(prog="svtplay-dl")
|
||||
general = parser.add_argument_group()
|
||||
|
||||
@ -183,8 +183,13 @@ def parser(version):
|
||||
cmorep.add_argument("--cmore-operator", dest="cmoreoperator", default=None, metavar="operator")
|
||||
|
||||
parser.add_argument("urls", nargs="*")
|
||||
options = parser.parse_args()
|
||||
|
||||
return parser
|
||||
|
||||
|
||||
def parser(version):
|
||||
parser = gen_parser(version)
|
||||
options = parser.parse_args()
|
||||
return parser, options
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user