Fix argv0

This commit is contained in:
Sleepy Monax 2024-02-19 20:32:13 +01:00
parent 886c90dd6f
commit f783f5607c
4 changed files with 20 additions and 9 deletions

View file

@ -76,7 +76,7 @@ def _(args: RootArgs):
@cli.command("u", "usage", "Show usage information")
def _():
print(f"Usage: {const.ARGV0} <command> [args...]")
print(f"Usage: {const.ARGV0} {cli._root.usage()}")
@cli.command("v", "version", "Show current version")

View file

@ -4,7 +4,7 @@ import typing as tp
import dataclasses as dt
import logging
from typing import Any, Callable, Optional, Union
from typing import Any, Callable, Optional
from cutekit import vt100, const
@ -536,7 +536,7 @@ class Schema:
@dt.dataclass
class Command:
shortName: Optional[str]
longName: str
path: list[str] = dt.field(default_factory=list)
description: str = ""
epilog: Optional[str] = None
@ -544,7 +544,10 @@ class Command:
callable: Optional[tp.Callable] = None
subcommands: dict[str, "Command"] = dt.field(default_factory=dict)
populated: bool = False
path: list[str] = dt.field(default_factory=list)
@property
def longName(self) -> str:
return self.path[-1]
def _spliceArgs(self, args: list[str]) -> tuple[list[str], list[str]]:
rest = args[:]
@ -601,9 +604,6 @@ class Command:
print(self.epilog)
print()
# for name, sub in self.subcommands.items():
# sub.help(f"{cmd} {name}")
def usage(self) -> str:
res = " "
if self.schema:
@ -716,7 +716,6 @@ def command(shortName: Optional[str], longName: str, description: str = "") -> C
raise ValueError(f"Command '{longName}' is already defined")
cmd.shortName = shortName
cmd.longName = len(path) > 0 and path[-1] or ""
cmd.description = description
cmd.schema = schema
cmd.callable = fn

View file

@ -18,7 +18,9 @@ class Uninitialized:
VERSION = (0, 7, 0, "dev")
VERSION_STR = f"{VERSION[0]}.{VERSION[1]}.{VERSION[2]}{'-' + VERSION[3] if len(VERSION) >= 4 else ''}"
MODULE_DIR = os.path.dirname(os.path.realpath(__file__))
ARGV0 = os.path.basename(sys.argv[0])
ARGV0 = "cutekit"
PROJECT_CK_DIR = ".cutekit"
GLOBAL_CK_DIR = os.path.join(os.path.expanduser("~"), ".cutekit")
BUILD_DIR = os.path.join(PROJECT_CK_DIR, "build")

View file

@ -237,6 +237,8 @@ def _(args: PodKillArgs):
def _():
client = docker.from_env()
hasPods = False
vt100.subtitle("Pods")
for container in client.containers.list(all=True):
if not container.name.startswith(podPrefix):
continue
@ -246,6 +248,14 @@ def _():
if not hasPods:
print(vt100.p("(No pod found)"))
print()
vt100.subtitle("Images")
for name, image in IMAGES.items():
print(vt100.p(f"{name}"))
print()
@cli.command("e", "pod/exec", "Execute a command in a pod")
def podExecCmd(args: PodExecArgs):