helper-cli 0.1.9__py3-none-any.whl → 0.1.11__py3-none-any.whl

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/commands/docker.py CHANGED
@@ -141,30 +141,33 @@ def get_verbosity(ctx: click.Context) -> Verbosity:
141
141
  verbosity.info(f"Verbosity level set to {verbose}")
142
142
  return verbosity
143
143
 
144
- @click.group(context_settings={"ignore_unknown_options": True, "allow_extra_args": True})
144
+ @click.group()
145
+ @click.option('-v', '--verbose', count=True, help='Increase verbosity (can be used multiple times)')
145
146
  @click.pass_context
146
- def docker(ctx):
147
+ def docker(ctx, verbose):
147
148
  """Docker management commands."""
148
- # Parse verbosity from args
149
- verbose = 0
150
- remaining_args = []
151
- i = 0
152
- while i < len(ctx.args):
153
- arg = ctx.args[i]
154
- if arg in ('-v', '--verbose'):
155
- if arg == '--verbose':
156
- verbose += 1
157
- else:
158
- # Count number of 'v's in -v, -vv, -vvv, etc.
159
- verbose += arg.count('v')
160
- # Remove the processed flag
161
- ctx.args.pop(i)
162
- else:
163
- i += 1
149
+ ctx.ensure_object(dict)
150
+
151
+ # Get verbosity from parent context if it exists, otherwise use the flag value
152
+ parent_verbosity = ctx.obj.get('verbosity', 0) if hasattr(ctx, 'obj') else 0
153
+ verbosity_level = max(verbose, parent_verbosity)
164
154
 
165
155
  # Initialize verbosity
166
- verbosity = Verbosity(verbosity=verbose)
167
- ctx.obj = {'verbosity': verbosity, 'args': ctx.args}
156
+ verbosity = Verbosity(verbosity=verbosity_level)
157
+ ctx.obj['verbosity'] = verbosity
158
+
159
+ # Set up logging
160
+ logger = logging.getLogger('docker-helper')
161
+ if verbosity_level >= 3:
162
+ logger.setLevel(logging.DEBUG)
163
+ elif verbosity_level == 2:
164
+ logger.setLevel(logging.INFO)
165
+ elif verbosity_level == 1:
166
+ logger.setLevel(logging.WARNING)
167
+ else:
168
+ logger.setLevel(logging.ERROR)
169
+
170
+ logger.debug(f"Docker command group initialized with verbosity level: {verbosity_level}")
168
171
 
169
172
  verbosity.debug("Initializing Docker command group")
170
173
  if not check_docker(verbosity):
@@ -407,28 +410,54 @@ def url(ctx, show_all, http_only):
407
410
  verbosity.debug(f"Found {len(port_mappings)} port mappings for {name}")
408
411
 
409
412
  for port in port_mappings:
410
- if port['host_port'] and port['container_port']:
411
- verbosity.debug(f"Checking port mapping: {port}")
412
-
413
- # Check if it's HTTP/HTTPS port (common ports)
414
- http_ports = ['80', '443', '8080', '8443', '3000', '5000', '8000', '8888']
415
- is_http_port = (
416
- port['container_port'] in http_ports or
417
- any(p in port['container_port'] for p in ['80/', '443/', '8080/', '8443/'])
418
- )
419
-
420
- if is_http_port:
421
- scheme = 'https' if port['container_port'].startswith('443') else 'http'
422
- url = f"{scheme}://{port['host_ip']}:{port['host_port']}"
423
- port_num = port['container_port'].split('/')[0]
424
-
425
- container_info['urls'].append({
426
- 'url': url,
427
- 'port': port_num
428
- })
429
- verbosity.info(f"Added URL for {name}: {url} (port {port_num})")
413
+ if not port.get('host_port') or not port.get('container_port'):
414
+ verbosity.debug(f"Skipping incomplete port mapping: {port}")
415
+ continue
416
+
417
+ verbosity.debug(f"Checking port mapping: {port}")
418
+ verbosity.debug(f"Container name: {name}, Port: {port['container_port']}")
419
+
420
+ # Handle different port string formats (e.g., '8069/tcp', '0.0.0.0:8080->80/tcp')
421
+ port_str = port['container_port']
422
+
423
+ # Extract port number and protocol
424
+ port_num = None
425
+ protocol = 'tcp' # default protocol
426
+
427
+ # Handle format like '8069/tcp' or '80/http'
428
+ if '/' in port_str:
429
+ port_num, protocol = port_str.split('/', 1)
430
+ # Handle format like '0.0.0.0:8080->80/tcp'
431
+ elif '->' in port_str:
432
+ _, port_mapping = port_str.split('->', 1)
433
+ if '/' in port_mapping:
434
+ port_num, protocol = port_mapping.split('/', 1)
430
435
  else:
431
- verbosity.debug(f"Skipping non-HTTP port: {port['container_port']}")
436
+ port_num = port_mapping
437
+ else:
438
+ port_num = port_str
439
+
440
+ # Clean up port number (remove any non-numeric characters)
441
+ port_num = ''.join(c for c in port_num if c.isdigit())
442
+
443
+ # Map all ports to HTTP URLs
444
+ if port_num: # Process all ports regardless of protocol
445
+ scheme = 'http'
446
+
447
+ # Handle IPv6 addresses (add brackets if needed)
448
+ host = port['host_ip']
449
+ if ':' in host and not host.startswith('['):
450
+ host = f'[{host}]'
451
+
452
+ url = f"{scheme}://{host}:{port['host_port']}"
453
+
454
+ container_info['urls'].append({
455
+ 'url': url,
456
+ 'port': port_num,
457
+ 'protocol': protocol
458
+ })
459
+ verbosity.info(f"Added URL for {name}: {url} (port {port_num}/{protocol})")
460
+ verbosity.info(f"Added URL for {name}: {url} (port {port_num})")
432
461
 
433
462
  # If http_only is True and no HTTP URLs, skip this container
434
463
  if http_only and not container_info['urls']:
helper/main.py CHANGED
@@ -1,10 +1,89 @@
1
1
  import click
2
+ import logging
3
+ import sys
2
4
  from .commands import internal_ip, public_ip, arch, nixos, docker
3
5
 
4
- @click.group()
6
+ class VerbosityCommand(click.Command):
7
+ def parse_args(self, ctx, args):
8
+ # Initialize verbosity from context if it exists
9
+ ctx.ensure_object(dict)
10
+ verbose = ctx.obj.get('verbosity', 0)
11
+
12
+ # Process args for verbosity flags
13
+ new_args = []
14
+ i = 0
15
+ while i < len(args):
16
+ arg = args[i]
17
+ if arg == '--verbose':
18
+ verbose += 1
19
+ elif arg.startswith('-v'):
20
+ verbose += arg.count('v')
21
+ else:
22
+ new_args.append(arg)
23
+ i += 1
24
+
25
+ # Update verbosity in context
26
+ ctx.obj['verbosity'] = verbose
27
+
28
+ # Set up logging
29
+ self._setup_logging(verbose)
30
+
31
+ # Continue with normal argument parsing
32
+ return super().parse_args(ctx, new_args)
33
+
34
+ def _setup_logging(self, verbose):
35
+ logger = logging.getLogger('docker-helper')
36
+ if verbose >= 3:
37
+ logger.setLevel(logging.DEBUG)
38
+ elif verbose == 2:
39
+ logger.setLevel(logging.INFO)
40
+ elif verbose == 1:
41
+ logger.setLevel(logging.WARNING)
42
+ else:
43
+ logger.setLevel(logging.ERROR)
44
+
45
+ class VerbosityGroup(click.Group):
46
+ def make_context(self, info_name, args, parent=None, **extra):
47
+ # Pre-process args to find verbosity flags
48
+ verbose = 0
49
+ processed_args = []
50
+
51
+ for arg in args:
52
+ if arg == '--verbose':
53
+ verbose += 1
54
+ elif arg.startswith('-v'):
55
+ verbose += arg.count('v')
56
+ else:
57
+ processed_args.append(arg)
58
+
59
+ # Create context with processed args
60
+ ctx = super().make_context(info_name, processed_args, parent=parent, **extra)
61
+
62
+ # Set verbosity in context
63
+ ctx.ensure_object(dict)
64
+ ctx.obj['verbosity'] = verbose
65
+
66
+ # Set up logging
67
+ logger = logging.getLogger('docker-helper')
68
+ if verbose >= 3:
69
+ logger.setLevel(logging.DEBUG)
70
+ elif verbose == 2:
71
+ logger.setLevel(logging.INFO)
72
+ elif verbose == 1:
73
+ logger.setLevel(logging.WARNING)
74
+ else:
75
+ logger.setLevel(logging.ERROR)
76
+
77
+ return ctx
78
+
79
+ @click.group(cls=VerbosityGroup)
5
80
  def cli():
6
81
  """Helper CLI - quick system info"""
7
- pass
82
+ # Set up basic logging
83
+ logging.basicConfig(
84
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
85
+ level=logging.ERROR
86
+ )
8
87
 
9
88
  # Register all commands
10
89
  cli.add_command(internal_ip.internal_ip)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: helper-cli
3
- Version: 0.1.9
3
+ Version: 0.1.11
4
4
  Summary: Simple system info CLI
5
5
  Requires-Python: >=3.8
6
6
  Requires-Dist: click
@@ -0,0 +1,13 @@
1
+ helper/main.py,sha256=39UV2OxIOAgak7ALwGRdK2oeCaaMXQqvXgnrWU77kB4,3247
2
+ helper/utils.py,sha256=JynYacwFA9kgkDuWpGPCj3VxYl_yFJL-FRCKlW1g6Mo,337
3
+ helper/commands/__init__.py,sha256=HFk0MU1U4VqGJUkb9SvCoslqpYSah8KePP9tP8Xzzs4,30
4
+ helper/commands/arch.py,sha256=AREsblUki99P_wVpi44maQd7KA8IlUCJ6ilzJAQODDU,141
5
+ helper/commands/docker.py,sha256=ZmEk3B2xor0p3AQJPkVQLz0biFa1MSsoF-dRxOHDvsI,25349
6
+ helper/commands/internal_ip.py,sha256=ZN7c1HRgB5f-wRk9IwfGQeI3YuZqmPW-UflIpGEImt0,786
7
+ helper/commands/nixos.py,sha256=--Uz2lA-xw6-spp1WBjzzfu4-imFtcziyZuUHZk3Pxs,3113
8
+ helper/commands/public_ip.py,sha256=HS99RDYCaKDZ-AxMQhUwazgR-tT6IGlBb5Qn0f5ITPg,150
9
+ helper_cli-0.1.11.dist-info/METADATA,sha256=6AR44RTeCCTlJvglidOgz754evOnjEhUeWb7yUqvocY,131
10
+ helper_cli-0.1.11.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ helper_cli-0.1.11.dist-info/entry_points.txt,sha256=4EoFQ0yRogLTvStcbjlpkTqayWmiRqbMwkcDBcgQbK8,43
12
+ helper_cli-0.1.11.dist-info/top_level.txt,sha256=VM8lkErPJijbKhnfEGA_hE_YDXde4iizgqWKloZIxW8,7
13
+ helper_cli-0.1.11.dist-info/RECORD,,
@@ -1,13 +0,0 @@
1
- helper/main.py,sha256=kFQ7ZyeRWPwzWlxb603tHpGvjscWlcmt2rxwt_LN09g,779
2
- helper/utils.py,sha256=JynYacwFA9kgkDuWpGPCj3VxYl_yFJL-FRCKlW1g6Mo,337
3
- helper/commands/__init__.py,sha256=HFk0MU1U4VqGJUkb9SvCoslqpYSah8KePP9tP8Xzzs4,30
4
- helper/commands/arch.py,sha256=AREsblUki99P_wVpi44maQd7KA8IlUCJ6ilzJAQODDU,141
5
- helper/commands/docker.py,sha256=BtkBK7RUyu8yKhYdyaJxFJ-fm_NcQWwC8fKavnrrze0,23835
6
- helper/commands/internal_ip.py,sha256=ZN7c1HRgB5f-wRk9IwfGQeI3YuZqmPW-UflIpGEImt0,786
7
- helper/commands/nixos.py,sha256=--Uz2lA-xw6-spp1WBjzzfu4-imFtcziyZuUHZk3Pxs,3113
8
- helper/commands/public_ip.py,sha256=HS99RDYCaKDZ-AxMQhUwazgR-tT6IGlBb5Qn0f5ITPg,150
9
- helper_cli-0.1.9.dist-info/METADATA,sha256=1HfCL5LQ12cE9K4BKgEx5X-ys6A4N1P35QpFRpDikg0,130
10
- helper_cli-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- helper_cli-0.1.9.dist-info/entry_points.txt,sha256=4EoFQ0yRogLTvStcbjlpkTqayWmiRqbMwkcDBcgQbK8,43
12
- helper_cli-0.1.9.dist-info/top_level.txt,sha256=VM8lkErPJijbKhnfEGA_hE_YDXde4iizgqWKloZIxW8,7
13
- helper_cli-0.1.9.dist-info/RECORD,,