helper-cli 0.1.23__tar.gz → 0.1.25__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {helper_cli-0.1.23 → helper_cli-0.1.25}/PKG-INFO +1 -1
- helper_cli-0.1.25/helper/commands/__init__.py +4 -0
- helper_cli-0.1.25/helper/commands/all_info.py +36 -0
- helper_cli-0.1.25/helper/commands/arch.py +20 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/commands/docker.py +14 -9
- helper_cli-0.1.25/helper/commands/env.py +85 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/commands/internal_ip.py +12 -7
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/commands/nixos.py +1 -1
- helper_cli-0.1.25/helper/commands/public_ip.py +20 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/commands/venv.py +1 -1
- helper_cli-0.1.23/helper/main.py → helper_cli-0.1.25/helper/commands/verbosity.py +13 -76
- helper_cli-0.1.25/helper/env_manager.py +92 -0
- helper_cli-0.1.25/helper/main.py +74 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper_cli.egg-info/PKG-INFO +1 -1
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper_cli.egg-info/SOURCES.txt +4 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/pyproject.toml +1 -1
- helper_cli-0.1.23/helper/commands/__init__.py +0 -1
- helper_cli-0.1.23/helper/commands/arch.py +0 -14
- helper_cli-0.1.23/helper/commands/public_ip.py +0 -17
- {helper_cli-0.1.23 → helper_cli-0.1.25}/README.md +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/__init__.py +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/commands/file.py +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/commands/speed.py +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/commands/system_info.py +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/my_speedtest.py +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/table.py +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper/utils.py +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper_cli.egg-info/dependency_links.txt +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper_cli.egg-info/entry_points.txt +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper_cli.egg-info/requires.txt +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/helper_cli.egg-info/top_level.txt +0 -0
- {helper_cli-0.1.23 → helper_cli-0.1.25}/setup.cfg +0 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""Command to display all system information."""
|
|
2
|
+
import click
|
|
3
|
+
from .. import commands
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def register_all_command(cli):
|
|
7
|
+
"""Register the 'all' command with the CLI.
|
|
8
|
+
|
|
9
|
+
Args:
|
|
10
|
+
cli: The main CLI group
|
|
11
|
+
"""
|
|
12
|
+
@cli.command()
|
|
13
|
+
@click.pass_context
|
|
14
|
+
def all(ctx):
|
|
15
|
+
"""Show all info"""
|
|
16
|
+
# Get the parent command (the main CLI group)
|
|
17
|
+
parent = ctx.parent.command
|
|
18
|
+
|
|
19
|
+
click.echo("=== Internal IP ===")
|
|
20
|
+
ctx.invoke(parent.get_command(ctx, "ip"))
|
|
21
|
+
|
|
22
|
+
click.echo("\n=== Public IP ===")
|
|
23
|
+
ctx.invoke(parent.get_command(ctx, "pubip"))
|
|
24
|
+
|
|
25
|
+
click.echo("\n=== Architecture ===")
|
|
26
|
+
ctx.invoke(parent.get_command(ctx, "arch"))
|
|
27
|
+
|
|
28
|
+
# NixOS command doesn't accept arguments, so we'll just run it directly
|
|
29
|
+
click.echo("\n=== NixOS (Skipped) ==="
|
|
30
|
+
"\nNote: NixOS version check skipped as it requires direct execution"
|
|
31
|
+
"\nTo check NixOS version, run: h nix")
|
|
32
|
+
|
|
33
|
+
click.echo("\n=== System Info ===")
|
|
34
|
+
ctx.invoke(parent.get_command(ctx, "si"))
|
|
35
|
+
|
|
36
|
+
return all
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import click
|
|
2
|
+
from helper import __version__
|
|
3
|
+
from helper.utils import run_cmd
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@click.command()
|
|
7
|
+
def arch():
|
|
8
|
+
"""Display system architecture information.
|
|
9
|
+
|
|
10
|
+
Shows the machine hardware name, which is useful for determining
|
|
11
|
+
if you're running on x86_64, arm64, or other architectures.
|
|
12
|
+
|
|
13
|
+
Equivalent to running 'uname -m' in the terminal.
|
|
14
|
+
|
|
15
|
+
Example:
|
|
16
|
+
$ h arch
|
|
17
|
+
arm64
|
|
18
|
+
"""
|
|
19
|
+
cmd = "uname -m"
|
|
20
|
+
run_cmd(cmd)
|
|
@@ -195,17 +195,22 @@ def get_verbosity(ctx: click.Context) -> Verbosity:
|
|
|
195
195
|
)
|
|
196
196
|
@click.pass_context
|
|
197
197
|
def docker(ctx, verbose):
|
|
198
|
-
"""Docker
|
|
198
|
+
"""Docker container and image management.
|
|
199
199
|
|
|
200
|
-
|
|
201
|
-
- ps: List containers
|
|
202
|
-
- run: Run a command in a new container
|
|
203
|
-
- rm: Remove one or more containers
|
|
204
|
-
- rmi: Remove one or more images
|
|
205
|
-
- url: Show containers with their HTTP/HTTPS URLs
|
|
200
|
+
Manage Docker containers and images with subcommands for common operations.
|
|
206
201
|
|
|
207
|
-
|
|
208
|
-
|
|
202
|
+
Subcommands:
|
|
203
|
+
ps List containers
|
|
204
|
+
run Run a command in a new container
|
|
205
|
+
rm Remove one or more containers
|
|
206
|
+
rmi Remove one or more images
|
|
207
|
+
url Show containers with their HTTP/HTTPS URLs
|
|
208
|
+
|
|
209
|
+
Examples:
|
|
210
|
+
h d ps # List running containers
|
|
211
|
+
h d run nginx # Run an nginx container
|
|
212
|
+
h d rm container # Remove a container
|
|
213
|
+
"""
|
|
209
214
|
ctx.ensure_object(dict)
|
|
210
215
|
|
|
211
216
|
# Get verbosity from parent context if it exists, otherwise use the flag value
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""Environment variable management commands."""
|
|
2
|
+
import os
|
|
3
|
+
import click
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
from ..env_manager import get_env, set_env, load_env, CONFIG_DIR, ENV_FILE
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
@click.group(name="env", help="Manage environment variables.")
|
|
9
|
+
def env():
|
|
10
|
+
"""Environment variable management commands."""
|
|
11
|
+
pass
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
@env.command(name="list")
|
|
15
|
+
def list_env_cmd():
|
|
16
|
+
"""List all environment variables in a formatted table."""
|
|
17
|
+
env_vars = load_env()
|
|
18
|
+
if not env_vars:
|
|
19
|
+
click.echo("No environment variables set.")
|
|
20
|
+
return
|
|
21
|
+
|
|
22
|
+
# Find the maximum key length for alignment
|
|
23
|
+
max_key_len = max(len(str(k)) for k in env_vars.keys())
|
|
24
|
+
|
|
25
|
+
# Print header
|
|
26
|
+
click.echo("Environment Variables:")
|
|
27
|
+
click.echo("-" * (max_key_len + 40)) # 40 is a rough estimate for value + padding
|
|
28
|
+
|
|
29
|
+
# Print each variable
|
|
30
|
+
for key, value in sorted(env_vars.items()):
|
|
31
|
+
click.echo(f"{key.ljust(max_key_len)} : {value}")
|
|
32
|
+
|
|
33
|
+
click.echo() # Add a newline at the end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@env.command(name="get")
|
|
37
|
+
@click.argument("key", required=False)
|
|
38
|
+
def get_env_cmd(key):
|
|
39
|
+
"""Get environment variable(s).
|
|
40
|
+
|
|
41
|
+
If no key is provided, all environment variables will be shown as a table.
|
|
42
|
+
"""
|
|
43
|
+
if not key:
|
|
44
|
+
return list_env_cmd()
|
|
45
|
+
|
|
46
|
+
env_vars = load_env()
|
|
47
|
+
value = env_vars.get(key, "")
|
|
48
|
+
click.echo(f"{key}={value}")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
@env.command(name="set")
|
|
52
|
+
@click.argument("key")
|
|
53
|
+
@click.argument("value")
|
|
54
|
+
def set_env_cmd(key, value):
|
|
55
|
+
"""Set an environment variable."""
|
|
56
|
+
set_env(key, value)
|
|
57
|
+
click.echo(f"Set {key}={value}")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@env.command(name="unset")
|
|
61
|
+
@click.argument("key")
|
|
62
|
+
def unset_env_cmd(key):
|
|
63
|
+
"""Unset an environment variable."""
|
|
64
|
+
env_vars = load_env()
|
|
65
|
+
if key in env_vars:
|
|
66
|
+
del env_vars[key]
|
|
67
|
+
save_env(env_vars)
|
|
68
|
+
if key in os.environ:
|
|
69
|
+
del os.environ[key]
|
|
70
|
+
click.echo(f"Unset {key}")
|
|
71
|
+
else:
|
|
72
|
+
click.echo(f"Variable {key} not found", err=True)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def save_env(env_vars):
|
|
76
|
+
"""Save environment variables to .env file.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
env_vars: Dictionary of environment variables to save.
|
|
80
|
+
"""
|
|
81
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
82
|
+
|
|
83
|
+
with open(ENV_FILE, 'w', encoding='utf-8') as f:
|
|
84
|
+
for key, value in env_vars.items():
|
|
85
|
+
f.write(f'{key}="{value}"\n')
|
|
@@ -24,12 +24,17 @@ def get_internal_ip():
|
|
|
24
24
|
|
|
25
25
|
@click.command()
|
|
26
26
|
def internal_ip():
|
|
27
|
-
"""
|
|
27
|
+
"""Display the local/internal IP address.
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
This command shows the internal (LAN) IP address of your machine.
|
|
30
|
+
It automatically detects the correct network interface based on your OS.
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
Examples:
|
|
33
|
+
$ h ip
|
|
34
|
+
192.168.1.100
|
|
35
|
+
|
|
36
|
+
Note: On multi-homed systems, this shows the primary network interface's IP.
|
|
37
|
+
"""
|
|
38
|
+
ip = get_internal_ip()
|
|
39
|
+
if ip:
|
|
40
|
+
click.echo(ip)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import click
|
|
2
|
+
from helper import __version__
|
|
3
|
+
from helper.utils import run_cmd
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@click.command()
|
|
7
|
+
def public_ip():
|
|
8
|
+
"""Display the public (external) IP address.
|
|
9
|
+
|
|
10
|
+
This command retrieves and displays your public IP address as seen from the internet.
|
|
11
|
+
It's useful for checking your current external network identity.
|
|
12
|
+
|
|
13
|
+
Examples:
|
|
14
|
+
$ h pubip
|
|
15
|
+
203.0.113.45
|
|
16
|
+
|
|
17
|
+
Note: Requires an active internet connection. Uses ifconfig.me service by default.
|
|
18
|
+
"""
|
|
19
|
+
cmd = "curl -s ifconfig.me"
|
|
20
|
+
run_cmd(cmd)
|
|
@@ -1,22 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"""Verbosity handling for CLI commands."""
|
|
2
2
|
import logging
|
|
3
|
-
import
|
|
4
|
-
import subprocess
|
|
5
|
-
from . import __version__
|
|
6
|
-
from .commands import (
|
|
7
|
-
internal_ip,
|
|
8
|
-
public_ip,
|
|
9
|
-
arch,
|
|
10
|
-
nixos,
|
|
11
|
-
docker,
|
|
12
|
-
speed,
|
|
13
|
-
system_info,
|
|
14
|
-
venv,
|
|
15
|
-
file,
|
|
16
|
-
)
|
|
3
|
+
import click
|
|
17
4
|
|
|
18
5
|
|
|
19
6
|
class VerbosityCommand(click.Command):
|
|
7
|
+
"""Custom click.Command that handles verbosity flags."""
|
|
8
|
+
|
|
20
9
|
def parse_args(self, ctx, args):
|
|
21
10
|
# Initialize verbosity from context if it exists
|
|
22
11
|
ctx.ensure_object(dict)
|
|
@@ -29,7 +18,7 @@ class VerbosityCommand(click.Command):
|
|
|
29
18
|
arg = args[i]
|
|
30
19
|
if arg == "--verbose":
|
|
31
20
|
verbose += 1
|
|
32
|
-
elif arg.startswith("-
|
|
21
|
+
elif arg.startswith("-"):
|
|
33
22
|
verbose += arg.count("v")
|
|
34
23
|
else:
|
|
35
24
|
new_args.append(arg)
|
|
@@ -45,6 +34,11 @@ class VerbosityCommand(click.Command):
|
|
|
45
34
|
return super().parse_args(ctx, new_args)
|
|
46
35
|
|
|
47
36
|
def _setup_logging(self, verbose):
|
|
37
|
+
"""Configure logging based on verbosity level.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
verbose (int): Verbosity level (0-3)
|
|
41
|
+
"""
|
|
48
42
|
logger = logging.getLogger("docker-helper")
|
|
49
43
|
if verbose >= 3:
|
|
50
44
|
logger.setLevel(logging.DEBUG)
|
|
@@ -57,6 +51,8 @@ class VerbosityCommand(click.Command):
|
|
|
57
51
|
|
|
58
52
|
|
|
59
53
|
class VerbosityGroup(click.Group):
|
|
54
|
+
"""Custom click.Group that handles verbosity flags for command groups."""
|
|
55
|
+
|
|
60
56
|
def make_context(self, info_name, args, parent=None, **extra):
|
|
61
57
|
# Pre-process args to find verbosity flags
|
|
62
58
|
verbose = 0
|
|
@@ -65,7 +61,7 @@ class VerbosityGroup(click.Group):
|
|
|
65
61
|
for arg in args:
|
|
66
62
|
if arg == "--verbose":
|
|
67
63
|
verbose += 1
|
|
68
|
-
elif arg.startswith("-
|
|
64
|
+
elif arg.startswith("-"):
|
|
69
65
|
verbose += arg.count("v")
|
|
70
66
|
else:
|
|
71
67
|
processed_args.append(arg)
|
|
@@ -89,62 +85,3 @@ class VerbosityGroup(click.Group):
|
|
|
89
85
|
logger.setLevel(logging.ERROR)
|
|
90
86
|
|
|
91
87
|
return ctx
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
@click.group(
|
|
95
|
-
cls=VerbosityGroup,
|
|
96
|
-
context_settings={
|
|
97
|
-
"help_option_names": ["-h", "--help"],
|
|
98
|
-
"token_normalize_func": lambda x: "helper" if x == "h" else x,
|
|
99
|
-
},
|
|
100
|
-
)
|
|
101
|
-
@click.version_option(__version__, "-V", "--version", message="%(prog)s version %(version)s")
|
|
102
|
-
def cli():
|
|
103
|
-
"""Helper CLI - quick system info (v{})
|
|
104
|
-
|
|
105
|
-
You can use 'h' as a shortcut for 'helper' command.
|
|
106
|
-
Example: h docker ps
|
|
107
|
-
|
|
108
|
-
For detailed help on a specific command, use: helper <command> --help
|
|
109
|
-
""".format(__version__)
|
|
110
|
-
# Set up basic logging
|
|
111
|
-
logging.basicConfig(
|
|
112
|
-
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
113
|
-
level=logging.ERROR,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
# Register all commands
|
|
118
|
-
cli.add_command(internal_ip.internal_ip)
|
|
119
|
-
cli.add_command(public_ip.public_ip)
|
|
120
|
-
cli.add_command(arch.arch)
|
|
121
|
-
cli.add_command(nixos.nixos, name="nixos")
|
|
122
|
-
cli.add_command(docker.docker, name="docker")
|
|
123
|
-
cli.add_command(speed.speed, name="speed")
|
|
124
|
-
cli.add_command(speed.speed, name="sp")
|
|
125
|
-
cli.add_command(system_info.system_info, name="system-info")
|
|
126
|
-
cli.add_command(system_info.system_info, name="sysinfo")
|
|
127
|
-
cli.add_command(system_info.system_info, name="si")
|
|
128
|
-
cli.add_command(venv.venv, name="v")
|
|
129
|
-
cli.add_command(file.file(), name="file")
|
|
130
|
-
cli.add_command(file.file(), name="f")
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
@cli.command()
|
|
134
|
-
@click.pass_context
|
|
135
|
-
def all(ctx):
|
|
136
|
-
"""Show all info"""
|
|
137
|
-
click.echo("=== Internal IP ===")
|
|
138
|
-
ctx.invoke(internal_ip.internal_ip)
|
|
139
|
-
click.echo("\n=== Public IP ===")
|
|
140
|
-
ctx.invoke(public_ip.public_ip)
|
|
141
|
-
click.echo("\n=== Architecture ===")
|
|
142
|
-
ctx.invoke(arch.arch)
|
|
143
|
-
click.echo("\n=== NixOS ===")
|
|
144
|
-
ctx.invoke(nixos.nixos, "version")
|
|
145
|
-
click.echo("\n=== System Info ===")
|
|
146
|
-
ctx.invoke(system_info.system_info)
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
if __name__ == "__main__":
|
|
150
|
-
cli()
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""Environment variable management for helper tool."""
|
|
2
|
+
import os
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Dict, Optional
|
|
5
|
+
|
|
6
|
+
# Default environment variables
|
|
7
|
+
DEFAULT_ENV = {
|
|
8
|
+
"AUTHOR": "nguyenhuy158",
|
|
9
|
+
"REPO": "github",
|
|
10
|
+
"ODOO_CONTAINER": "fnp-odoo-1",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
# Environment file path
|
|
14
|
+
CONFIG_DIR = Path.home() / ".config" / "helper"
|
|
15
|
+
ENV_FILE = CONFIG_DIR / ".env"
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def ensure_config_dir() -> None:
|
|
19
|
+
"""Ensure the config directory exists."""
|
|
20
|
+
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def load_env() -> Dict[str, str]:
|
|
24
|
+
"""Load environment variables from .env file or create with defaults.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
Dict containing the environment variables.
|
|
28
|
+
"""
|
|
29
|
+
# Ensure config directory exists
|
|
30
|
+
ensure_config_dir()
|
|
31
|
+
|
|
32
|
+
env_vars = DEFAULT_ENV.copy()
|
|
33
|
+
|
|
34
|
+
# Load existing .env file if it exists
|
|
35
|
+
if ENV_FILE.exists():
|
|
36
|
+
with open(ENV_FILE, 'r', encoding='utf-8') as f:
|
|
37
|
+
for line in f:
|
|
38
|
+
line = line.strip()
|
|
39
|
+
if line and not line.startswith('#'):
|
|
40
|
+
try:
|
|
41
|
+
key, value = line.split('=', 1)
|
|
42
|
+
env_vars[key.strip()] = value.strip().strip('"\'')
|
|
43
|
+
except ValueError:
|
|
44
|
+
continue
|
|
45
|
+
else:
|
|
46
|
+
# Create .env file with default values
|
|
47
|
+
save_env(env_vars)
|
|
48
|
+
|
|
49
|
+
# Update os.environ with loaded values
|
|
50
|
+
os.environ.update(env_vars)
|
|
51
|
+
|
|
52
|
+
return env_vars
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def save_env(env_vars: Dict[str, str]) -> None:
|
|
56
|
+
"""Save environment variables to .env file.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
env_vars: Dictionary of environment variables to save.
|
|
60
|
+
"""
|
|
61
|
+
ensure_config_dir()
|
|
62
|
+
|
|
63
|
+
with open(ENV_FILE, 'w', encoding='utf-8') as f:
|
|
64
|
+
for key, value in env_vars.items():
|
|
65
|
+
f.write(f'{key}="{value}"\n')
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def get_env(key: str, default: Optional[str] = None) -> Optional[str]:
|
|
69
|
+
"""Get an environment variable value.
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
key: The environment variable name.
|
|
73
|
+
default: Default value if key doesn't exist.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
The value of the environment variable or default if not found.
|
|
77
|
+
"""
|
|
78
|
+
env_vars = load_env()
|
|
79
|
+
return env_vars.get(key, default)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def set_env(key: str, value: str) -> None:
|
|
83
|
+
"""Set an environment variable and save to .env file.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
key: The environment variable name.
|
|
87
|
+
value: The value to set.
|
|
88
|
+
"""
|
|
89
|
+
env_vars = load_env()
|
|
90
|
+
env_vars[key] = value
|
|
91
|
+
save_env(env_vars)
|
|
92
|
+
os.environ[key] = value
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import click
|
|
2
|
+
import logging
|
|
3
|
+
import sys
|
|
4
|
+
import subprocess
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from . import __version__
|
|
7
|
+
from .env_manager import load_env
|
|
8
|
+
from .commands import (
|
|
9
|
+
internal_ip,
|
|
10
|
+
public_ip,
|
|
11
|
+
arch,
|
|
12
|
+
nixos,
|
|
13
|
+
docker,
|
|
14
|
+
speed,
|
|
15
|
+
system_info,
|
|
16
|
+
venv,
|
|
17
|
+
file,
|
|
18
|
+
verbosity,
|
|
19
|
+
all_info,
|
|
20
|
+
env_cmd,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
# Import verbosity classes from the verbosity module
|
|
25
|
+
VerbosityCommand = verbosity.VerbosityCommand
|
|
26
|
+
VerbosityGroup = verbosity.VerbosityGroup
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@click.group(
|
|
30
|
+
cls=VerbosityGroup,
|
|
31
|
+
context_settings={
|
|
32
|
+
"help_option_names": ["-h", "--help"],
|
|
33
|
+
"token_normalize_func": lambda x: "helper" if x == "h" else x,
|
|
34
|
+
},
|
|
35
|
+
)
|
|
36
|
+
@click.version_option(__version__, "-V", "--version", message="%(prog)s version %(version)s")
|
|
37
|
+
def cli():
|
|
38
|
+
"""Helper CLI - quick system info (v{})
|
|
39
|
+
|
|
40
|
+
You can use 'h' as a shortcut for 'helper' command.
|
|
41
|
+
Example: h docker ps
|
|
42
|
+
|
|
43
|
+
For detailed help on a specific command, use: helper <command> --help
|
|
44
|
+
""".format(__version__)
|
|
45
|
+
# Initialize environment variables
|
|
46
|
+
load_env()
|
|
47
|
+
|
|
48
|
+
# Set up basic logging
|
|
49
|
+
logging.basicConfig(
|
|
50
|
+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
|
51
|
+
level=logging.ERROR,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# Register all commands
|
|
56
|
+
# Keep only short versions of commands where duplicates exist
|
|
57
|
+
cli.add_command(internal_ip.internal_ip, name="ip")
|
|
58
|
+
cli.add_command(public_ip.public_ip, name="pubip")
|
|
59
|
+
cli.add_command(arch.arch, name="arch")
|
|
60
|
+
cli.add_command(nixos.nixos, name="nix")
|
|
61
|
+
cli.add_command(docker.docker, name="d")
|
|
62
|
+
cli.add_command(speed.speed, name="sp")
|
|
63
|
+
cli.add_command(system_info.system_info, name="si")
|
|
64
|
+
cli.add_command(venv.venv, name="v")
|
|
65
|
+
cli.add_command(file.file(), name="f")
|
|
66
|
+
cli.add_command(env_cmd, name="env")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# Register the all command
|
|
70
|
+
all_info.register_all_command(cli)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
if __name__ == "__main__":
|
|
74
|
+
cli()
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
README.md
|
|
2
2
|
pyproject.toml
|
|
3
3
|
helper/__init__.py
|
|
4
|
+
helper/env_manager.py
|
|
4
5
|
helper/main.py
|
|
5
6
|
helper/my_speedtest.py
|
|
6
7
|
helper/table.py
|
|
7
8
|
helper/utils.py
|
|
8
9
|
helper/commands/__init__.py
|
|
10
|
+
helper/commands/all_info.py
|
|
9
11
|
helper/commands/arch.py
|
|
10
12
|
helper/commands/docker.py
|
|
13
|
+
helper/commands/env.py
|
|
11
14
|
helper/commands/file.py
|
|
12
15
|
helper/commands/internal_ip.py
|
|
13
16
|
helper/commands/nixos.py
|
|
@@ -15,6 +18,7 @@ helper/commands/public_ip.py
|
|
|
15
18
|
helper/commands/speed.py
|
|
16
19
|
helper/commands/system_info.py
|
|
17
20
|
helper/commands/venv.py
|
|
21
|
+
helper/commands/verbosity.py
|
|
18
22
|
helper_cli.egg-info/PKG-INFO
|
|
19
23
|
helper_cli.egg-info/SOURCES.txt
|
|
20
24
|
helper_cli.egg-info/dependency_links.txt
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
# Initialize commands package
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import click
|
|
2
|
-
from helper import __version__
|
|
3
|
-
from helper.utils import run_cmd
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@click.command()
|
|
7
|
-
def arch():
|
|
8
|
-
"""Show CPU architecture information.
|
|
9
|
-
|
|
10
|
-
Version: {}
|
|
11
|
-
Displays the machine hardware name (equivalent to 'uname -m').
|
|
12
|
-
""".format(__version__)
|
|
13
|
-
cmd = "uname -m"
|
|
14
|
-
run_cmd(cmd)
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import click
|
|
2
|
-
from helper import __version__
|
|
3
|
-
from helper.utils import run_cmd
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
@click.command()
|
|
7
|
-
def public_ip():
|
|
8
|
-
"""Show public IP address.
|
|
9
|
-
|
|
10
|
-
Version: {}
|
|
11
|
-
|
|
12
|
-
Retrieves and displays the public IP address of the current machine.
|
|
13
|
-
Uses https://ifconfig.me as the primary service and falls back to curl
|
|
14
|
-
if the primary method fails.
|
|
15
|
-
""".format(__version__)
|
|
16
|
-
cmd = "curl -s ifconfig.me"
|
|
17
|
-
run_cmd(cmd)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|