Skip to content

Commit 7b05d30

Browse files
committed
!squash more
1 parent ed621e6 commit 7b05d30

File tree

14 files changed

+396
-371
lines changed

14 files changed

+396
-371
lines changed

tests/test_cli.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,17 @@
1313
import libtmux
1414
from libtmux.common import has_lt_version
1515
from libtmux.exc import LibTmuxException
16-
from tmuxp import config, exc
17-
from tmuxp.cli import load as cli
16+
from tmuxp import cli, config, exc
17+
from tmuxp.cli.debug_info import command_debug_info
1818
from tmuxp.cli.load import (
19-
ConfigPath,
2019
_load_append_windows_to_current_session,
2120
_load_attached,
2221
_reattach,
23-
command_debug_info,
24-
command_ls,
25-
get_config_dir,
26-
is_pure_name,
2722
load_plugins,
2823
load_workspace,
29-
scan_config,
3024
)
25+
from tmuxp.cli.ls import command_ls
26+
from tmuxp.cli.utils import ConfigPath, get_config_dir, is_pure_name, scan_config
3127
from tmuxp.workspacebuilder import WorkspaceBuilder
3228

3329
from .constants import FIXTURE_PATH

tests/test_workspacebuilder.py

Lines changed: 1 addition & 1 deletion
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

tmuxp/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
:license: MIT, see LICENSE for details
99
1010
"""
11+
1112
from . import cli, config, util
1213
from .__about__ import (
1314
__author__,

tmuxp/cli/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,19 @@
55
66
"""
77
import logging
8+
import os
9+
import sys
810

911
import click
1012

13+
from libtmux.common import has_minimum_version
14+
from libtmux.exc import TmuxCommandNotFound
15+
16+
from .. import exc
1117
from ..__about__ import __version__
1218
from ..log import setup_logger
1319
from .load import command_load
20+
from .utils import tmuxp_echo
1421

1522
log = logging.getLogger(__name__)
1623

tmuxp/cli/config.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

tmuxp/cli/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VALID_CONFIG_DIR_FILE_EXTENSIONS = [".yaml", ".yml", ".json"]

tmuxp/cli/debug_info.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
import pathlib
2+
3+
import click
4+
5+
tmuxp_path = pathlib.Path(__file__).parent.parent
6+
7+
18
@click.command(name="debug-info", short_help="Print out all diagnostic info")
29
def command_debug_info():
310
"""

tmuxp/cli/edit.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
import click
2+
3+
from .utils import ConfigPath
4+
5+
16
@click.command(name="edit", short_help="Run $EDITOR on config.")
27
@click.argument("config", type=ConfigPath(exists=True), nargs=1)
38
def command_edit_config(config):

tmuxp/cli/freeze.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
import click
2+
3+
from libtmux.server import Server
4+
5+
from .. import config, util
6+
from ..workspacebuilder import freeze
7+
8+
19
@click.command(name="freeze")
210
@click.argument("session_name", nargs=1, required=False)
311
@click.option("-S", "socket_path", help="pass-through for tmux -S")

tmuxp/cli/import_config.py

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
@cli.group(name="import")
1+
import os
2+
import sys
3+
4+
import click
5+
import kaptan
6+
7+
from .. import config
8+
from .utils import ConfigPath, _validate_choices, get_abs_path, tmuxp_echo
9+
10+
11+
def _resolve_path_no_overwrite(config):
12+
path = get_abs_path(config)
13+
if os.path.exists(path):
14+
raise click.exceptions.UsageError("%s exists. Pick a new filename." % path)
15+
return path
16+
17+
18+
@click.group(name="import")
219
def import_config_cmd():
320
"""Import a teamocil/tmuxinator config."""
421

@@ -53,6 +70,56 @@ def import_config(configfile, importfunc):
5370
sys.exit()
5471

5572

73+
@import_config_cmd.command(
74+
name="tmuxinator", short_help="Convert and import a tmuxinator config."
75+
)
76+
@click.argument(
77+
"configfile", type=ConfigPath(exists=True, config_dir=get_tmuxinator_dir), nargs=1
78+
)
79+
def command_import_tmuxinator(configfile):
80+
"""Convert a tmuxinator config from CONFIGFILE to tmuxp format and import
81+
it into tmuxp."""
82+
import_config(configfile, config.import_tmuxinator)
83+
84+
85+
@click.command(name="convert")
86+
@click.option(
87+
"--yes", "-y", "confirmed", help='Auto confirms with "yes".', is_flag=True
88+
)
89+
@click.argument("config", type=ConfigPath(exists=True), nargs=1)
90+
def command_convert(confirmed, config):
91+
"""Convert a tmuxp config between JSON and YAML."""
92+
93+
_, ext = os.path.splitext(config)
94+
ext = ext.lower()
95+
if ext == ".json":
96+
to_filetype = "yaml"
97+
elif ext in [".yaml", ".yml"]:
98+
to_filetype = "json"
99+
else:
100+
raise click.BadParameter(
101+
f"Unknown filetype: {ext} (valid: [.json, .yaml, .yml])"
102+
)
103+
104+
configparser = kaptan.Kaptan()
105+
configparser.import_config(config)
106+
newfile = config.replace(ext, ".%s" % to_filetype)
107+
108+
export_kwargs = {"default_flow_style": False} if to_filetype == "yaml" else {}
109+
newconfig = configparser.export(to_filetype, indent=2, **export_kwargs)
110+
111+
if not confirmed:
112+
if click.confirm(f"convert to <{config}> to {to_filetype}?"):
113+
if click.confirm("Save config to %s?" % newfile):
114+
confirmed = True
115+
116+
if confirmed:
117+
buf = open(newfile, "w")
118+
buf.write(newconfig)
119+
buf.close()
120+
print("New config saved to <%s>." % newfile)
121+
122+
56123
@import_config_cmd.command(
57124
name="teamocil", short_help="Convert and import a teamocil config."
58125
)

0 commit comments

Comments
 (0)