Skip to content

Commit 8fc6c01

Browse files
committed
refactor!(cli): Split commands
1 parent 2e19bde commit 8fc6c01

13 files changed

+1416
-1274
lines changed

tests/test_cli.py

+26-20
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@
1414
from libtmux.common import has_lt_version
1515
from libtmux.exc import LibTmuxException
1616
from tmuxp import cli, config, exc
17-
from tmuxp.cli import (
17+
from tmuxp.cli.debug_info import command_debug_info
18+
from tmuxp.cli.import_config import get_teamocil_dir, get_tmuxinator_dir
19+
from tmuxp.cli.load import (
1820
_load_append_windows_to_current_session,
1921
_load_attached,
2022
_reattach,
21-
command_debug_info,
22-
command_ls,
23-
get_config_dir,
24-
is_pure_name,
2523
load_plugins,
2624
load_workspace,
25+
)
26+
from tmuxp.cli.ls import command_ls
27+
from tmuxp.cli.utils import (
28+
ConfigPath,
29+
_validate_choices,
30+
get_abs_path,
31+
get_config_dir,
32+
is_pure_name,
2733
scan_config,
2834
)
2935
from tmuxp.workspacebuilder import WorkspaceBuilder
@@ -267,7 +273,7 @@ def test_scan_config_arg(
267273
runner = CliRunner()
268274

269275
@click.command()
270-
@click.argument("config", type=cli.ConfigPath(exists=True), nargs=-1)
276+
@click.argument("config", type=ConfigPath(exists=True), nargs=-1)
271277
def config_cmd(config):
272278
click.echo(config)
273279

@@ -470,15 +476,15 @@ def test_load_log_file(cli_args, tmp_path, monkeypatch):
470476
monkeypatch.setenv("HOME", str(tmp_path))
471477

472478
monkeypatch.chdir(tmp_path)
473-
print(f"tmp_path: {tmp_path}")
474479
runner = CliRunner()
475480

476481
# If autoconfirm (-y) no need to prompt y
477482
input_args = "y\ny\n" if "-y" not in cli_args else ""
478483

479-
runner.invoke(cli.cli, cli_args, input=input_args)
484+
result = runner.invoke(cli.cli, cli_args, input=input_args)
480485
log_file_path = tmp_path / "log.txt"
481486
assert "Loading" in log_file_path.open().read()
487+
assert result is not None
482488

483489

484490
@pytest.mark.parametrize("cli_cmd", ["shell", ("shell", "--pdb")])
@@ -1002,30 +1008,30 @@ def test_freeze_overwrite(server, cli_args, inputs, tmp_path, monkeypatch):
10021008
def test_get_abs_path(tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch):
10031009
expect = str(tmp_path)
10041010
monkeypatch.chdir(tmp_path)
1005-
cli.get_abs_path("../") == os.path.dirname(expect)
1006-
cli.get_abs_path(".") == expect
1007-
cli.get_abs_path("./") == expect
1008-
cli.get_abs_path(expect) == expect
1011+
get_abs_path("../") == os.path.dirname(expect)
1012+
get_abs_path(".") == expect
1013+
get_abs_path("./") == expect
1014+
get_abs_path(expect) == expect
10091015

10101016

10111017
def test_get_tmuxinator_dir(monkeypatch):
1012-
assert cli.get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")
1018+
assert get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")
10131019

10141020
monkeypatch.setenv("HOME", "/moo")
1015-
assert cli.get_tmuxinator_dir() == "/moo/.tmuxinator/"
1016-
assert cli.get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")
1021+
assert get_tmuxinator_dir() == "/moo/.tmuxinator/"
1022+
assert get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")
10171023

10181024

10191025
def test_get_teamocil_dir(monkeypatch: pytest.MonkeyPatch):
1020-
assert cli.get_teamocil_dir() == os.path.expanduser("~/.teamocil/")
1026+
assert get_teamocil_dir() == os.path.expanduser("~/.teamocil/")
10211027

10221028
monkeypatch.setenv("HOME", "/moo")
1023-
assert cli.get_teamocil_dir() == "/moo/.teamocil/"
1024-
assert cli.get_teamocil_dir() == os.path.expanduser("~/.teamocil/")
1029+
assert get_teamocil_dir() == "/moo/.teamocil/"
1030+
assert get_teamocil_dir() == os.path.expanduser("~/.teamocil/")
10251031

10261032

10271033
def test_validate_choices():
1028-
validate = cli._validate_choices(["choice1", "choice2"])
1034+
validate = _validate_choices(["choice1", "choice2"])
10291035

10301036
assert validate("choice1")
10311037
assert validate("choice2")
@@ -1051,7 +1057,7 @@ def test_pass_config_dir_ClickPath(
10511057
@click.command()
10521058
@click.argument(
10531059
"config",
1054-
type=cli.ConfigPath(exists=True, config_dir=(str(configdir))),
1060+
type=ConfigPath(exists=True, config_dir=(str(configdir))),
10551061
nargs=-1,
10561062
)
10571063
def config_cmd(config):

tests/test_workspacebuilder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from libtmux.common import has_gte_version
1414
from libtmux.test import retry, temp_session
1515
from tmuxp import config, exc
16-
from tmuxp.cli import load_plugins
16+
from tmuxp.cli.load import load_plugins
1717
from tmuxp.workspacebuilder import WorkspaceBuilder
1818

1919
from .constants import EXAMPLE_PATH, FIXTURE_PATH

0 commit comments

Comments
 (0)