Skip to content

Commit ec3d6ee

Browse files
authored
refactor(cli): Break up into modules, cli.py -> cli/{command}.py (#762)
2 parents 4a4ff08 + 4cbab8d commit ec3d6ee

17 files changed

+1502
-1360
lines changed

docs/api.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,27 +45,27 @@ If you need an internal API stabilized please [file an issue](https://github.com
4545
## CLI
4646

4747
```{eval-rst}
48-
.. automethod:: tmuxp.cli._reattach
48+
.. automethod:: tmuxp.cli.utils.get_config_dir
4949
```
5050

5151
```{eval-rst}
52-
.. automethod:: tmuxp.cli.get_config_dir
52+
.. automethod:: tmuxp.cli.utils._validate_choices
5353
```
5454

5555
```{eval-rst}
56-
.. automethod:: tmuxp.cli.get_teamocil_dir
56+
.. automethod:: tmuxp.cli.import_config.get_teamocil_dir
5757
```
5858

5959
```{eval-rst}
60-
.. automethod:: tmuxp.cli.get_tmuxinator_dir
60+
.. automethod:: tmuxp.cli.import_config.get_tmuxinator_dir
6161
```
6262

6363
```{eval-rst}
64-
.. automethod:: tmuxp.cli.load_workspace
64+
.. automethod:: tmuxp.cli.load.load_workspace
6565
```
6666

6767
```{eval-rst}
68-
.. automethod:: tmuxp.cli._validate_choices
68+
.. automethod:: tmuxp.cli.load._reattach
6969
```
7070

7171
## Configuration

docs/cli/import.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
## From teamocil
88

99
```{eval-rst}
10-
.. click:: tmuxp.cli:command_import_teamocil
10+
.. click:: tmuxp.cli.import_config:command_import_teamocil
1111
:prog: tmuxp import teamocil
1212
:nested: full
1313
```
@@ -33,7 +33,7 @@ $ tmuxp import teamocil /path/to/file.json
3333
## From tmuxinator
3434

3535
```{eval-rst}
36-
.. click:: tmuxp.cli:command_import_tmuxinator
36+
.. click:: tmuxp.cli.import_config:command_import_tmuxinator
3737
:prog: tmuxp import tmuxinator
3838
:nested: short
3939
```

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)