Skip to content

Commit

Permalink
In is_running(), list CLI commands generically (#411)
Browse files Browse the repository at this point in the history
* In is_running(), list CLI commands generically, also allowing commands from loaded plugins to do things outside of one account only

Signed-off-by: Nicolas Höning <nicolas@seita.nl>

* add a test for new util function cli.is_running

Signed-off-by: Nicolas Höning <nicolas@seita.nl>
  • Loading branch information
nhoening committed Apr 4, 2022
1 parent fbc9c30 commit be0bace
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 1 addition & 2 deletions flexmeasures/cli/__init__.py
Expand Up @@ -29,9 +29,8 @@ def is_running() -> bool:
See also: the run_as_cli test fixture, which uses the (non-public) PRETEND_RUNNING_AS_CLI env setting.
TODO: How can plugins add their CLI set here, should they need that?
"""
cli_sets = ("add", "delete", "show", "monitor", "jobs", "db-ops")
cli_sets = current_app.cli.list_commands(ctx=None)
command_line = " ".join(sys.argv)
for cli_set in cli_sets:
if f"flexmeasures {cli_set}" in command_line:
Expand Down
11 changes: 11 additions & 0 deletions flexmeasures/cli/tests/test_utils.py
@@ -0,0 +1,11 @@
import sys

from flexmeasures.cli import is_running as cli_is_running


def test_cli_is_running(app, monkeypatch):
assert cli_is_running() is False
monkeypatch.setattr(
sys, "argv", ["/bin/flexmeasures", "add", "account", "--name", "XCorp."]
)
assert cli_is_running() is True

0 comments on commit be0bace

Please sign in to comment.