コード例 #1
0
 def add_arguments(self, parser, cli_name):
     self._subparser = parser
     # add arguments and sub-commands of verbs
     add_subparsers_on_demand(parser,
                              cli_name,
                              '_verb',
                              'ros2interface.verb',
                              required=False)
コード例 #2
0
 def add_arguments(self, parser, cli_name):
     self._subparser = parser
     # get verb extensions and let them add their arguments
     add_subparsers_on_demand(parser,
                              cli_name,
                              '_verb',
                              'ros2trace_analysis.verb',
                              required=False)
コード例 #3
0
 def add_arguments(self, parser, cli_name, *, argv=None):
     self._subparser = parser
     # get verb extensions and let them add their arguments
     add_subparsers_on_demand(parser,
                              cli_name,
                              '_verb',
                              'sros2.verb',
                              required=False,
                              argv=argv)
コード例 #4
0
    def add_arguments(self, parser, cli_name):
        self._subparser = parser
        parser.add_argument('--include-hidden-services',
                            action='store_true',
                            help='Consider hidden services as well')

        # add arguments and sub-commands of verbs
        add_subparsers_on_demand(parser,
                                 cli_name,
                                 '_verb',
                                 'ros2service.verb',
                                 required=False)
コード例 #5
0
def main(*, script_name='ros2', argv=None, description=None, extension=None):
    if description is None:
        description = f'{script_name} is an extensible command-line tool ' \
            'for ROS 2.'

    # top level parser
    parser = argparse.ArgumentParser(
        description=description,
        formatter_class=argparse.RawDescriptionHelpFormatter
    )

    # add arguments for command extension(s)
    if extension:
        extension.add_arguments(parser, script_name)
    else:
        # get command entry points as needed
        selected_extension_key = '_command'
        add_subparsers_on_demand(
            parser, script_name, selected_extension_key, 'ros2cli.command',
            # hide the special commands in the help
            hide_extensions=['extension_points', 'extensions'],
            required=False, argv=argv)

    # register argcomplete hook if available
    try:
        from argcomplete import autocomplete
    except ImportError:
        pass
    else:
        autocomplete(parser, exclude=['-h', '--help'])

    # parse the command line arguments
    args = parser.parse_args(args=argv)

    if extension is None:
        # get extension identified by the passed command (if available)
        extension = getattr(args, selected_extension_key, None)

    # handle the case that no command was passed
    if extension is None:
        parser.print_help()
        return 0

    # call the main method of the extension
    try:
        rc = extension.main(parser=parser, args=args)
    except KeyboardInterrupt:
        rc = signal.SIGINT
    except RuntimeError as e:
        rc = str(e)
    return rc
コード例 #6
0
ファイル: _nodl.py プロジェクト: kyrofa/nodl
 def add_arguments(self,
                   parser: argparse.ArgumentParser,
                   cli_name: str,
                   *,
                   argv: Optional[List] = None):
     self._subparser = parser
     add_subparsers_on_demand(
         parser=parser,
         cli_name=cli_name,
         dest='_verb',
         group_name='ros2nodl.verb',
         required=False,
         argv=argv,
     )
コード例 #7
0
 def add_arguments(self, parser, cli_name):
     group = parser.add_mutually_exclusive_group(required=False)
     group.add_argument('--report',
                        '-r',
                        action='store_true',
                        help='Print all reports.')
     group.add_argument('--report-failed',
                        '-rf',
                        action='store_true',
                        help='Print reports of failed checks only.')
     parser.add_argument(
         '--include-warnings',
         '-iw',
         action='store_true',
         help=
         'Include warnings as failed checks. Warnings are ignored by default.'
     )
     # add arguments and sub-commands of verbs
     add_subparsers_on_demand(parser,
                              cli_name,
                              '_verb',
                              'ros2doctor.verb',
                              required=False)
コード例 #8
0
def main(*, script_name='ros2', argv=None, description=None, extension=None):
    if description is None:
        description = f'{script_name} is an extensible command-line tool ' \
            'for ROS 2.'

    # top level parser
    parser = argparse.ArgumentParser(
        description=description,
        formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument(
        '--use-python-default-buffering',
        action='store_true',
        default=False,
        help=
        ('Do not force line buffering in stdout and instead use the python default buffering, '
         'which might be affected by PYTHONUNBUFFERED/-u and depends on whatever stdout is '
         'interactive or not'))

    # add arguments for command extension(s)
    if extension:
        extension.add_arguments(parser, script_name)
    else:
        # get command entry points as needed
        selected_extension_key = '_command'
        add_subparsers_on_demand(
            parser,
            script_name,
            selected_extension_key,
            'ros2cli.command',
            # hide the special commands in the help
            hide_extensions=['extension_points', 'extensions'],
            required=False,
            argv=argv)

    # register argcomplete hook if available
    try:
        from argcomplete import autocomplete
    except ImportError:
        pass
    else:
        autocomplete(parser, exclude=['-h', '--help'])

    # parse the command line arguments
    args = parser.parse_args(args=argv)

    if not args.use_python_default_buffering:
        # Make the output always line buffered.
        # TextIoWrapper has a reconfigure() method, call that if available.
        # https://docs.python.org/3/library/io.html#io.TextIOWrapper.reconfigure
        try:
            sys.stdout.reconfigure(line_buffering=True)
        except AttributeError:
            # if stdout is not a TextIoWrapper instance, or we're using python older than 3.7,
            # force line buffering by patching print
            builtins.print = functools.partial(print, flush=True)

    if extension is None:
        # get extension identified by the passed command (if available)
        extension = getattr(args, selected_extension_key, None)

    # handle the case that no command was passed
    if extension is None:
        parser.print_help()
        return 0

    # call the main method of the extension
    try:
        rc = extension.main(parser=parser, args=args)
    except KeyboardInterrupt:
        rc = signal.SIGINT
    except RuntimeError as e:
        rc = str(e)
    return rc