Skip to content

Commit 715649f

Browse files
committed
[cli] Fix --config-file command line option
1 parent 7e3b860 commit 715649f

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ in progress
2121
- [ntfy] [Frigate] Improve example/tutorial about Frigate event notifications
2222
- [ntfy] [Frigate] Synchronize JSON event and snapshot image receive order
2323
- [ntfy] [Frigate] Tests: Verify notification was properly received by ntfy
24+
- [cli] Fix ``--config-file`` command line option
2425

2526

2627
2023-04-11 0.33.0

mqttwarn/commands.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def run():
9090

9191
# Run mqttwarn in service mode when no command line arguments are given
9292
else:
93-
run_mqttwarn()
93+
run_mqttwarn(configfile=options["--config-file"])
9494

9595

9696
def launch_plugin_standalone(
@@ -131,13 +131,13 @@ def launch_plugin_standalone(
131131
run_plugin(config=config, name=plugin, options=options, data=data)
132132

133133

134-
def run_mqttwarn():
134+
def run_mqttwarn(configfile: t.Optional[str] = None):
135135

136136
# Script name (without extension) used as last resort fallback for config/logfile names
137137
scriptname = os.path.splitext(os.path.basename(sys.argv[0]))[0]
138138

139139
# Load configuration file
140-
config = load_configuration(name=scriptname)
140+
config = load_configuration(configfile=configfile, name=scriptname)
141141

142142
# Setup logging
143143
setup_logging(config)

tests/test_commands.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ def test_mqttwarn_main_help(capsys):
3333
assert "Usage:" in capsys.readouterr().out
3434

3535

36-
def test_run_mqttwarn(mocker, caplog):
36+
def test_run_mqttwarn_with_configuration_from_environment(mocker, caplog):
3737
"""
3838
Verify that `mqttwarn.commands.run_mqttwarn` works as expected.
39+
Here, a configuration file is obtained using the `MQTTWARNINI` environment variable.
3940
"""
4041
mocker.patch("os.environ", {"MQTTWARNINI": "tests/etc/no-functions.ini"})
4142
mocker.patch("sys.argv", ["mqttwarn"])
@@ -48,7 +49,22 @@ def test_run_mqttwarn(mocker, caplog):
4849
]
4950

5051

51-
def test_run(mocker, caplog):
52+
def test_run_mqttwarn_with_configuration_from_file(mocker, caplog):
53+
"""
54+
Verify that `mqttwarn.commands.run_mqttwarn` works as expected.
55+
Here, a configuration file is obtained using the `--config-file` command line option.
56+
"""
57+
mocker.patch("sys.argv", ["mqttwarn-custom"])
58+
mocker.patch("mqttwarn.commands.subscribe_forever")
59+
mqttwarn.commands.run_mqttwarn(configfile="tests/etc/no-functions.ini")
60+
61+
assert caplog.messages == [
62+
"Starting mqttwarn-custom",
63+
"Log level is DEBUG",
64+
]
65+
66+
67+
def test_run_command(mocker, caplog):
5268
"""
5369
Verify that `mqttwarn.commands.run` works as expected.
5470
"""

0 commit comments

Comments
 (0)