fix help command output docstrings and more CLI log coloring

This commit is contained in:
Nick Sweeting 2024-09-30 18:29:17 -07:00
parent 7489663ff3
commit 31ce490321
No known key found for this signature in database
4 changed files with 21 additions and 13 deletions

View file

@ -45,7 +45,9 @@ class ShellConfig(BaseConfigSet):
@computed_field @computed_field
@property @property
def TERM_WIDTH(self) -> int: def TERM_WIDTH(self) -> int:
return shutil.get_terminal_size((100, 10)).columns if not self.IS_TTY:
return 200
return shutil.get_terminal_size((140, 10)).columns
@computed_field @computed_field
@property @property

View file

@ -228,7 +228,7 @@ def progress_bar(seconds: int, prefix: str='', ANSI: Dict[str, str]=ANSI) -> Non
def log_cli_command(subcommand: str, subcommand_args: List[str], stdin: Optional[str | IO], pwd: str): def log_cli_command(subcommand: str, subcommand_args: List[str], stdin: Optional[str | IO], pwd: str):
args = ' '.join(subcommand_args) args = ' '.join(subcommand_args)
version_msg = '[dark_magenta]\\[i] [{now}] ArchiveBox v{VERSION}: [/dark_magenta][green4]archivebox [green3]{subcommand}[green2] {args}[/green2]'.format( version_msg = '[dark_magenta]\\[{now}][/dark_magenta] [dark_red]ArchiveBox[/dark_red] [dark_goldenrod]v{VERSION}[/dark_goldenrod]: [green4]archivebox [green3]{subcommand}[green2] {args}[/green2]'.format(
now=datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S'), now=datetime.now(timezone.utc).strftime('%Y-%m-%d %H:%M:%S'),
VERSION=VERSION, VERSION=VERSION,
subcommand=subcommand, subcommand=subcommand,

View file

@ -96,20 +96,20 @@ def help(out_dir: Path=DATA_DIR) -> None:
all_subcommands = CLI_SUBCOMMANDS all_subcommands = CLI_SUBCOMMANDS
COMMANDS_HELP_TEXT = '\n '.join( COMMANDS_HELP_TEXT = '\n '.join(
f'{cmd.ljust(20)} {summary}' f'{cmd.ljust(20)} {func.__doc__}'
for cmd, summary in all_subcommands.items() for cmd, func in all_subcommands.items()
if cmd in meta_cmds if cmd in meta_cmds
) + '\n\n ' + '\n '.join( ) + '\n\n ' + '\n '.join(
f'{cmd.ljust(20)} {summary}' f'{cmd.ljust(20)} {func.__doc__}'
for cmd, summary in all_subcommands.items() for cmd, func in all_subcommands.items()
if cmd in main_cmds if cmd in main_cmds
) + '\n\n ' + '\n '.join( ) + '\n\n ' + '\n '.join(
f'{cmd.ljust(20)} {summary}' f'{cmd.ljust(20)} {func.__doc__}'
for cmd, summary in all_subcommands.items() for cmd, func in all_subcommands.items()
if cmd in archive_cmds if cmd in archive_cmds
) + '\n\n ' + '\n '.join( ) + '\n\n ' + '\n '.join(
f'{cmd.ljust(20)} {summary}' f'{cmd.ljust(20)} {func.__doc__}'
for cmd, summary in all_subcommands.items() for cmd, func in all_subcommands.items()
if cmd not in display_first if cmd not in display_first
) )
@ -127,8 +127,10 @@ def help(out_dir: Path=DATA_DIR) -> None:
{} {}
{lightred}Example Use:{reset} {lightred}Example Use:{reset}
mkdir my-archive; cd my-archive/ mkdir -p ~/archivebox/data; cd ~/archivebox/data
archivebox init archivebox init
archivebox setup
archivebox version
archivebox status archivebox status
archivebox add https://example.com/some/page archivebox add https://example.com/some/page

View file

@ -1,8 +1,9 @@
__package__ = 'archivebox' __package__ = 'archivebox'
import sys
import shutil
import django import django
import pydantic import pydantic
import shutil
import django_stubs_ext import django_stubs_ext
@ -21,9 +22,12 @@ timezone.utc = datetime.timezone.utc
# Install rich for pretty tracebacks in console logs # Install rich for pretty tracebacks in console logs
# https://rich.readthedocs.io/en/stable/traceback.html#traceback-handler # https://rich.readthedocs.io/en/stable/traceback.html#traceback-handler
from rich.traceback import install from rich.traceback import install
install(show_locals=True, word_wrap=False, locals_max_length=10, locals_hide_dunder=True, suppress=[django, pydantic], extra_lines=2, width=shutil.get_terminal_size((100, 10)).columns - 1) TERM_WIDTH = (shutil.get_terminal_size((200, 10)).columns - 1) if sys.stdout.isatty() else 200
# os.environ.setdefault('COLUMNS', str(TERM_WIDTH))
install(show_locals=True, word_wrap=False, locals_max_length=10, locals_hide_dunder=True, suppress=[django, pydantic], extra_lines=2, width=TERM_WIDTH)
from daphne import access from daphne import access