Coverage for aipyapp/cli/command/cmd_help.py: 0%

1 from rich import print

2

3 from ... import T

4 from .base import Completable

5 from .base_parser import ParserCommand

6 from .utils import print_table

7

8 class HelpCommand(ParserCommand):

9 name = 'help'

10 description = T('Show available commands or detailed help for a specific command')

11

12 def add_arguments(self, parser):

13 parser.add_argument('target_command', nargs='?', help='Command to show detailed help for')

14

15 def get_arg_values(self, arg, subcommand=None, partial_value=''):

16 if arg.name == 'target_command':

17 return [Completable(cmd.name, cmd.description) for cmd in self.manager.commands.values()]

18 else:

19 return []

20

21 def execute(self, args):

22 manager = self.manager

23 if args.target_command:

24 if args.target_command in manager.commands:

25 parser = manager.commands[args.target_command].parser

26 print(f"Help for command '{args.target_command}':")

27 print(parser.format_help())

28 else:

29 print(f"Unknown command: {args.target_command}")

30 else:

31 rows = []

32 for cmd, cmd_instance in sorted(manager.commands.items()):

33 rows.append([f"/{cmd}", cmd_instance.description])

34 print_table(rows, headers=[T('Command'), T('Description')], title=T('Available commands'))

35 print()

36 print(T("Or directly enter the question to be processed by AI, for example:\n>> Who are you?"))

37 print()