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

1#!/usr/bin/env python

2# -*- coding: utf-8 -*-

3

4 from .utils import print_records

5 from .base import CommandMode, Completable

6 from .base_parser import ParserCommand

7 from ... import T

8

9 class StepsCommand(ParserCommand):

10 """Steps command"""

11 name = "step"

12 description = T("Manage task steps")

13 modes = [CommandMode.TASK]

14

15 def add_subcommands(self, subparsers):

16 subparsers.add_parser('list', help=T('List task steps'))

17 subparsers.add_parser('clear', help=T('Clear task steps'))

18 parser = subparsers.add_parser('delete', help=T('Delete task steps'))

19 parser.add_argument('index', type=int, help=T('Index of the task step to delete'))

20

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

22 if subcommand == 'delete' and arg.name == 'index':

23 ctx = self.manager.context

24 return [Completable(str(step.Index), step.Instruction[:32]) for step in ctx.task.list_steps()]

25 return None

26

27 def cmd(self, args, ctx):

28 return self.cmd_list(args, ctx)

29

30 def cmd_list(self, args, ctx):

31 task = ctx.task

32 steps = task.list_steps()

33 print_records(steps, title=T("Task Steps"))

34

35 def cmd_clear(self, args, ctx):

36 task = ctx.task

37 ret = task.clear_steps()

38 if ret:

39 ctx.console.print(T("Task steps cleared"))

40 else:

41 ctx.console.print(T("Failed to clear task steps"))

42 return ret

43

44 def cmd_delete(self, args, ctx):

45 task = ctx.task

46 ret = task.delete_step(args.index)

47 if ret:

48 ctx.console.print(T("Task step deleted"))

49 else:

50 ctx.console.print(T("Failed to delete task step"))

51 return ret