提交 4b91276e 编写于 作者: R Rudá Moura

avocado.core.parser: Add option --config.

Use command line --config to read a custom configuration from a file.
Note this option is for the avocado application, so it has
effect for all subcommands.

Example:

$ avocado --config /var/tmp/avocado.conf config
Config files read (in order):
/home/rmoura/Work/avocado/etc/avocado/avocado.conf
/home/rmoura/Work/avocado/etc/avocado/conf.d/gdb.conf
/var/tmp/avocado.conf
...

Also, update man-page about the new option --config.
Signed-off-by: NRudá Moura <rmoura@redhat.com>
上级 718e8bcf
......@@ -21,6 +21,7 @@ import sys
import argparse
from avocado.core import tree
from avocado.core import settings
from avocado.version import VERSION
PROG = 'avocado'
......@@ -45,6 +46,8 @@ class Parser(object):
self.application.add_argument('--plugins', action='store',
help='Load extra plugins from directory',
dest='plugins_dir', default='')
self.application.add_argument('--config', metavar='CONFIG_FILE',
help='Use custom configuration from a file')
def start(self):
"""
......@@ -55,6 +58,10 @@ class Parser(object):
"""
self.args, _ = self.application.parse_known_args()
# Load settings from file, if user provides one
if self.args.config is not None:
settings.settings.process_config_path(self.args.config)
# Use parent parsing to avoid breaking the output of --help option
self.application = argparse.ArgumentParser(prog=PROG,
description=DESCRIPTION,
......
......@@ -6,7 +6,7 @@
SYNOPSIS
========
avocado [-h] [-v] [--plugins PLUGINS_DIR]
avocado [-h] [-v] [--plugins PLUGINS_DIR] [--config CONFIG_FILE]
{run,list,sysinfo,multiplex,plugins,datadir} ...
DESCRIPTION
......@@ -31,6 +31,7 @@ on them being loaded::
-h, --help show this help message and exit
-v, --version show program's version number and exit
--plugins PLUGINS_DIR Load extra plugins from directory
--config CONFIG_FILE Use custom configuration from a file
Real use of avocado depends on running avocado subcommands. This a typical list
of avocado subcommands::
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册