def _get_commands_in_context(opt_template, context_path=None): """seek for available commands in current context (internally called)""" command_completion = [] # list available command in template suiting context (even command "followed by template" native of that template) if opt_template: command_completion.extend([ command for command in commands.get_commands_by_criteria( template=opt_template) if command.is_right_context(context_path, verbose=False) ]) # add commands followed by a template if we don't already have a template provided (native command followed by template has already been handled before) else: command_completion.extend([ command for command in commands.get_commands_by_criteria( followed_by_template=True) if command.is_right_context(context_path, verbose=False) ]) # add builtin commands command_completion.extend([ command for command in commands.get_commands_by_criteria(template="builtins") if command.is_right_context(context_path, verbose=False) ]) return command_completion
def _get_commands_in_context(opt_template, context_path=None): """seek for available commands in current context (internally called)""" command_completion = [] # list available command in template suiting context (even command "followed by template" native of that template) if opt_template: command_completion.extend([command for command in commands.get_commands_by_criteria(template=opt_template) if command.is_right_context(context_path, verbose=False)]) # add commands followed by a template if we don't already have a template provided (native command followed by template has already been handled before) else: command_completion.extend([command for command in commands.get_commands_by_criteria(followed_by_template=True) if command.is_right_context(context_path, verbose=False)]) # add builtin commands command_completion.extend([command for command in commands.get_commands_by_criteria(template="builtins") if command.is_right_context(context_path, verbose=False)]) return command_completion
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_completion_in_context(argv, context_path=None): """seek for available completion (command, example…) : return tuples with list of available commands and origin (default or example) """ 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 ("-e", "--example"): available_completion.extend(['example_argument']) 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_example) = process_command_line(argv[3:]) if not opt_example and configurationhandler.loadConfig(can_stop=False, config_file_path=context_path) == 0: try: opt_example = configurationhandler.project_config['example'] 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_example, 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_example, 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", "-e", "--example", "--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_commands_in_template(template): '''get a list of commands for a template''' return commands.get_commands_by_criteria(template=template)