qubes/tools: ArgumentParser prepopulated with common options

This commit is contained in:
Wojtek Porczyk 2015-06-24 16:42:06 +02:00
parent 7832f23d5d
commit 6dc5f328f3
3 changed files with 24 additions and 15 deletions

View File

@ -25,8 +25,27 @@
'''Qubes' command line tools
'''
import argparse
import importlib
# TODO --verbose, logger setup
def get_parser_base(*args, **kwargs):
'''Get base parser with options common to all Qubes OS tools.
Currently supported options: ``--xml``.
*args* and *kwargs* are passed to :py:class:`argparser.ArgumentParser`.
'''
parser = argparse.ArgumentParser(*args, **kwargs)
parser.add_argument('--xml', metavar='XMLFILE',
action='store',
help='Qubes OS store file')
return parser
def get_parser_for_command(command):
'''Get parser for given qvm-tool.

View File

@ -28,11 +28,9 @@
import argparse
import qubes
import qubes.tools
parser = argparse.ArgumentParser(description='Create new Qubes OS store.')
parser.add_argument('--xml', metavar='XMLFILE',
action='store',
help='Qubes OS store file')
parser = qubes.tools.get_parser_base(description='Create new Qubes OS store.')
def main(args=None):
'''Main routine of :program:`qubes-create`.

View File

@ -37,6 +37,7 @@ import textwrap
import qubes
import qubes.config
import qubes.tools
import qubes.utils
@ -567,7 +568,7 @@ def get_parser():
wrapper = textwrap.TextWrapper(width=80, break_on_hyphens=False,
initial_indent=' ', subsequent_indent=' ')
parser = argparse.ArgumentParser(
parser = qubes.tools.get_parser_base(
formatter_class=argparse.RawTextHelpFormatter,
description='List Qubes domains and their parametres.',
epilog='available formats (see --help-formats):\n{}\n\n'
@ -582,7 +583,7 @@ def get_parser():
parser_formats = parser.add_mutually_exclusive_group()
parser_formats.add_argument('--format', '-o', metavar='FORMAT',
action='store', choices=formats.keys(),
action='store', choices=formats.keys(), default='simple',
help='preset format')
parser_formats.add_argument('--fields', '-O', metavar='FIELD,...',
@ -594,15 +595,6 @@ def get_parser():
# action='store', metavar='CFGFILE',
# help='Qubes config file')
parser.add_argument('--xml', metavar='XMLFILE',
action='store',
help='Qubes store file')
parser.set_defaults(
qubesxml=os.path.join(qubes.config.system_path['qubes_base_dir'],
qubes.config.system_path['qubes_store_filename']),
format='simple')
return parser