44~~~~~~~~~
55
66"""
7+ import argparse
78import logging
89import os
910import sys
1011
11- import click
12-
1312from libtmux .__about__ import __version__ as libtmux_version
1413from libtmux .common import has_minimum_version
1514from libtmux .exc import TmuxCommandNotFound
1817from .. import exc
1918from ..__about__ import __version__
2019from ..log import setup_logger
21- from .convert import command_convert
22- from .debug_info import command_debug_info
23- from .edit import command_edit
24- from .freeze import command_freeze
25- from .import_config import command_import
26- from .load import command_load
27- from .shell import command_shell
20+
21+ # from .convert import command_convert, create_convert_subparser
22+ # from .debug_info import command_debug_info, create_debug_info_subparser
23+ # from .edit import command_edit, create_edit_subparser
24+ # from .freeze import command_freeze, create_command_freeze
25+ # from .import_config import command_import, create_command_import
26+ from .load import command_load , create_load_subparser
27+
28+ # from .shell import command_shell, create_command_shell
2829from .utils import tmuxp_echo
2930
3031logger = logging .getLogger (__name__ )
3132
3233
33- @click .group (context_settings = {"obj" : {}, "help_option_names" : ["-h" , "--help" ]})
34- @click .version_option (
35- __version__ ,
36- "-V" ,
37- "--version" ,
38- message = f"%(prog)s %(version)s, libtmux { libtmux_version } " ,
39- )
40- @click .option (
41- "--log-level" ,
42- default = "INFO" ,
43- help = "Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)" ,
44- )
45- def cli (log_level ):
34+ def create_parser () -> argparse .ArgumentParser :
35+ parser = argparse .ArgumentParser (prog = "tmuxp" )
36+ parser .add_argument (
37+ "--version" ,
38+ "-V" ,
39+ action = "version" ,
40+ version = f"%(prog)s { __version__ } , libtmux { libtmux_version } " ,
41+ )
42+ parser .add_argument (
43+ "--log-level" ,
44+ action = "store" ,
45+ default = "INFO" ,
46+ help = "Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)" ,
47+ )
48+ subparsers = parser .add_subparsers (dest = "subparser_name" )
49+ sync_parser = subparsers .add_parser ("load" , help = "Load tmuxp workspaces" )
50+ create_load_subparser (sync_parser )
51+
52+ return parser
53+
54+
55+ # @click.group(context_settings={"obj": {}, "help_option_names": ["-h", "--help"]})
56+ # @click.version_option(
57+ # __version__,
58+ # "-V",
59+ # "--version",
60+ # message=f"%(prog)s %(version)s, libtmux {libtmux_version}",
61+ # )
62+ # @click.option(
63+ # "--log-level",
64+ # default="INFO",
65+ # help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
66+ # )
67+ def cli (args = None ):
4668 """Manage tmux sessions.
4769
4870 Pass the "--help" argument to any command to see detailed help.
4971 See detailed documentation and examples at:
5072 http://tmuxp.git-pull.com/"""
73+
5174 try :
5275 has_minimum_version ()
5376 except TmuxCommandNotFound :
@@ -56,7 +79,22 @@ def cli(log_level):
5679 except exc .TmuxpException as e :
5780 tmuxp_echo (e , err = True )
5881 sys .exit ()
59- setup_logger (logger = logger , level = log_level .upper ())
82+
83+ parser = create_parser ()
84+ args = parser .parse_args (args )
85+
86+ setup_logger (logger = logger , level = args .log_level .upper ())
87+
88+ if args .subparser_name is None :
89+ parser .print_help ()
90+ return
91+ elif args .subparser_name == "sync" :
92+ sync (
93+ repo_terms = args .repo_terms ,
94+ config = args .config ,
95+ exit_on_error = args .exit_on_error ,
96+ parser = parser ,
97+ )
6098
6199
62100def startup (config_dir ):
@@ -72,12 +110,12 @@ def startup(config_dir):
72110 os .makedirs (config_dir )
73111
74112
75- # Register sub-commands here
76- cli .add_command (command_convert )
77- cli .add_command (command_edit )
78- cli .add_command (command_debug_info )
79- cli .add_command (command_load )
80- cli .add_command (command_ls )
81- cli .add_command (command_freeze )
82- cli .add_command (command_shell )
83- cli .add_command (command_import )
113+ # # Register sub-commands here
114+ # cli.add_command(command_convert)
115+ # cli.add_command(command_edit)
116+ # cli.add_command(command_debug_info)
117+ # cli.add_command(command_load)
118+ # cli.add_command(command_ls)
119+ # cli.add_command(command_freeze)
120+ # cli.add_command(command_shell)
121+ # cli.add_command(command_import)
0 commit comments