Example #1
0
def add_checkout_parser(
        subparsers: argparse._SubParsersAction) -> None:  # noqa
    """Add clowder checkout parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """

    parser = subparsers.add_parser('checkout',
                                   help='Checkout local branch in projects')
    parser.formatter_class = argparse.RawTextHelpFormatter
    parser.set_defaults(func=checkout)

    add_parser_arguments(
        parser, [(['branch'],
                  dict(nargs=1,
                       action='store',
                       help='branch to checkout',
                       metavar='<branch>')),
                 (['projects'],
                  dict(metavar='<project|group>',
                       default='default',
                       nargs='*',
                       choices=CLOWDER_CONTROLLER.project_choices_with_default,
                       help=fmt.project_options_help_message(
                           'projects and groups to checkout branches for')))])
Example #2
0
def add_prune_parser(subparsers: argparse._SubParsersAction):  # noqa
    """Add clowder prune parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """

    parser = subparsers.add_parser('prune', help='Prune branches')
    parser.formatter_class = argparse.RawTextHelpFormatter
    parser.set_defaults(func=prune)

    add_parser_arguments(parser, [
        (['branch'], dict(help='name of branch to remove', metavar='<branch>')),
        (['projects'], dict(metavar='<project|group>', default='default', nargs='*',
                            choices=CLOWDER_CONTROLLER.project_choices_with_default,
                            help=fmt.project_options_help_message('projects and groups to prune'))),
        (['--force', '-f'], dict(action='store_true', help='force prune branches'))
    ])

    mutually_exclusive_arguments = [
        (['--all', '-a'], dict(action='store_true', help='prune local and remote branches')),
        (['--remote', '-r'], dict(action='store_true', help='prune remote branches'))
    ]
    add_parser_arguments(parser.add_mutually_exclusive_group(), [
        (['--all', '-a'], dict(action='store_true', help='prune local and remote branches')),
        (['--remote', '-r'], dict(action='store_true', help='prune remote branches'))
    ])
Example #3
0
def add_forall_parser(subparsers: argparse._SubParsersAction) -> None:  # noqa
    """Add clowder forall parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """

    parser = subparsers.add_parser(
        'forall', help='Run command or script in project directories')
    parser.formatter_class = argparse.RawTextHelpFormatter
    parser.set_defaults(func=forall)

    add_parser_arguments(parser, [
        (['command'],
         dict(metavar='<command>',
              nargs=1,
              default=None,
              help='command to run in project directories')),
        (['projects'],
         dict(metavar='<project|group>',
              default='default',
              nargs='*',
              choices=CLOWDER_CONTROLLER.project_choices_with_default,
              help=fmt.project_options_help_message(
                  'projects and groups to run command for'))),
        (['--ignore-errors', '-i'],
         dict(action='store_true', help='ignore errors in command or script')),
        (['--jobs', '-j'],
         dict(metavar='<n>',
              nargs=1,
              default=None,
              type=int,
              help='number of jobs to use running commands in parallel')),
    ])
Example #4
0
def add_start_parser(subparsers: argparse._SubParsersAction) -> None:  # noqa
    """Add clowder start parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """

    parser = subparsers.add_parser('start', help='Start a new branch')
    parser.formatter_class = argparse.RawTextHelpFormatter
    parser.set_defaults(func=start)

    add_parser_arguments(
        parser,
        [(['branch'],
          dict(help='name of branch to create',
               nargs=1,
               default=None,
               metavar='<branch>')),
         (['projects'],
          dict(metavar='<project|group>',
               default='default',
               nargs='*',
               choices=CLOWDER_CONTROLLER.project_choices_with_default,
               help=fmt.project_options_help_message(
                   'projects and groups to start branches for'))),
         (['--tracking', '-t'],
          dict(action='store_true', help='create remote tracking branch'))])
Example #5
0
def add_branch_parser(subparsers: argparse._SubParsersAction) -> None:  # noqa
    """Add clowder branch parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """

    parser = subparsers.add_parser('branch', help='Display current branches')
    parser.formatter_class = argparse.RawTextHelpFormatter
    parser.set_defaults(func=branch)

    add_parser_arguments(
        parser, [(['projects'],
                  dict(metavar='<project|group>',
                       default='default',
                       nargs='*',
                       choices=CLOWDER_CONTROLLER.project_choices_with_default,
                       help=fmt.project_options_help_message(
                           'projects and groups to show branches for')))])

    add_parser_arguments(
        parser.add_mutually_exclusive_group(),
        [(['--all', '-a'],
          dict(action='store_true', help='show local and remote branches')),
         (['--remote', '-r'
           ], dict(action='store_true', help='show remote branches'))])
Example #6
0
def add_herd_parser(subparsers: argparse._SubParsersAction) -> None:  # noqa
    """Add clowder herd parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """

    parser = subparsers.add_parser(
        'herd', help='Clone and update projects with latest changes')
    parser.formatter_class = argparse.RawTextHelpFormatter
    parser.set_defaults(func=herd)

    add_parser_arguments(
        parser,
        [(['projects'],
          dict(metavar='<project|group>',
               default='default',
               nargs='*',
               choices=CLOWDER_CONTROLLER.project_choices_with_default,
               help=fmt.project_options_help_message(
                   'projects and groups to show branches for'))),
         (['--jobs', '-j'],
          dict(metavar='<n>',
               nargs=1,
               default=None,
               type=int,
               help='number of jobs to use running commands in parallel')),
         (['--rebase', '-r'
           ], dict(action='store_true', help='use rebase instead of pull')),
         (['--depth', '-d'],
          dict(default=None,
               type=int,
               nargs=1,
               metavar='<n>',
               help='depth to herd')),
         (['--protocol', '-p'],
          dict(default=None,
               nargs=1,
               metavar='<protocol>',
               choices=('ssh', 'https'),
               help='git protocol to use for cloning'))])

    add_parser_arguments(parser.add_mutually_exclusive_group(),
                         [(['--branch', '-b'],
                           dict(nargs=1,
                                default=None,
                                metavar='<branch>',
                                help='branch to herd if present')),
                          (['--tag', '-t'],
                           dict(nargs=1,
                                default=None,
                                metavar='<tag>',
                                help='tag to herd if present'))])
Example #7
0
def add_stash_parser(subparsers: argparse._SubParsersAction) -> None:  # noqa
    """Add clowder stash parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """

    parser = subparsers.add_parser('stash', help='Stash current changes')
    parser.formatter_class = argparse.RawTextHelpFormatter
    parser.set_defaults(func=stash)

    add_parser_arguments(parser, [
        (['projects'],
         dict(metavar='<project|group>',
              default='default',
              nargs='*',
              choices=CLOWDER_CONTROLLER.project_choices_with_default,
              help=fmt.project_options_help_message(
                  'projects and groups to stash changes for'))),
    ])
Example #8
0
def add_reset_parser(subparsers: argparse._SubParsersAction):  # noqa
    """Add clowder reset parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """

    parser = subparsers.add_parser('reset', help='Reset branches to upstream commits or '
                                                 'check out detached HEADs for tags and shas')
    parser.formatter_class = argparse.RawTextHelpFormatter
    parser.set_defaults(func=reset)

    add_parser_arguments(parser, [
        (['projects'], dict(metavar='<project|group>', default='default', nargs='*',
                            choices=CLOWDER_CONTROLLER.project_choices_with_default,
                            help=fmt.project_options_help_message('projects and groups to reset'))),
        (['--jobs', '-j'], dict(metavar='<n>', nargs=1, default=None, type=int,
                                help='number of jobs to use running commands in parallel')),
        # (['--timestamp', '-t'], dict(choices=CLOWDER_CONTROLLER.project_names,
        #                              default=None, nargs=1, metavar='<timestamp>',
        #                              help='project to reset timestamps relative to'))
    ])
Example #9
0
def add_status_parser(subparsers: argparse._SubParsersAction) -> None:  # noqa
    """Add clowder status parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """

    parser = subparsers.add_parser('status', help='Print project status')
    parser.formatter_class = argparse.RawTextHelpFormatter
    parser.set_defaults(func=status)

    add_parser_arguments(
        parser, [(['projects'],
                  dict(metavar='<project|group>',
                       default='default',
                       nargs='*',
                       choices=CLOWDER_CONTROLLER.project_choices_with_default,
                       help=fmt.project_options_help_message(
                           'projects and groups to print status of'))),
                 (['--fetch', '-f'],
                  dict(action='store_true',
                       help='fetch projects before printing status'))])
Example #10
0
def add_config_set_parser(
        subparsers: argparse._SubParsersAction) -> None:  # noqa
    """Add clowder config set parser

    :param argparse._SubParsersAction subparsers: Subparsers action to add parser to
    """
    def config_help_set(_):
        """Clowder config set help handler"""

        config_set_parser.print_help()

    # clowder config set
    config_set_parser = subparsers.add_parser(
        'set', help='Set clowder config options')
    config_set_parser.set_defaults(func=config_help_set)
    config_set_subparsers = config_set_parser.add_subparsers()

    # clowder config set rebase
    rebase_parser = config_set_subparsers.add_parser(
        'rebase', help='Set use rebase with herd command')
    rebase_parser.set_defaults(func=config_set_rebase)

    # clowder config set jobs
    jobs_arguments = [
        (['jobs'],
         dict(
             metavar='<n>',
             nargs=1,
             default=None,
             type=int,
             help=
             'Set default number of jobs to use running commands in parallel'))
    ]
    jobs_parser = config_set_subparsers.add_parser(
        'jobs', help='Set default number of jobs for relevant commands')
    add_parser_arguments(jobs_parser, jobs_arguments)
    jobs_parser.set_defaults(func=config_set_jobs)

    # clowder config set projects
    projects_arguments = [
        (['projects'],
         dict(metavar='PROJECT',
              nargs='+',
              choices=CLOWDER_CONTROLLER.project_choices,
              help=fmt.project_options_help_message(
                  'Default projects and groups to run commands for')))
    ]
    projects_parser = config_set_subparsers.add_parser(
        'projects', help='Set default projects and groups')
    add_parser_arguments(projects_parser, projects_arguments)
    projects_parser.set_defaults(func=config_set_projects)

    # clowder config set protocol
    protocol_choices = ('https', 'ssh')
    protocol_arguments = [
        (['protocol'],
         dict(metavar='PROTOCOL',
              nargs=1,
              choices=protocol_choices,
              help=fmt.options_help_message(protocol_choices,
                                            'Default git protocol to use')))
    ]
    protocol_parser = config_set_subparsers.add_parser(
        'protocol', help='Set default git protocol')
    add_parser_arguments(protocol_parser, protocol_arguments)
    protocol_parser.set_defaults(func=config_set_protocol)