-from stgit import stack, git
-
-
-help = 'push a patch on top of the series'
-usage = """%prog [options] [<name>]
-
-Push a patch (defaulting to the first unapplied one) or range of
-patches to the stack. The 'push' operation allows patch reordering by
-commuting them with the three-way merge algorithm. If the result of
-the 'push' operation is not acceptable or if there are too many
-conflicts, the '--undo' option can be used to revert the patch and the
-tree to the state before the operation. Conflicts raised during the
-push operation have to be fixed and the 'resolved' command run.
-
-The 'push' command also notifies when the patch becomes empty after
-the merge operation (i.e. it was fully merged upstream)."""
-
-options = [make_option('-a', '--all',
- help = 'push all the unapplied patches',
- action = 'store_true'),
- make_option('-n', '--number', type = 'int',
- help = 'push the specified number of patches'),
- make_option('-t', '--to', metavar = 'PATCH1[:PATCH2]',
- help = 'push all patches to PATCH1 or between '
- 'PATCH1 and PATCH2'),
- make_option('--reverse',
- help = 'push the patches in reverse order',
- action = 'store_true'),
- make_option('--undo',
- help = 'undo the last push operation',
- action = 'store_true')]
-
+from stgit.out import *
+from stgit import argparse, stack, git
+
+help = 'Push one or more patches onto the stack'
+kind = 'stack'
+usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]']
+description = """
+Push one or more patches (defaulting to the first unapplied one) onto
+the stack. The 'push' operation allows patch reordering by commuting
+them with the three-way merge algorithm. If there are conflicts while
+pushing a patch, those conflicts are written to the work tree, and the
+command halts. Conflicts raised during the push operation have to be
+fixed and the 'resolved' command run (alternatively, you may undo the
+conflicting push with 'stg undo').
+
+The command also notifies when the patch becomes empty (fully merged
+upstream) or is modified (three-way merged) by the 'push' operation."""
+
+args = [argparse.patch_range(argparse.unapplied_patches)]
+options = [
+ opt('-a', '--all', action = 'store_true',
+ short = 'Push all the unapplied patches'),
+ opt('-n', '--number', type = 'int',
+ short = 'Push the specified number of patches'),
+ opt('--reverse', action = 'store_true',
+ short = 'Push the patches in reverse order'),
+ opt('-m', '--merged', action = 'store_true',
+ short = 'Check for patches merged upstream')]
+
+directory = DirectoryGotoToplevel(log = True)