from rdopkg.action import Action, Arg


ACTIONS = [
    Action('clone',
           help="clone an RDO package distgit and setup remotes",
           required_args=[
               Arg('package', positional=True, metavar='PACKAGE',
                   help="RDO package to clone (see `rdopkg info`)"),
           ],
           optional_args=[
               Arg('use_master_distgit', shortcut='-m', action='store_true',
                   help="clone 'master-distgit'"),
               Arg('gerrit_remotes', shortcut='-g', action='store_true',
                   help="create branches "
                        "'gerrit-origin' and 'gerrit-patches'"),
               Arg('review_user', shortcut='-u', metavar='USER',
                   help="gerrit username for reviews"),
           ]),
    Action('pkgenv', help="show detected package environment",
           steps=[
               Action('get_package_env'),
               Action('show_package_env'),
           ]),
    Action('patchlog', help="show patches branch log",
           steps=[
               Action('get_package_env'),
               Action('show_patch_log'),
           ]),
    Action('get-patches',
           help="setup local patches branch and switch to it",
           optional_args=[
               Arg('patches_branch', shortcut='-p', metavar='REMOTE/BRANCH',
                   help="remote git branch containing patches"),
               Arg('local_patches_branch', shortcut='-P',
                   metavar='LOCAL_BRANCH',
                   help="local git branch containing patches"),
               Arg('gerrit_patches_chain', shortcut='-g',
                   metavar='REVIEW_NUMBER',
                   help="top gerrit review id of the patch chain"),
               Arg('force', shortcut='-f', action='store_true',
                   help="use patch even if it was not validated in CI"),
           ],
           steps=[
               Action('get_package_env'),
               Action('ensure_patches_branch'),
               Action('get_patches_branch'),
               Action('checkout_patches_branch'),
           ]),
    Action('fix', help="change .spec file without introducing new patches",
           steps=[
               Action('get_package_env'),
               Action('update_spec'),
               Action('edit_spec'),
               Action('commit_distgit_update'),
               Action('final_spec_diff'),
           ]),
    Action('patch',
           help="introduce new patches to the package",
           optional_args=[
               Arg('patches_branch', shortcut='-p', metavar='REMOTE/BRANCH',
                   help="remote git branch containing patches"),
               Arg('local_patches_branch', shortcut='-P',
                   metavar='LOCAL_BRANCH',
                   help="local git branch containing patches"),
               Arg('local_patches', shortcut='-l', action='store_true',
                   help="don't reset local patches branch, use it as is"),
               Arg('gerrit_patches_chain', shortcut='-g',
                   metavar='REVIEW_NUMBER',
                   help="top gerrit review id of the patch chain"),
               Arg('force', shortcut='-f', action='store_true',
                   help="use patch even if it was not validated in CI"),
               Arg('no_bump', shortcut='-B', action='store_true',
                   help="don't bump release and generate changelog "
                        "(update patches only)"),
               Arg('changelog', shortcut='-C',
                   choices=['detect', 'count', 'plain'],
                   help="how to generate changelog from patches"),
               Arg('commit_header_file', shortcut='-H', metavar='FILE',
                   help="start commit message with FILE contents, "
                        "- for stdin"),
               Arg('changelog_user', shortcut='-u', default=None,
                   help="User to be used in new changelog entry"),
               Arg('changelog_email', shortcut='-e', default=None,
                   help="email address to be used in new changelog entry"),
           ],
           steps=[
               Action('get_package_env'),
               Action('ensure_patches_branch'),
               Action('get_patches_branch'),
               Action('check_new_patches'),
               Action('update_patches',
                      const_args={'require_patches_change': True}),
               Action('update_spec'),
               Action('commit_distgit_update', const_args={'amend': True}),
               Action('final_spec_diff'),
           ]),
    Action('new_version', continuable=True,
           help="update package to new upstream version",
           optional_args=[
               Arg('new_version', positional=True, nargs='?',
                   help="version to update to"),
               Arg('patches_branch', shortcut='-p', metavar='REMOTE/BRANCH',
                   help="remote git branch containing patches"),
               Arg('local_patches_branch', shortcut='-P',
                   metavar='LOCAL_BRANCH',
                   help="local git branch containing patches"),
               Arg('local_patches', shortcut='-l', action='store_true',
                   help="don't reset local patches branch, use it as is"),
               Arg('bump_only', shortcut='-b', action='store_true',
                   help="only bump .spec to new version a la rpmdev-bumpspec"),
               Arg('no_diff', shortcut='-d', action='store_true',
                   help="don't show git/requirements diff"),
               Arg('new_sources', shortcut='-N', action='store_true',
                   help=("run `fedpkg new-sources`"
                         " (default: depends on branch name)")),
               Arg('no_new_sources', shortcut='-n', action='store_true',
                   help=("don't run `fedpkg new-sources`"
                         " (default: depends on branch name)")),
               Arg('unattended', shortcut='-U', action='store_true',
                   help="don't ask any questions (NOT RECOMMENDED)"),
               Arg('no_push_patches', shortcut='-t', action='store_true',
                   help="don't push patches branch"),
               Arg('bug', shortcut='-B', metavar='BUG(S)',
                   help="reference BUG(S) in changelog. (example:"
                        " --bug rhbz#1234,rhbz#5678)"),
               Arg('commit_header_file', shortcut='-H', metavar='FILE',
                   help="start commit message with FILE contents, "
                        "- for stdin"),
               Arg('changelog_user', shortcut='-u', default=None,
                   help="User to be used in new changelog entry"),
               Arg('changelog_email', shortcut='-e', default=None,
                   help="email address to be used in new changelog entry"),
           ],
           steps=[
               Action('get_package_env'),
               Action('new_version_setup'),
               Action('diff'),
               Action('prep_new_patches_branch'),
               Action('get_patches_branch'),
               Action('rebase_patches_branch'),
               Action('update_spec'),
               Action('get_source'),
               Action('new_sources'),
               Action('commit_distgit_update'),
               Action('update_patches', const_args={'amend': True}),
               Action('final_spec_diff'),
               Action('review_patches_branch')
           ]),
    Action('update_patches',
           help='[DEPRECATED] update patches from -patches branch',
           description=(
               "WARNING: This is a low-level action for backward "
               "compatibility with ancient update-patches.sh script.\n\n"
               "Please use `rdopkg patch -lB` instead.\n\n"),
           steps=[
               Action('update_patches_deprecated'),
               Action('get_package_env'),
               Action('update_patches'),
           ],
           optional_args=[
               Arg('amend', shortcut='-a', action='store_true',
                   help="amend previous commit"),
               Arg('local_patches_branch', shortcut='-P',
                   metavar='LOCAL_BRANCH',
                   help="local git branch containing patches"),
           ]),
    Action('amend',
           help="amend last commit and recreate commit message",
           optional_args=[
               Arg('commit_header_file', shortcut='-H', metavar='FILE',
                   help="start commit message with FILE contents, "
                        "- for stdin"),
           ]),
    Action('squash',
           help="squash HEAD into HEAD~ using HEAD~ commit message"),
    Action('get_source', help="fetch source archive",
           steps=[
               Action('get_source', const_args={'new_sources': True})
           ]),
    Action('tag_patches',
           help='tag the -patches branch in Git with the current NVR',
           optional_args=[
               Arg('force', shortcut='-f', action='store_true',
                   help='replace an existing tag with this name'),
               Arg('push', shortcut='-p', action='store_true',
                   help='push this new tag to the patches remote'),
           ],
           steps=[
               Action('get_package_env'),
               Action('ensure_patches_branch'),
               Action('tag_patches_branch'),
           ]),
]
