示例#1
0
    def add_arguments(self, git, gitproject, project, parser_manager,
                      plugin_manager):
        """Add arguments for 'git project init.'"""
        # init
        init_parser = add_top_level_command(parser_manager,
                                            'init',
                                            'init',
                                            help='Initialize project')

        add_plugin_version_argument(init_parser)

        init_parser.set_defaults(func=command_init)
    def add_arguments(self, git, gitproject, project, parser_manager,
                      plugin_manager):
        """Add arguments for 'git-project artifact.'"""

        artifact_parser = add_top_level_command(parser_manager,
                                                'artifact',
                                                'artifact',
                                                help='Manipulate artifacts')

        add_plugin_version_argument(artifact_parser)

        artifact_subparser = parser_manager.add_subparser(
            artifact_parser, 'artifact-command', help='artifact commands')

        # add
        add_parser = parser_manager.add_parser(
            artifact_subparser,
            'add',
            'artifact-add',
            help='Add an artifact',
            epilog="""
The <subsection> argument is appended to the <project>.artifact section to form
the final git config section that will hold the artifact path.
""",
            formatter_class=argparse.RawDescriptionHelpFormatter)

        add_parser.add_argument(
            'subsection', help='Subsection under which to add the artifact')
        add_parser.add_argument('path',
                                help='Artifact path, may use substitutions')

        add_parser.set_defaults(func=command_artifact_add)

        # rm
        rm_parser = parser_manager.add_parser(
            artifact_subparser,
            'rm',
            'artifact-rm',
            help='Remove an artifact path',
            epilog="""
The <subsection> argument is appended to the <project>.artifact section to form
the final git config section that will hold the artifact path.
""",
            formatter_class=argparse.RawDescriptionHelpFormatter)

        rm_parser.add_argument(
            'subsection', help='Subsection under which to add the artifact')
        rm_parser.add_argument('path',
                               nargs='?',
                               help='Artifact path, may use substitutions')

        rm_parser.set_defaults(func=command_artifact_rm)
    def add_arguments(self,
                      git,
                      gitproject,
                      project,
                      parser_manager,
                      plugin_manager):
        """Add arguments for 'git project branch.'"""
        # branch
        branch_parser = add_top_level_command(parser_manager,
                                              'branch',
                                              'branch',
                                              help='Manipulate branches')

        add_plugin_version_argument(branch_parser)

        branch_subparser = parser_manager.add_subparser(branch_parser,
                                                        'branch_command',
                                                        help='branch commands')

        # branch status
        branch_status_parser = parser_manager.add_parser(branch_subparser,
                                                         'status',
                                                         'branch-status',
                                                         help='Show branch status')

        branch_status_parser.set_defaults(func=command_branch_status)

        branch_status_parser.add_argument('name_or_ref', nargs='?', help='Branch or pattern to filter branches')
        branch_status_parser.add_argument('target', nargs='?', help='Target branch to check against')
        branch_status_parser.add_argument('--all', action='store_true', help='Show all branches')
        branch_status_parser.add_argument('--all-user', action='store_true', help='Show all user\'s branches')

        # branch prune
        branch_prune_parser = parser_manager.add_parser(branch_subparser,
                                                        'prune',
                                                        'branch-prune',
                                                        help='Delete merged branches')

        branch_prune_parser.set_defaults(func=command_branch_prune)

        branch_prune_parser.add_argument('name_or_ref', nargs='?', help='Branch name or pattern to filter branches')
        branch_prune_parser.add_argument('--all-user', action='store_true', help='Prune all user\'s branches')
        branch_prune_parser.add_argument('--force', action='store_true', help='Prune even if unmerged')
        branch_prune_parser.add_argument('--no-ask', action='store_true', help='Do not ask before pruning')
    def _add_config_parser(self, cls, project, parser_manager):
        command = cls.get_managing_command()
        config_key = command + '-config' if command else 'config'
        config_parser = parser_manager.find_parser(config_key)

        if not config_parser:
            # Create a config parser under the managing command.
            command_subparser_key = command + '-command' if command else 'command'
            command_subparser = parser_manager.find_subparser(
                command_subparser_key)
            if not command_subparser:
                # This plugin doesn't have subcommands, so don't add one.
                return

            config_help = 'Configure ' + command if command else 'Configure git-project'
            config_parser = parser_manager.add_parser(command_subparser,
                                                      'config',
                                                      config_key,
                                                      help=config_help)

            config_parser.set_defaults(func=command_config)
            config_parser.set_defaults(getter=cls.get)
            config_parser.set_defaults(exister=cls.exists)
            config_parser.set_defaults(classname=cls.__name__)

            if hasattr(cls, 'subsection'):
                config_parser.set_defaults(subsection=cls.subsection())
                config_parser.add_argument('ident',
                                           help=f'{cls.__name__} to modify')

            if not command:
                # This is the top-level 'config' command.
                add_plugin_version_argument(config_parser)

            config_parser.add_argument('name', help='Property name')
            config_parser.add_argument('value',
                                       nargs='?',
                                       help='Property value to set')
            config_parser.add_argument('--add',
                                       action='store_true',
                                       help='Add a value to a property')
            config_parser.add_argument('--unset',
                                       action='store_true',
                                       help='Remove a value from a property')
示例#5
0
    def add_arguments(self, git, gitproject, project, parser_manager,
                      plugin_manager):
        """Add arguments for 'git-project clone.'"""
        # clone
        clone_parser = add_top_level_command(parser_manager,
                                             'clone',
                                             'clone',
                                             help='Clone project')

        add_plugin_version_argument(clone_parser)

        clone_parser.set_defaults(func=command_clone)

        clone_parser.add_argument('url', help='URL to clone')

        clone_parser.add_argument('path',
                                  nargs='?',
                                  help='Local repository location')

        clone_parser.add_argument('--bare',
                                  action='store_true',
                                  help='Clone a bare repository')
示例#6
0
    def add_arguments(self, git, gitproject, project, parser_manager,
                      plugin_manager):
        """Add arguments for 'git-project help'"""
        # help
        help_parser = add_top_level_command(parser_manager,
                                            'help',
                                            'help',
                                            help='Display help')

        help_parser.set_defaults(func=command_help)

        add_plugin_version_argument(help_parser)

        help_parser.add_argument('options',
                                 nargs='*',
                                 help='Specify help section')

        # add help
        add_parser = get_or_add_top_level_command(
            parser_manager,
            'add',
            'add',
            help=f'Add config sections to {project.get_section()}')

        add_subparser = parser_manager.get_or_add_subparser(
            add_parser, 'add-command', help='add sections')

        add_help_parser = parser_manager.add_parser(
            add_subparser,
            'help',
            'add-help',
            help=f'Add help to {project.get_section()}')

        add_help_parser.set_defaults(func=command_add_help)

        add_help_parser.add_argument('--manpage',
                                     action='store_true',
                                     help='Add help as manpage')

        add_help_parser.add_argument('name',
                                     help='Command name for which to add help')

        add_help_parser.add_argument('text', help='Help text')

        # rm help
        rm_parser = get_or_add_top_level_command(
            parser_manager,
            'rm',
            'rm',
            help=f'Remove config sections from {project.get_section()}')

        rm_subparser = parser_manager.get_or_add_subparser(
            rm_parser, 'rm-command', help='remove sections')

        rm_help_parser = parser_manager.add_parser(
            rm_subparser,
            'help',
            'rm-help',
            help=f'Remove help from {project.get_section()}')

        rm_help_parser.set_defaults(func=command_rm_help)

        rm_help_parser.add_argument('--manpage',
                                    action='store_true',
                                    help='Add help as manpage')

        rm_help_parser.add_argument('name',
                                    help='Command name for which to add help')
示例#7
0
    def _add_alias_arguments(self, git, gitproject, project, parser_manager,
                             Class):
        alias = Class.get_managing_command()

        # add run
        add_parser = get_or_add_top_level_command(
            parser_manager,
            'add',
            'add',
            help=f'Add config sections to {project.get_section()}')

        add_subparser = parser_manager.get_or_add_subparser(
            add_parser, 'add-command', help='add sections')

        add_run_parser = parser_manager.add_parser(
            add_subparser,
            alias,
            'add-' + alias,
            help=f'Add a {alias} to {project.get_section()}')

        def command_add_run(git, gitproject, project, clargs):
            f"""Implement git-project add {alias}"""
            run = Class.get(git, project, clargs.name, command=clargs.command)
            project.add_item(alias, clargs.name)
            return run

        add_run_parser.set_defaults(func=command_add_run)

        add_run_parser.add_argument('name', help='Name for the run')

        add_run_parser.add_argument('command', help='Command to run')

        runs = []
        if hasattr(project, alias):
            runs = [run for run in project.iter_multival(alias)]

        # rm run
        rm_parser = get_or_add_top_level_command(
            parser_manager,
            'rm',
            'rm',
            help=f'Remove config sections from {project.get_section()}')

        rm_subparser = parser_manager.get_or_add_subparser(rm_parser,
                                                           'rm-command',
                                                           help='rm sections')

        rm_run_parser = parser_manager.add_parser(
            rm_subparser,
            alias,
            'rm-' + alias,
            help=f'Remove a {alias} from {project.get_section()}')

        def command_rm_run(git, gitproject, project, clargs):
            f"""Implement git-project rm {alias}"""
            run = Run.get(git,
                          project,
                          alias,
                          clargs.name,
                          command=clargs.command)
            run.rm()
            print(f'Removing project {alias} {clargs.name}')
            project.rm_item(alias, clargs.name)

        rm_run_parser.set_defaults(func=command_rm_run)

        if runs:
            rm_run_parser.add_argument('name',
                                       choices=runs,
                                       help='Command name')

        # run
        command_subparser = parser_manager.find_subparser('command')

        run_parser = parser_manager.add_parser(
            command_subparser,
            alias,
            alias,
            help=f'Invoke {alias}',
            epilog=self._gen_runs_epilog(git, project, alias, runs),
            formatter_class=argparse.RawDescriptionHelpFormatter)

        def command_run(git, gitproject, project, clargs):
            """Implement git-project run"""
            if clargs.make_alias:
                run_config = RunConfig.get(git, project)
                run_config.add_item('alias', clargs.name)
            else:
                if not clargs.name in runs:
                    raise GitProjectException(
                        f'Unknown {alias} "{clargs.name}," choose one of: {{ {runs} }}'
                    )
                run = Class.get(git, project, clargs.name)

                translation_table = dict.fromkeys(map(ord, '{}'), None)

                option_names = ' '.join(clargs.options)
                option_names = option_names.translate(translation_table)
                option_key = '-'.join(clargs.options)
                option_key = option_key.translate(translation_table)

                formats = {
                    'options': ' '.join(clargs.options),
                    'option_names': option_names,
                    'option_key': option_key,
                    'option_keysep': '-' if len(clargs.options) > 0 else ''
                }

                run.run(git, project, formats)

        run_parser.set_defaults(func=command_run)

        add_plugin_version_argument(run_parser)

        run_parser.add_argument('--make-alias',
                                action='store_true',
                                help=f'Alias "{alias}" to another command')

        run_parser.add_argument('name', help='Command name or alias')

        run_parser.add_argument('options',
                                nargs='*',
                                help='Additions options to pass to command')
    def add_arguments(self,
                      git,
                      gitproject,
                      project,
                      parser_manager,
                      plugin_manage):
        """Add arguments for 'git-project worktree.'"""

        # worktree
        worktree_parser = add_top_level_command(parser_manager,
                                                Worktree.get_managing_command(),
                                                Worktree.get_managing_command(),
                                                help='Manage worktrees',
                                                formatter_class=argparse.RawDescriptionHelpFormatter)

        add_plugin_version_argument(worktree_parser)

        worktree_subparser = parser_manager.add_subparser(worktree_parser,
                                                          'worktree-command',
                                                          help='worktree commands')

        # worktree add
        worktree_add_parser = parser_manager.add_parser(worktree_subparser,
                                                        'add',
                                                        'worktree-add',
                                                        help='Create a worktree',
                                                        epilog='One of path or committish is required.  If only one is specifiedd, the other will be inferred from the specified value.')

        worktree_add_parser.set_defaults(func=command_worktree_add)

        worktree_add_parser.add_argument('path',
                                         nargs='?',
                                         help='Path for worktree checkout')
        worktree_add_parser.add_argument('committish',
                                         nargs='?',
                                         help='Branch point for worktree')
        worktree_add_parser.add_argument('-b',
                                         '--branch',
                                         metavar='BRANCH',
                                         help='Create BRANCH for the worktree')

        # worktree rm
        worktree_rm_parser = parser_manager.add_parser(worktree_subparser,
                                                       'rm',
                                                       'worktree-rm',
                                                       help='Remove a worktree')

        worktree_rm_parser.set_defaults(func=command_worktree_rm)

        worktree_rm_parser.add_argument('name',
                                        help='Worktree to remove')
        worktree_rm_parser.add_argument('-f', '--force', action='store_true',
                                        help='Remove even if branch is not merged')

        # add a clone option to create a worktree layout.
        clone_parser = parser_manager.find_parser('clone')
        if clone_parser:
            clone_parser.add_argument('--worktree', action='store_true',
                                      help='Create a layout convenient for worktree use')

        # add an init option to create a worktree layout.
        init_parser = parser_manager.find_parser('init')
        if init_parser:
            init_parser.add_argument('--worktree', action='store_true',
                                     help='Create a layout convenient for worktree use')