mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-20 21:33:13 -07:00
Update jaraco.windows to v3.6:
Dependencies: * backports.functools-lru-cache 1.2.1 * jaraco.classes 1.3 * jaraco.collections 1.3.2 * jaraco.functools 1.11 * jaraco.structures 1.0 * jaraco.text 1.7 * jaraco.ui 1.4 * jaraco.windows 3.6 * more-itertools 2.2 * path.py 8.2.1 * six 1.10.0
This commit is contained in:
parent
f093fafd8d
commit
6bb4ae56bd
30 changed files with 6271 additions and 10 deletions
62
libs/jaraco/ui/cmdline.py
Normal file
62
libs/jaraco/ui/cmdline.py
Normal file
|
@ -0,0 +1,62 @@
|
|||
import argparse
|
||||
|
||||
import six
|
||||
from jaraco.classes import meta
|
||||
from jaraco import text
|
||||
|
||||
|
||||
@six.add_metaclass(meta.LeafClassesMeta)
|
||||
class Command(object):
|
||||
"""
|
||||
A general-purpose base class for creating commands for a command-line
|
||||
program using argparse. Each subclass of Command represents a separate
|
||||
sub-command of a program.
|
||||
|
||||
For example, one might use Command subclasses to implement the Mercurial
|
||||
command set::
|
||||
|
||||
class Commit(Command):
|
||||
@staticmethod
|
||||
def add_arguments(cls, parser):
|
||||
parser.add_argument('-m', '--message')
|
||||
|
||||
@classmethod
|
||||
def run(cls, args):
|
||||
"Run the 'commit' command with args (parsed)"
|
||||
|
||||
class Merge(Command): pass
|
||||
class Pull(Command): pass
|
||||
...
|
||||
|
||||
Then one could create an entry point for Mercurial like so::
|
||||
|
||||
def hg_command():
|
||||
Command.invoke()
|
||||
"""
|
||||
|
||||
@classmethod
|
||||
def add_subparsers(cls, parser):
|
||||
subparsers = parser.add_subparsers()
|
||||
[cmd_class.add_parser(subparsers) for cmd_class in cls._leaf_classes]
|
||||
|
||||
@classmethod
|
||||
def add_parser(cls, subparsers):
|
||||
cmd_string = text.words(cls.__name__).lowered().dash_separated()
|
||||
parser = subparsers.add_parser(cmd_string)
|
||||
parser.set_defaults(action=cls)
|
||||
cls.add_arguments(parser)
|
||||
return parser
|
||||
|
||||
@classmethod
|
||||
def add_arguments(cls, parser):
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def invoke(cls):
|
||||
"""
|
||||
Invoke the command using ArgumentParser
|
||||
"""
|
||||
parser = argparse.ArgumentParser()
|
||||
cls.add_subparsers(parser)
|
||||
args = parser.parse_args()
|
||||
args.action.run(args)
|
Loading…
Add table
Add a link
Reference in a new issue