def get_completion_in_context(argv, context_path=None): """seek for available completion (command, template…) : return tuples with list of available commands and origin (default or template) """ if context_path is None: context_path = os.getcwd() else: context_path = os.path.abspath(context_path) available_completion = [] # get available templates after option if needed if argv[-2] in ("-t", "--template"): available_completion.extend( [template for template in commands.get_all_templates()]) else: # treat commands and try to get the template from the project directory if we are in a project (if not already provided by the -t option) (opt_command, opt_template) = process_command_line(argv[3:]) if not opt_template and configurationhandler.loadConfig( can_stop=False, config_file_path=context_path) == 0: try: opt_template = configurationhandler.project_config['template'] except KeyError: pass # if no command yet, check for available command if len(opt_command) == 1: available_completion.extend([ command.name for command in _get_commands_in_context( opt_template, context_path) ]) else: # ask for the command what she needs (it automatically handle the case of command followed by template and command followed by command) for command in commands.get_commands_by_criteria( name=opt_command[0] ): # as 1: is '' or the begining of a word available_completion.extend( command.shell_completion(opt_template, opt_command[1:])) # dash option completion. Some commands have dash args, but we also have them. So we take what command thought # should be the completions and add our own. We also strip anything that doesn't start with a dash, since many # completion functions are naive and just give all possible matches, even if they don't match. if argv[-1].startswith("-"): available_completion.extend([ "-h", "--help", "-t", "--template", "--staging", "--verbose", "--version" ]) available_completion = [ arg for arg in available_completion if arg.startswith('-') ] # remove duplicates and sort completion = list(set(available_completion)) completion.sort() return (completion)
def list_template_for_command(command_name): """from the command_name, return all templates containing it""" proposed_templates = [] for template in commands.get_all_templates(): try: commands.get_all_commands()[template][command_name] proposed_templates.append(template) except KeyError: pass return proposed_templates
def print_template_candidates(for_cmd=None): templates = [] if for_cmd: possible_command = commands.get_command_names_by_criteria(name=for_cmd, followed_by_template=True) if possible_command: templates = tools.list_template_for_command(for_cmd) else: templates = templates or commands.get_all_templates() if templates: templates.sort() print _("Candidate templates are: %s") % ", ".join(templates)
def print_template_candidates(for_cmd=None): templates = [] if for_cmd: possible_command = commands.get_command_names_by_criteria( name=for_cmd, followed_by_template=True) if possible_command: templates = tools.list_template_for_command(for_cmd) else: templates = templates or commands.get_all_templates() if templates: templates.sort() print _("Candidate templates are: %s") % ", ".join(templates)
def get_completion_in_context(argv, context_path=None): """seek for available completion (command, template…) : return tuples with list of available commands and origin (default or template) """ if context_path is None: context_path = os.getcwd() else: context_path = os.path.abspath(context_path) available_completion = [] # get available templates after option if needed if argv[-2] in ("-t", "--template"): available_completion.extend([template for template in commands.get_all_templates()]) else: # treat commands and try to get the template from the project directory if we are in a project (if not already provided by the -t option) (opt_command, opt_template) = process_command_line(argv[3:]) if not opt_template and configurationhandler.loadConfig(can_stop=False, config_file_path=context_path) == 0: try: opt_template = configurationhandler.project_config['template'] except KeyError: pass # if no command yet, check for available command if len(opt_command) == 1: available_completion.extend([command.name for command in _get_commands_in_context(opt_template, context_path)]) else: # ask for the command what she needs (it automatically handle the case of command followed by template and command followed by command) for command in commands.get_commands_by_criteria(name=opt_command[0]): # as 1: is '' or the begining of a word available_completion.extend(command.shell_completion(opt_template, opt_command[1:])) # dash option completion. Some commands have dash args, but we also have them. So we take what command thought # should be the completions and add our own. We also strip anything that doesn't start with a dash, since many # completion functions are naive and just give all possible matches, even if they don't match. if argv[-1].startswith("-"): available_completion.extend(["-h", "--help", "-t", "--template", "--staging", "--verbose", "--version"]) available_completion = [arg for arg in available_completion if arg.startswith('-')] # remove duplicates and sort completion = list(set(available_completion)) completion.sort() return (completion)
def get_template_list(): '''get a generator of available template''' return commands.get_all_templates()