Ejemplo n.º 1
0
 def print_help(self) -> None:
     help_command: Command = Finder.find_only(
         [command for command in self._commands if command.name == 'help'])
     arguments: Dict[str, str] = help_command.parse_arguments()
     if 'command' in arguments:
         command_name: str = arguments['command']
         user_command: Command = Finder.find_only([
             command for command in self._commands
             if command.name == command_name
         ])
         user_command.print_help()
     else:
         self._print_group_help()
Ejemplo n.º 2
0
 def find_file(self,
               name: str,
               ignored_directories: List[Regex] = None) -> File:
     return Finder.find_only([
         file_ for file_ in self.find_files(ignored_directories)
         if file_.name == name
     ])
Ejemplo n.º 3
0
 def _find_command(self, index: int) -> Command:
     command_names: List[str] = [command.name for command in self._commands]
     user_input: str = sys.argv[index]
     if user_input not in command_names:
         raise ValueError(
             'Invalid command \'{0}\' given'.format(user_input))
     return Finder.find_only([
         command for command in self._commands if command.name == user_input
     ])
Ejemplo n.º 4
0
 def _validate(self) -> None:
     flag_names: List[str] = [flag.names[0] for flag in self._flags
                              ] + [flag.names[1] for flag in self._flags]
     if ('--help' in sys.argv or '-h' in sys.argv) and self._name != 'help':
         self.print_help()
         sys.exit()
     duplicate_flag_names: Set[str] = Finder.find_duplicates(flag_names)
     if len(duplicate_flag_names) > 0:
         raise ValueError('Duplicate flag definitions found: ' +
                          str(duplicate_flag_names))
     argument_names: List[str] = [
         argument.name for argument in self._arguments
     ]
     duplicate_argument_names: Set[str] = Finder.find_duplicates(
         argument_names)
     if len(duplicate_argument_names) > 0:
         raise ValueError('Duplicate argument definitions found: ' +
                          str(duplicate_argument_names))
Ejemplo n.º 5
0
 def find_directory(self,
                    name: str,
                    ignored_directories: List[Regex] = None,
                    regex: Regex = None) -> 'Directory':
     return Finder.find_only([
         directory
         for directory in self.find_directories(ignored_directories, regex)
         if directory.name == name
     ])
Ejemplo n.º 6
0
 def find_one_by_text(self, text: str) -> 'HtmlTag':
     return Finder.find_only(self.find_all_by_text(text))
Ejemplo n.º 7
0
 def find_one_by_name(self, name: str) -> 'HtmlTag':
     return Finder.find_only(self.find_all_by_name(name))
Ejemplo n.º 8
0
 def find_by_id(self, id_name: str) -> 'HtmlTag':
     return Finder.find_only(self._find_all_by_id(id_name))
Ejemplo n.º 9
0
 def get_one_by_class(self, class_name: str) -> 'HtmlTag':
     return Finder.find_only(self.get_all_by_class(class_name))
Ejemplo n.º 10
0
 def get_by_id(self, id_name: str) -> 'HtmlTag':
     return Finder.find_only([
         child for child in self._children
         if 'id' in child.attributes and child.attributes['id'] == id_name
     ])
Ejemplo n.º 11
0
 def find_one_by_attribute(self,
                           name: str,
                           value: str = None) -> 'XmlElement':
     return Finder.find_only(self.find_all_by_attribute(name, value))
Ejemplo n.º 12
0
 def find_one_by_text(self, text: str) -> 'XmlElement':
     return Finder.find_only(self.find_all_by_text(text))
Ejemplo n.º 13
0
 def find_one_by_name(self, name: str) -> 'XmlElement':
     return Finder.find_only(self.find_all_by_name(name))
Ejemplo n.º 14
0
 def _find_flag(self, user_input_flag) -> Flag:
     return Finder.find_only([
         flag for flag in self._flags if user_input_flag == flag.names[0]
         or user_input_flag == flag.names[1]
     ])
Ejemplo n.º 15
0
 def get_directory(self, name: str) -> 'Directory':
     return Finder.find_only([
         directory for directory in self.get_directories()
         if directory.name == name
     ])
Ejemplo n.º 16
0
 def get_file(self, name: str) -> File:
     return Finder.find_only(
         [file_ for file_ in self.get_files() if file_.name == name])