mirror of
https://github.com/ArchiveBox/ArchiveBox.git
synced 2025-05-13 06:34:25 -04:00
colorized and better command sorting in help msg
This commit is contained in:
parent
718e25c973
commit
4ca9a0beac
3 changed files with 20 additions and 14 deletions
|
@ -8,8 +8,11 @@ CLI_DIR = os.path.dirname(os.path.abspath(__file__))
|
|||
required_attrs = ('__package__', '__command__', '__description__', 'main')
|
||||
|
||||
|
||||
order = ('help', 'version', 'init', 'list', 'update', 'add', 'remove')
|
||||
|
||||
|
||||
def list_subcommands():
|
||||
COMMANDS = {}
|
||||
COMMANDS = []
|
||||
for filename in os.listdir(CLI_DIR):
|
||||
if filename.startswith('archivebox_') and filename.endswith('.py'):
|
||||
subcommand = filename.replace('archivebox_', '').replace('.py', '')
|
||||
|
@ -17,9 +20,9 @@ def list_subcommands():
|
|||
|
||||
assert all(hasattr(module, attr) for attr in required_attrs)
|
||||
assert module.__command__.split(' ')[-1] == subcommand
|
||||
COMMANDS[subcommand] = module.__description__
|
||||
COMMANDS.append((subcommand, module.__description__))
|
||||
|
||||
return COMMANDS
|
||||
return dict(sorted(COMMANDS, key=lambda cmd: order.index(cmd[0]) if cmd[0] in order else 10 + len(cmd[0])))
|
||||
|
||||
|
||||
def run_subcommand(subcommand: str, args=None):
|
||||
|
|
|
@ -8,6 +8,7 @@ import sys
|
|||
import argparse
|
||||
|
||||
from ..legacy.util import reject_stdin
|
||||
from ..legacy.config import ANSI
|
||||
from . import list_subcommands
|
||||
|
||||
|
||||
|
@ -28,14 +29,15 @@ def main(args=None):
|
|||
for cmd, summary in list_subcommands().items()
|
||||
)
|
||||
|
||||
print(f'''ArchiveBox: The self-hosted internet archive.
|
||||
Usage:
|
||||
print('''{green}ArchiveBox: The self-hosted internet archive.{reset}
|
||||
|
||||
{lightblue}Usage:{reset}
|
||||
archivebox [command] [--help] [--version] [...args]
|
||||
|
||||
Comamnds:
|
||||
{COMMANDS_HELP_TEXT}
|
||||
{lightblue}Comamnds:{reset}
|
||||
{}
|
||||
|
||||
Example Use:
|
||||
{lightblue}Example Use:{reset}
|
||||
mkdir my-archive; cd my-archive/
|
||||
archivebox init
|
||||
|
||||
|
@ -46,9 +48,9 @@ Example Use:
|
|||
archivebox update --resume=15109948213.123
|
||||
archivebox list --sort=timestamp --csv=timestamp,url,is_archived
|
||||
|
||||
Documentation:
|
||||
{lightblue}Documentation:{reset}
|
||||
https://github.com/pirate/ArchiveBox/wiki
|
||||
''')
|
||||
'''.format(COMMANDS_HELP_TEXT, **ANSI))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -30,11 +30,12 @@ def init(output_dir: str=OUTPUT_DIR):
|
|||
|
||||
if not is_empty:
|
||||
if existing_index:
|
||||
stderr('[√] You already have an archive setup up in this folder. To add new links, you can run:')
|
||||
stderr(' archivebox add https://example.com')
|
||||
stderr('{green}[√] You already have an archive index in this folder.{reset}'.format(**ANSI))
|
||||
stderr(' To add new links, you can run:')
|
||||
stderr(" archivebox add 'https://example.com'")
|
||||
stderr()
|
||||
stderr('[i] Fore more usage and examples, run "archivebox help" or visit:')
|
||||
stderr(' https://github.com/pirate/ArchiveBox/wiki/Usage')
|
||||
stderr(' For more usage and examples, run:')
|
||||
stderr(' archivebox help')
|
||||
# TODO: import old archivebox version's archive data folder
|
||||
|
||||
raise SystemExit(1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue