~ --config-dir becomes --config-dirs for clarity

This commit is contained in:
nicobo 2021-02-07 16:54:24 +01:00
parent 10a385bbec
commit b4a2c78c7b
No known key found for this signature in database
GPG key ID: 2581E71C5FA5285F
4 changed files with 9 additions and 9 deletions

View file

@ -310,7 +310,7 @@ matched = [ p['name'] for p in output['messages'][-1]['patterns'] if p['matched'
The following options are common to both bots : The following options are common to both bots :
- **--config-file** and **--config-dir** let you change the default configuration directory and file. All configuration files will be looked up from this directory ; `--config-file` allows overriding the location of `config.yml`. - **--config-file** and **--config-dirs** let you change the default configuration directory and file. All configuration files will be looked up from this directory ; `--config-file` allows overriding the location of `config.yml`.
- **--backend** selects the *chatter* system to use : it currently supports "console", "signal" and "jabber" (see below) - **--backend** selects the *chatter* system to use : it currently supports "console", "signal" and "jabber" (see below)
- **--stealth** will make the bot connect and listen to messages but print answers to the console instead of sending it ; useful to observe the bot's behavior in a real chatroom... - **--stealth** will make the bot connect and listen to messages but print answers to the console instead of sending it ; useful to observe the bot's behavior in a real chatroom...
- **--debug / -d / --verbosity / -v** those options modify the verbosity level : `--debug` is a flag that sets it to *DEBUG* while with `--verbosity` you can define [the exact level](https://docs.python.org/3/library/logging.html#levels) (e.g. `-v TRACE`). - **--debug / -d / --verbosity / -v** those options modify the verbosity level : `--debug` is a flag that sets it to *DEBUG* while with `--verbosity` you can define [the exact level](https://docs.python.org/3/library/logging.html#levels) (e.g. `-v TRACE`).
@ -320,7 +320,7 @@ The following options are common to both bots :
#### Configuration file : config.yml #### Configuration file : config.yml
Options can also be taken from a configuration file. Options can also be taken from a configuration file.
By default it reads the `config.yml` file in the current directory but can be changed with the `--config-file` and `--config-dir` options. By default it reads the `config.yml` file in the current directory but can be changed with the `--config-file` and `--config-dirs` options.
This file is in YAML format with all options at root level. This file is in YAML format with all options at root level.
Keys are named after the command line options, with middle dashes `-` replaced with underscores `_` and a `s` appended for lists (option `--ibmcloud-url https://api...` will become `ibmcloud_url: https://api...` and `--keywords-file 1.json --keywords-file 2.json` will become : Keys are named after the command line options, with middle dashes `-` replaced with underscores `_` and a `s` appended for lists (option `--ibmcloud-url https://api...` will become `ibmcloud_url: https://api...` and `--keywords-file 1.json --keywords-file 2.json` will become :

View file

@ -72,7 +72,7 @@ case "${opt_bot}" in
askbot|transbot) askbot|transbot)
#exec python3 -m "nicobot.${opt_bot}" "$@" #exec python3 -m "nicobot.${opt_bot}" "$@"
# TODO Allow to override config dirs with the docker command line # TODO Allow to override config dirs with the docker command line
exec "${opt_bot}" "--config-dir" /etc/nicobot /var/nicobot "$@" exec "${opt_bot}" "--config-dirs" /etc/nicobot /var/nicobot "$@"
;; ;;
*) *)
echo "Unknown bot : '*{opt_bot}'" >2 echo "Unknown bot : '*{opt_bot}'" >2

View file

@ -90,7 +90,7 @@ class ArgsHelper:
# Bootstrap options # Bootstrap options
parser.add_argument("--config-file", "-c", "--config", dest="config_file", default=self.config_file, help="YAML configuration file.") parser.add_argument("--config-file", "-c", "--config", dest="config_file", default=self.config_file, help="YAML configuration file.")
parser.add_argument("--config-dir", "-C", dest="config_dirs", nargs='+', default=self.config_dirs, help="Directories where to find configuration files by default.") parser.add_argument("--config-dirs", "-C", dest="config_dirs", nargs='+', default=self.config_dirs, help="Directories where to find configuration files by default.")
parser.add_argument('--verbosity', '-v', dest='verbosity', default=self.verbosity, help="Log level") parser.add_argument('--verbosity', '-v', dest='verbosity', default=self.verbosity, help="Log level")
# Chatter-generic arguments # Chatter-generic arguments
parser.add_argument("--backend", "-b", dest="backend", choices=['console','jabber','signal'], default=self.backend, help="Chat backend to use") parser.add_argument("--backend", "-b", dest="backend", choices=['console','jabber','signal'], default=self.backend, help="Chat backend to use")

View file

@ -28,25 +28,25 @@ class TestOptions(unittest.TestCase):
config = AskbotConfig() config = AskbotConfig()
args = [] args = []
config = parse_args_2pass( self.parser, args, config ) config = parse_args_2pass( self.parser, args, config )
self.assertTrue( len(config.config_dirs) == 1 ) self.assertEqual( 1, len(config.config_dirs) )
self.assertEqual( os.path.realpath(os.getcwd()), os.path.realpath(config.config_dirs[0]) ) self.assertEqual( os.path.realpath(os.getcwd()), os.path.realpath(config.config_dirs[0]) )
def test_config_path_custom(self): def test_config_path_custom(self):
# Using AskbotConfig but it could be another one as long as this test is not askbot-specific # Using AskbotConfig but it could be another one as long as this test is not askbot-specific
config = AskbotConfig() config = AskbotConfig()
args = [ '--config-dir', '/tmp/nicobot' ] args = [ '--config-dirs', '/tmp/nicobot' ]
config = parse_args_2pass( self.parser, args, config ) config = parse_args_2pass( self.parser, args, config )
self.assertTrue( len(config.config_dirs) == 1 ) self.assertEqual( 1, len(config.config_dirs) )
self.assertEqual( os.path.realpath('/tmp/nicobot'), os.path.realpath(config.config_dirs[0]) ) self.assertEqual( os.path.realpath('/tmp/nicobot'), os.path.realpath(config.config_dirs[0]) )
def test_config_path_default_and_custom(self): def test_config_path_default_and_custom(self):
# Using AskbotConfig but it could be another one as long as this test is not askbot-specific # Using AskbotConfig but it could be another one as long as this test is not askbot-specific
config = AskbotConfig() config = AskbotConfig()
args = [ '--config-dir', '/etc/nicobot', '/tmp/nicobot' ] args = [ '--config-dirs', '/etc/nicobot', '/tmp/nicobot' ]
config = parse_args_2pass( self.parser, args, config ) config = parse_args_2pass( self.parser, args, config )
self.assertTrue( len(config.config_dirs) == 2 ) self.assertEqual( 2, len(config.config_dirs) )
self.assertEqual( os.path.realpath('/etc/nicobot'), os.path.realpath(config.config_dirs[0]) ) self.assertEqual( os.path.realpath('/etc/nicobot'), os.path.realpath(config.config_dirs[0]) )
self.assertEqual( os.path.realpath('/tmp/nicobot'), os.path.realpath(config.config_dirs[1]) ) self.assertEqual( os.path.realpath('/tmp/nicobot'), os.path.realpath(config.config_dirs[1]) )