def do_tasks(self, args): """ Retrieves a listing of all tasks for the currently active project, if available. If there is no currently active project, simply lists all tasks across all projects. Takes an optional project name or id, only listing the tasks of the given project. """ project_id = None if self.state.active_project: project_id = self.state.active_project.obj_id elif args: project_id = args[0] pos = 0 if project_id: project = Project(self._wrapper, project_id) prnt('<', project, '>', VIOLET, None, VIOLET) pos = cli.print_listing(project, pos) return project.tasks else: projects = self._wrapper.get_projects() tasks = [] for project in projects: prnt('<', project, '>', VIOLET, None, VIOLET) pos = cli.print_listing(project, pos) tasks.extend(project.tasks) return tasks
def get_conf_json_or_die(conf_filename, required_fields, optional_fields): conf_filepath = os.path.join(os.path.expanduser('~'), conf_filename) with open(conf_filepath) as conf_file: try: conf_json = json.load(conf_file) return TodoConfig(conf_json, required_fields, optional_fields) except json.decoder.JSONDecodeError: prnt("Invalid JSON in {}.".format(conf_filename), RED) exit(1)
def cmd_trycatch(self, arg): cmds = _decompose(arg) if len(cmds) > 1: self.cmdqueue.extend(cmds[1:]) args = shlex.split(cmds[0] if cmds else arg, comments=True) try: return func(self, args) except CmdError as e: prnt("Error: {}.".format(str(e)), RED) prnt("Command details:", RED) prnt("\tCommand:\n\t\t->\"{}\"".format(pure_cmd_name(func)), RED) prnt("\tArgument string:\n\t\t->\"{}\"".format(arg), RED)
def print_listing(items, pos): for offset, item in enumerate(items): prnt(pos + offset, '. ', item, VIOLET, None, None) return pos + len(items)
def do_exit(self, args): """ Exits the CLI application. """ prnt("Bye", VIOLET) exit(0)