Skip to content

CLI: Break up into modules #762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ If you need an internal API stabilized please [file an issue](https://github.com
## CLI

```{eval-rst}
.. automethod:: tmuxp.cli._reattach
.. automethod:: tmuxp.cli.utils.get_config_dir
```

```{eval-rst}
.. automethod:: tmuxp.cli.get_config_dir
.. automethod:: tmuxp.cli.utils._validate_choices
```

```{eval-rst}
.. automethod:: tmuxp.cli.get_teamocil_dir
.. automethod:: tmuxp.cli.import_config.get_teamocil_dir
```

```{eval-rst}
.. automethod:: tmuxp.cli.get_tmuxinator_dir
.. automethod:: tmuxp.cli.import_config.get_tmuxinator_dir
```

```{eval-rst}
.. automethod:: tmuxp.cli.load_workspace
.. automethod:: tmuxp.cli.load.load_workspace
```

```{eval-rst}
.. automethod:: tmuxp.cli._validate_choices
.. automethod:: tmuxp.cli.load._reattach
```

## Configuration
Expand Down
4 changes: 2 additions & 2 deletions docs/cli/import.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## From teamocil

```{eval-rst}
.. click:: tmuxp.cli:command_import_teamocil
.. click:: tmuxp.cli.import_config:command_import_teamocil
:prog: tmuxp import teamocil
:nested: full
```
Expand All @@ -33,7 +33,7 @@ $ tmuxp import teamocil /path/to/file.json
## From tmuxinator

```{eval-rst}
.. click:: tmuxp.cli:command_import_tmuxinator
.. click:: tmuxp.cli.import_config:command_import_tmuxinator
:prog: tmuxp import tmuxinator
:nested: short
```
Expand Down
46 changes: 26 additions & 20 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@
from libtmux.common import has_lt_version
from libtmux.exc import LibTmuxException
from tmuxp import cli, config, exc
from tmuxp.cli import (
from tmuxp.cli.debug_info import command_debug_info
from tmuxp.cli.import_config import get_teamocil_dir, get_tmuxinator_dir
from tmuxp.cli.load import (
_load_append_windows_to_current_session,
_load_attached,
_reattach,
command_debug_info,
command_ls,
get_config_dir,
is_pure_name,
load_plugins,
load_workspace,
)
from tmuxp.cli.ls import command_ls
from tmuxp.cli.utils import (
ConfigPath,
_validate_choices,
get_abs_path,
get_config_dir,
is_pure_name,
scan_config,
)
from tmuxp.workspacebuilder import WorkspaceBuilder
Expand Down Expand Up @@ -267,7 +273,7 @@ def test_scan_config_arg(
runner = CliRunner()

@click.command()
@click.argument("config", type=cli.ConfigPath(exists=True), nargs=-1)
@click.argument("config", type=ConfigPath(exists=True), nargs=-1)
def config_cmd(config):
click.echo(config)

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

monkeypatch.chdir(tmp_path)
print(f"tmp_path: {tmp_path}")
runner = CliRunner()

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

runner.invoke(cli.cli, cli_args, input=input_args)
result = runner.invoke(cli.cli, cli_args, input=input_args)
log_file_path = tmp_path / "log.txt"
assert "Loading" in log_file_path.open().read()
assert result is not None


@pytest.mark.parametrize("cli_cmd", ["shell", ("shell", "--pdb")])
Expand Down Expand Up @@ -1002,30 +1008,30 @@ def test_freeze_overwrite(server, cli_args, inputs, tmp_path, monkeypatch):
def test_get_abs_path(tmp_path: pathlib.Path, monkeypatch: pytest.MonkeyPatch):
expect = str(tmp_path)
monkeypatch.chdir(tmp_path)
cli.get_abs_path("../") == os.path.dirname(expect)
cli.get_abs_path(".") == expect
cli.get_abs_path("./") == expect
cli.get_abs_path(expect) == expect
get_abs_path("../") == os.path.dirname(expect)
get_abs_path(".") == expect
get_abs_path("./") == expect
get_abs_path(expect) == expect


def test_get_tmuxinator_dir(monkeypatch):
assert cli.get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")
assert get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")

monkeypatch.setenv("HOME", "/moo")
assert cli.get_tmuxinator_dir() == "/moo/.tmuxinator/"
assert cli.get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")
assert get_tmuxinator_dir() == "/moo/.tmuxinator/"
assert get_tmuxinator_dir() == os.path.expanduser("~/.tmuxinator/")


def test_get_teamocil_dir(monkeypatch: pytest.MonkeyPatch):
assert cli.get_teamocil_dir() == os.path.expanduser("~/.teamocil/")
assert get_teamocil_dir() == os.path.expanduser("~/.teamocil/")

monkeypatch.setenv("HOME", "/moo")
assert cli.get_teamocil_dir() == "/moo/.teamocil/"
assert cli.get_teamocil_dir() == os.path.expanduser("~/.teamocil/")
assert get_teamocil_dir() == "/moo/.teamocil/"
assert get_teamocil_dir() == os.path.expanduser("~/.teamocil/")


def test_validate_choices():
validate = cli._validate_choices(["choice1", "choice2"])
validate = _validate_choices(["choice1", "choice2"])

assert validate("choice1")
assert validate("choice2")
Expand All @@ -1051,7 +1057,7 @@ def test_pass_config_dir_ClickPath(
@click.command()
@click.argument(
"config",
type=cli.ConfigPath(exists=True, config_dir=(str(configdir))),
type=ConfigPath(exists=True, config_dir=(str(configdir))),
nargs=-1,
)
def config_cmd(config):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_workspacebuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from libtmux.common import has_gte_version
from libtmux.test import retry, temp_session
from tmuxp import config, exc
from tmuxp.cli import load_plugins
from tmuxp.cli.load import load_plugins
from tmuxp.workspacebuilder import WorkspaceBuilder

from .constants import EXAMPLE_PATH, FIXTURE_PATH
Expand Down
Loading