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')
|
required_attrs = ('__package__', '__command__', '__description__', 'main')
|
||||||
|
|
||||||
|
|
||||||
|
order = ('help', 'version', 'init', 'list', 'update', 'add', 'remove')
|
||||||
|
|
||||||
|
|
||||||
def list_subcommands():
|
def list_subcommands():
|
||||||
COMMANDS = {}
|
COMMANDS = []
|
||||||
for filename in os.listdir(CLI_DIR):
|
for filename in os.listdir(CLI_DIR):
|
||||||
if filename.startswith('archivebox_') and filename.endswith('.py'):
|
if filename.startswith('archivebox_') and filename.endswith('.py'):
|
||||||
subcommand = filename.replace('archivebox_', '').replace('.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 all(hasattr(module, attr) for attr in required_attrs)
|
||||||
assert module.__command__.split(' ')[-1] == subcommand
|
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):
|
def run_subcommand(subcommand: str, args=None):
|
||||||
|
|
|
@ -8,6 +8,7 @@ import sys
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
from ..legacy.util import reject_stdin
|
from ..legacy.util import reject_stdin
|
||||||
|
from ..legacy.config import ANSI
|
||||||
from . import list_subcommands
|
from . import list_subcommands
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,14 +29,15 @@ def main(args=None):
|
||||||
for cmd, summary in list_subcommands().items()
|
for cmd, summary in list_subcommands().items()
|
||||||
)
|
)
|
||||||
|
|
||||||
print(f'''ArchiveBox: The self-hosted internet archive.
|
print('''{green}ArchiveBox: The self-hosted internet archive.{reset}
|
||||||
Usage:
|
|
||||||
|
{lightblue}Usage:{reset}
|
||||||
archivebox [command] [--help] [--version] [...args]
|
archivebox [command] [--help] [--version] [...args]
|
||||||
|
|
||||||
Comamnds:
|
{lightblue}Comamnds:{reset}
|
||||||
{COMMANDS_HELP_TEXT}
|
{}
|
||||||
|
|
||||||
Example Use:
|
{lightblue}Example Use:{reset}
|
||||||
mkdir my-archive; cd my-archive/
|
mkdir my-archive; cd my-archive/
|
||||||
archivebox init
|
archivebox init
|
||||||
|
|
||||||
|
@ -46,9 +48,9 @@ Example Use:
|
||||||
archivebox update --resume=15109948213.123
|
archivebox update --resume=15109948213.123
|
||||||
archivebox list --sort=timestamp --csv=timestamp,url,is_archived
|
archivebox list --sort=timestamp --csv=timestamp,url,is_archived
|
||||||
|
|
||||||
Documentation:
|
{lightblue}Documentation:{reset}
|
||||||
https://github.com/pirate/ArchiveBox/wiki
|
https://github.com/pirate/ArchiveBox/wiki
|
||||||
''')
|
'''.format(COMMANDS_HELP_TEXT, **ANSI))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -30,11 +30,12 @@ def init(output_dir: str=OUTPUT_DIR):
|
||||||
|
|
||||||
if not is_empty:
|
if not is_empty:
|
||||||
if existing_index:
|
if existing_index:
|
||||||
stderr('[√] You already have an archive setup up in this folder. To add new links, you can run:')
|
stderr('{green}[√] You already have an archive index in this folder.{reset}'.format(**ANSI))
|
||||||
stderr(' archivebox add https://example.com')
|
stderr(' To add new links, you can run:')
|
||||||
|
stderr(" archivebox add 'https://example.com'")
|
||||||
stderr()
|
stderr()
|
||||||
stderr('[i] Fore more usage and examples, run "archivebox help" or visit:')
|
stderr(' For more usage and examples, run:')
|
||||||
stderr(' https://github.com/pirate/ArchiveBox/wiki/Usage')
|
stderr(' archivebox help')
|
||||||
# TODO: import old archivebox version's archive data folder
|
# TODO: import old archivebox version's archive data folder
|
||||||
|
|
||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue