Auto-generate man pages for all StGit commands
authorKarl Hasselström <kha@treskal.com>
Sun, 21 Sep 2008 12:17:39 +0000 (14:17 +0200)
committerKarl Hasselström <kha@treskal.com>
Sun, 21 Sep 2008 12:17:51 +0000 (14:17 +0200)
Auto-generate man pages based on the docs that are in each
stgit/commands/<cmd>.py file. That doc format is extended in order to
support both brief command help output and manpage text.

The existing interactive help is made briefer (just the usage, the
one-line explanation, and the option listing).

The text in the man pages needs some love, both content-wise and
asciidoc-markup-wise. This is left for future patches to resolve. (It
should be rather simple to improve the man pages one by one now that
the infrastructure is in place.)

Signed-off-by: Karl Hasselström <kha@treskal.com>
50 files changed:
Documentation/.gitignore
Documentation/COMMAND-TEMPLATE.txt [deleted file]
Documentation/Makefile
Documentation/asciidoc.conf
Documentation/stg-branch.txt [deleted file]
Documentation/stg-clone.txt [deleted file]
Documentation/stg-init.txt [deleted file]
Documentation/stg-new.txt [deleted file]
Documentation/stg-sink.txt [deleted file]
stg-build [new file with mode: 0755]
stgit/argparse.py
stgit/commands/branch.py
stgit/commands/clean.py
stgit/commands/clone.py
stgit/commands/coalesce.py
stgit/commands/commit.py
stgit/commands/delete.py
stgit/commands/diff.py
stgit/commands/edit.py
stgit/commands/export.py
stgit/commands/files.py
stgit/commands/float.py
stgit/commands/fold.py
stgit/commands/goto.py
stgit/commands/hide.py
stgit/commands/id.py
stgit/commands/imprt.py
stgit/commands/init.py
stgit/commands/log.py
stgit/commands/mail.py
stgit/commands/new.py
stgit/commands/patches.py
stgit/commands/pick.py
stgit/commands/pop.py
stgit/commands/pull.py
stgit/commands/push.py
stgit/commands/rebase.py
stgit/commands/refresh.py
stgit/commands/rename.py
stgit/commands/repair.py
stgit/commands/resolved.py
stgit/commands/series.py
stgit/commands/show.py
stgit/commands/sink.py
stgit/commands/status.py
stgit/commands/sync.py
stgit/commands/top.py
stgit/commands/uncommit.py
stgit/commands/unhide.py
stgit/main.py

index 6da6dc4..32dd09d 100644 (file)
@@ -1,5 +1,5 @@
 *.html
 *.pdf
-*.7
-*.1
+*.[1-9]
+stg-*.txt
 doc.dep
diff --git a/Documentation/COMMAND-TEMPLATE.txt b/Documentation/COMMAND-TEMPLATE.txt
deleted file mode 100644 (file)
index 7bc029a..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-stg-NAME(1)
-==========
-XXX <xxx@xxx.xx>
-v0.12.1, Xxxx 2007
-
-NAME
-----
-stg-NAME - stgdesc:NAME[]
-
-SYNOPSIS
---------
-[verse]
-'stg' NAME [OPTIONS] XXX
-
-DESCRIPTION
------------
-
-XXX
-
-OPTIONS
--------
-
-XXX
-
-FILES
------
-
-       <templates>/XXX
-
-ENVIRONMENT VARIABLES
----------------------
-
-       XXX
-
-GIT CONFIGURATION VARIABLES
----------------------------
-
-       stgit.XXX
-
-StGIT
------
-Part of the StGIT suite - see gitlink:stg[1].
index c53c4af..1c14fe3 100644 (file)
@@ -1,4 +1,7 @@
-MAN1_TXT=$(wildcard stg*.txt)
+COMMANDS = $(shell ../stg-build --commands)
+COMMANDS_TXT = $(patsubst %,stg-%.txt,$(COMMANDS))
+
+MAN1_TXT=$(wildcard stg*.txt) $(COMMANDS_TXT)
 
 DOC_HTML=$(patsubst %.txt,%.html,$(MAN1_TXT))
 
@@ -57,7 +60,10 @@ doc.dep : $(wildcard *.txt) build-docdep.perl
 -include doc.dep
 
 clean:
-       rm -f *.xml *.html *.pdf *.1 doc.dep
+       rm -f *.xml *.html *.pdf *.1 doc.dep $(COMMANDS_TXT)
+
+$(COMMANDS_TXT): $(shell find .. -name '*.py')
+       ../stg-build --asciidoc $(basename $(subst stg-,,$@)) > $@
 
 %.html : %.txt
        $(ASCIIDOC) -b xhtml11 -d manpage -f asciidoc.conf $(ASCIIDOC_EXTRA) $<
index 3df8814..4c83756 100644 (file)
@@ -49,11 +49,3 @@ ifdef::backend-xhtml11[]
 [stglink-inlinemacro]
 <a href="stg-{target}.html">stg {target}(1)</a>
 endif::backend-xhtml11[]
-
-# stgdesc
-[stgdesc-inlinemacro]
-{sys:../stg help|grep "  {target}" | tr -s ' '| cut -d' ' -f3-}
-
-[stgdesc-blockmacro]
-stglink:{target}[]::
-       stgdesc:{target}[]
diff --git a/Documentation/stg-branch.txt b/Documentation/stg-branch.txt
deleted file mode 100644 (file)
index 25ca951..0000000
+++ /dev/null
@@ -1,114 +0,0 @@
-stg-branch(1)
-=============
-Yann Dirson <ydirson@altern.org>
-v0.12.1, April 2007
-
-NAME
-----
-stg-branch - stgdesc:branch[]
-
-SYNOPSIS
---------
-[verse]
-'stg' branch
-'stg' branch <branch>
-'stg' branch --list
-'stg' branch --create <newstack> [<commit-id>]
-'stg' branch --clone [<newstack>]
-'stg' branch --rename <oldname> <newname>
-'stg' branch --description=<description> [<branch>]
-'stg' branch --protect [<branch>]
-'stg' branch --unprotect [<branch>]
-'stg' branch --delete [--force] <branch>
-
-DESCRIPTION
------------
-
-Assorted operations on branches.
-
-no command, no argument::
-       Display the name of the current branch.
-
-no command, one argument::
-       Switch to the named <branch>.
-
-'stg' branch [-l | --list]::
-       Display the list of branches in the current repository,
-       suffixed by the branch description if any, and optionally
-       prefixed by the letter flags 's' if the branch is an StGIT
-       stack, and 'p' if the StGIT stack is protected.  The current
-       branch is shown with a leading ">" character.
-
-'stg' branch [-c | --create]::
-       Create a new StGIT stack based at the specified commit, or at
-       the current HEAD if not specified.  The repository HEAD is
-       switched to the new stack.
-+
-StGIT will try to detect the branch off which the new stack is forked,
-as well as the remote repository from which that parent branch is
-taken (if any), so running stglink:pull[] will effectively pull new
-commits from the correct branch.  It will warn if it cannot guess the
-parent branch (eg. if you do not specify a branch name as
-<commit-id>).
-
-'stg' branch --clone::
-       Clone the current stack, under the name <newstack> if
-       specified, or using the current stack's name suffixed by a
-       timestamp.
-+
-The description of the new stack is set to tell it is a clone of the
-current stack.  The parent information of the new stack is copied from
-the current stack.
-+
-Cloning a GIT branch that is not an StGIT stack is similar to creating
-a new stack off the current branch.
-
-'stg' branch [-r | --rename]::
-       Rename the stack named <oldname> to <newname>.
-
-'stg' branch [-d <desc> | --description=<desc>]::
-       Set the branch description.
-
-'stg' branch [-p | --protect]::
-       Protect the named stack or the current one, preventing
-       further StGIT operations from modifying this stack.
-
-'stg' branch [-u | --unprotect]::
-       Remove a "protected" flag previously set with '--protect'.
-
-'stg' branch --delete::
-       Delete the named <branch>.  If there are any patches left in
-       the series, StGIT will refuse to delete it, unless '--force'
-       is specified.
-+
-A protected branch cannot be deleted, it must be unprotected first
-(see above).
-+
-When the current branch is deleted, the repository HEAD is switched to
-the "master" branch if it exists.
-+
-Branch "master" is treated specially (see bug #8732), in that only the
-StGIT metadata are removed, the GIT branch itself is not destroyed.
-
-OPTIONS
--------
-
---force::
-       Force a delete when the series is not empty.
-
-FILES
------
-
-       $GIT_DIR/patches/<branch>/description
-       $GIT_DIR/patches/<branch>/protected
-
-GIT CONFIGURATION VARIABLES
----------------------------
-
-       branch.<branchname>.remote
-       branch.<branchname>.merge
-       branch.<branchname>.stgit.parentbranch
-
-StGIT
------
-Part of the StGIT suite - see gitlink:stg[1].
diff --git a/Documentation/stg-clone.txt b/Documentation/stg-clone.txt
deleted file mode 100644 (file)
index 19a8b79..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-stg-clone(1)
-==========
-Yann Dirson <ydirson@altern.org>
-v0.12.1, April 2007
-
-NAME
-----
-stg-clone - stgdesc:clone[]
-
-SYNOPSIS
---------
-[verse]
-'stg' clone <repository> <dir>
-
-DESCRIPTION
------------
-
-Clone a GIT <repository> into the local <dir> (using
-gitlink:git-clone[1]) and initialise the resulting "master" branch as
-a patch stack.
-
-This operation is for example suitable to start working using the
-"tracking branch" workflow (see gitlink:stg[1]).  Other means to setup
-an StGIT stack are stglink:init[] and the '--create' and '--clone'
-commands of stglink:branch[].
-
-The target directory named by <dir> will be created by this command,
-and must not exist beforehand.
-
-StGIT
------
-Part of the StGIT suite - see gitlink:stg[1].
diff --git a/Documentation/stg-init.txt b/Documentation/stg-init.txt
deleted file mode 100644 (file)
index 03877e0..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-stg-init(1)
-==========
-Yann Dirson <ydirson@altern.org>
-v0.12.1, April 2007
-
-NAME
-----
-stg-init - stgdesc:init[]
-
-SYNOPSIS
---------
-[verse]
-'stg' init
-
-DESCRIPTION
------------
-
-Initialise the current GIT branch to be used as an StGIT stack.  You
-must already be in a GIT repository and .git/HEAD must point to a
-valid file in refs/heads/.
-
-This operation is for example suitable to start working using the
-"development branch" workflow (see gitlink:stg[1]).  Other means to setup
-an StGIT stack are stglink:clone[] and the '--create' and '--clone'
-commands of stglink:branch[].
-
-StGIT
------
-Part of the StGIT suite - see gitlink:stg[1].
diff --git a/Documentation/stg-new.txt b/Documentation/stg-new.txt
deleted file mode 100644 (file)
index fbf2f67..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-stg-new(1)
-==========
-Yann Dirson <ydirson@altern.org>
-v0.12.1, February 2007
-
-NAME
-----
-stg-new - stgdesc:new[]
-
-SYNOPSIS
---------
-[verse]
-'stg' new [OPTIONS] [name]
-
-DESCRIPTION
------------
-
-Create a new, empty patch with the given <name> on the current stack.
-The new patch is created on top of the currently applied patches, and
-is made the new top of the stack.  The local changes in the working
-tree are not included in the patch. A stglink:refresh[] command is
-needed for this.
-
-The given <name> must be unique in the stack, and may only contain
-alphanumeric characters, dashes and underscores. If no name is given,
-one is generated from the first line of the commit message.
-
-An editor will be launched to edit the commit message to be used for
-the patch, unless the '--message' flag already specified one.  The
-'patchdescr.tmpl' template file is used if available to pre-fill the
-editor.  The editor to use is taken from the first of the following
-sources of information, and defaults to 'vi':
-
-. the 'stgit.editor' GIT configuration variable
-. the 'EDITOR' environment variable
-
-The message and other GIT commit attributes can be modified later
-using stglink:refresh[].
-
-AUTHOR AND COMMITTER INFORMATION
---------------------------------
-
-The author name (resp. email) to record in the StGIT patch is taken
-from the first of the following sources for the information:
-
-. the '--authname' (resp. '--authemail') or '--author' flag on command-line
-. the 'GIT_AUTHOR_NAME' (resp. 'GIT_AUTHOR_EMAIL') environment variable
-. the 'user.name' (resp. 'user.email') GIT configuration variable
-
-Similarly, the committer name (resp. email) is taken from the first of
-the following sources:
-
-. the '--commname' (resp. '--commemail') flag on command-line
-. the 'GIT_COMMITTER_NAME' (resp. 'GIT_COMMITTER_EMAIL') environment variable
-. the 'user.name' (resp. 'user.email') GIT configuration variable
-
-The GIT commit generated by stglink:refresh[] will use these
-informations when available.  If one of them is not available, GIT
-will pick the value from your machine's configuration at that time, as
-described in gitlink:git-commit-tree[1].
-
-OPTIONS
--------
-
---message=<message>::
--m <message>::
-       Use <message> as the patch description.
-
---showpatch::
--s::
-       Show the patch content in the editor buffer.  This flag does
-       nothing if '-m' is also specified.
-
---author="Name <email@company>"::
--a "Name <email@company>"::
-       Use "Name <email@company>" as the author details.  This form
-       sets both 'authname' and 'authemail'.
-
---authname=<name>::
-       Use <name> as the author name
---authemail=<email>::
-       Use <email> as the author e-mail
---authdate=<date>::
-       Use <date> as the author date
-
---commname=<name>::
-       Use <name> as the committer name
---commemail=<email>::
-       Use <email> as the committer e-mail
-
-FILES
------
-
-       <templates>/patchdescr.tmpl
-
-ENVIRONMENT VARIABLES
----------------------
-
-       GIT_AUTHOR_NAME
-       GIT_AUTHOR_EMAIL
-       GIT_AUTHOR_DATE
-       GIT_COMMITTER_NAME
-       GIT_COMMITTER_EMAIL
-       EDITOR
-
-GIT CONFIGURATION VARIABLES
----------------------------
-
-       user.name
-       user.email
-       stgit.editor
-
-StGIT
------
-Part of the StGIT suite - see gitlink:stg[1].
diff --git a/Documentation/stg-sink.txt b/Documentation/stg-sink.txt
deleted file mode 100644 (file)
index 0f569be..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-stg-sink(1)
-===========
-Yann Dirson <ydirson@altern.org>
-v0.13, April 2007
-
-NAME
-----
-stg-sink - stgdesc:sink[]
-
-SYNOPSIS
---------
-[verse]
-'stg' sink [--to=<target>] [--nopush] [<patches>]
-
-DESCRIPTION
------------
-
-This is the opposite operation of stglink:float[]: move the specified
-patches down the stack.  It is for example useful to group stable
-patches near the bottom of the stack, where they are less likely to be
-impacted by the push of another patch, and from where they can be more
-easily committed or pushed.
-
-If no patch is specified on command-line, the current patch gets sunk.
-By default patches are sunk to the bottom of the stack, but the
-'--to' option allows to place them under any applied patch.
-
-Sinking internally involves popping all patches (or all patches
-including <target patch>), then pushing the patches to sink, and then
-(unless '--nopush' is also given) pushing back into place the
-formerly-applied patches.
-
-
-OPTIONS
--------
-
---to=<TARGET>::
--t <TARGET>::
-       Specify a target patch to place the patches below, instead of
-       sinking them to the bottom of the stack.
-
---nopush::
--n::
-       Do not push back on the stack the formerly-applied patches.
-       Only the patches to sink are pushed.
-
-StGIT
------
-Part of the StGIT suite - see gitlink:stg[1].
diff --git a/stg-build b/stg-build
new file mode 100755 (executable)
index 0000000..8c39a6f
--- /dev/null
+++ b/stg-build
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# -*- python -*-
+import optparse, sys
+import stgit.main
+from stgit import argparse
+
+def main():
+    op = optparse.OptionParser()
+    op.add_option('--asciidoc', metavar = 'CMD',
+                  help = 'Print asciidoc documentation for a command')
+    op.add_option('--commands', action = 'store_true',
+                  help = 'Print list of all stg subcommands')
+    options, args = op.parse_args()
+    if args:
+        op.error('Wrong number of arguments')
+    if options.asciidoc:
+        argparse.write_asciidoc(stgit.main.commands[options.asciidoc],
+                                sys.stdout)
+    elif options.commands:
+        for cmd in sorted(stgit.main.commands.iterkeys()):
+            print cmd
+    else:
+        op.error('No command')
+
+if __name__ == '__main__':
+    main()
index 4999272..4cd9527 100644 (file)
-"""Utility functions for command-line option parsing."""
+"""This module provides a layer on top of the standard library's
+C{optparse} module, so that we can easily generate both interactive
+help and asciidoc documentation (such as man pages)."""
 
-import optparse, sys
+import optparse, sys, textwrap
 from stgit import utils
 from stgit.config import config
 
+def _splitlist(lst, split_on):
+    """Iterate over the sublists of lst that are separated by an element e
+    such that split_on(e) is true."""
+    current = []
+    for e in lst:
+        if split_on(e):
+            yield current
+            current = []
+        else:
+            current.append(e)
+    yield current
+
+def _paragraphs(s):
+    """Split a string s into a list of paragraphs, each of which is a list
+    of lines."""
+    lines = [line.rstrip() for line in textwrap.dedent(s).strip().splitlines()]
+    return [p for p in _splitlist(lines, lambda line: not line.strip()) if p]
+
+class opt(object):
+    """Represents a command-line flag."""
+    def __init__(self, *args, **kwargs):
+        self.args = args
+        self.kwargs = kwargs
+    def get_option(self):
+        kwargs = dict(self.kwargs)
+        kwargs['help'] = kwargs['short']
+        del kwargs['short']
+        if 'long' in kwargs:
+            del kwargs['long']
+        return optparse.make_option(*self.args, **kwargs)
+    def metavar(self):
+        o = self.get_option()
+        if not o.nargs:
+            return None
+        if o.metavar:
+            return o.metavar
+        for flag in self.args:
+            if flag.startswith('--'):
+                return utils.strip_prefix('--', flag).upper()
+        raise Exception('Cannot determine metavar')
+    def write_asciidoc(self, f):
+        for flag in self.args:
+            f.write(flag)
+            m = self.metavar()
+            if m:
+                f.write(' ' + m)
+            f.write('::\n')
+        paras = _paragraphs(self.kwargs.get('long', self.kwargs['short'] + '.'))
+        for line in paras[0]:
+            f.write(' '*8 + line + '\n')
+        for para in paras[1:]:
+            f.write('+\n')
+            for line in para:
+                f.write(line + '\n')
+
+def _cmd_name(cmd_mod):
+    return getattr(cmd_mod, 'name', cmd_mod.__name__.split('.')[-1])
+
+def make_option_parser(cmd):
+    pad = ' '*len('Usage: ')
+    return optparse.OptionParser(
+        prog = 'stg %s' % _cmd_name(cmd),
+        usage = (('\n' + pad).join('%%prog %s' % u for u in cmd.usage) +
+                 '\n\n' + cmd.help),
+        option_list = [o.get_option() for o in cmd.options])
+
+def _write_underlined(s, u, f):
+    f.write(s + '\n')
+    f.write(u*len(s) + '\n')
+
+def write_asciidoc(cmd, f):
+    _write_underlined('stg-%s(1)' % _cmd_name(cmd), '=', f)
+    f.write('\n')
+    _write_underlined('NAME', '-', f)
+    f.write('stg-%s - %s\n\n' % (_cmd_name(cmd), cmd.help))
+    _write_underlined('SYNOPSIS', '-', f)
+    f.write('[verse]\n')
+    for u in cmd.usage:
+        f.write("'stg' %s %s\n" % (_cmd_name(cmd), u))
+    f.write('\n')
+    _write_underlined('DESCRIPTION', '-', f)
+    f.write('\n%s\n\n' % cmd.description.strip('\n'))
+    if cmd.options:
+        _write_underlined('OPTIONS', '-', f)
+        for o in cmd.options:
+            o.write_asciidoc(f)
+            f.write('\n')
+    _write_underlined('StGit', '-', f)
+    f.write('Part of the StGit suite - see stglink:stg[1]\n')
+
 def sign_options():
     def callback(option, opt_str, value, parser, sign_str):
         if parser.values.sign_str not in [None, sign_str]:
             raise optparse.OptionValueError(
                 '--ack and --sign were both specified')
         parser.values.sign_str = sign_str
-    return [optparse.make_option('--sign', action = 'callback',
-                                 callback = callback, dest = 'sign_str',
-                                 callback_args = ('Signed-off-by',),
-                                 help = 'add Signed-off-by line'),
-            optparse.make_option('--ack', action = 'callback',
-                                 callback = callback, dest = 'sign_str',
-                                 callback_args = ('Acked-by',),
-                                 help = 'add Acked-by line')]
+    return [
+        opt('--sign', action = 'callback', dest = 'sign_str',
+            callback = callback, callback_args = ('Signed-off-by',),
+            short = 'Add "Signed-off-by:" line', long = """
+            Add a "Signed-off-by:" to the end of the patch."""),
+        opt('--ack', action = 'callback', dest = 'sign_str',
+            callback = callback, callback_args = ('Acked-by',),
+            short = 'Add "Acked-by:" line', long = """
+            Add an "Acked-by:" line to the end of the patch.""")]
 
 def message_options():
     def no_dup(parser):
@@ -53,16 +146,26 @@ def message_options():
                 f.close()
         parser.values.save_template = w
         no_combine(parser)
-    m = optparse.make_option
-    return [m('-m', '--message', action = 'callback', callback = msg_callback,
-              dest = 'message', type = 'string',
-              help = 'use MESSAGE instead of invoking the editor'),
-            m('-f', '--file', action = 'callback', callback = file_callback,
-              dest = 'message', type = 'string', metavar = 'FILE',
-              help = 'use FILE instead of invoking the editor'),
-            m('--save-template', action = 'callback', callback = templ_callback,
-              metavar = 'FILE', dest = 'save_template', type = 'string',
-              help = 'save the message template to FILE and exit')]
+    return [
+        opt('-m', '--message', action = 'callback',
+            callback = msg_callback, dest = 'message', type = 'string',
+            short = 'Use MESSAGE instead of invoking the editor'),
+        opt('-f', '--file', action = 'callback', callback = file_callback,
+            dest = 'message', type = 'string',
+            short = 'Use FILE instead of invoking the editor', long = """
+            Use the contents of FILE instead of invoking the editor.
+            (If FILE is "-", write to stdout.)"""),
+        opt('--save-template', action = 'callback', dest = 'save_template',
+            callback = templ_callback, metavar = 'FILE', type = 'string',
+            short = 'Save the message template to FILE and exit', long = """
+            Instead of running the command, just write the message
+            template to FILE, and exit. (If FILE is "-", write to
+            stdout.)
+
+            When driving StGit from another program, it is often
+            useful to first call a command with '--save-template',
+            then let the user edit the message, and then call the same
+            command with '--file'.""")]
 
 def diff_opts_option():
     def diff_opts_callback(option, opt_str, value, parser):
@@ -70,14 +173,14 @@ def diff_opts_option():
             parser.values.diff_flags.extend(value.split())
         else:
             parser.values.diff_flags = []
-    return [optparse.make_option(
-        '-O', '--diff-opts', dest = 'diff_flags',
-        default = (config.get('stgit.diff-opts') or '').split(),
-        action = 'callback', callback = diff_opts_callback,
-        type = 'string', metavar = 'OPTIONS',
-        help = 'extra options to pass to "git diff"')]
+    return [
+        opt('-O', '--diff-opts', dest = 'diff_flags',
+            default = (config.get('stgit.diff-opts') or '').split(),
+            action = 'callback', callback = diff_opts_callback,
+            type = 'string', metavar = 'OPTIONS',
+            short = 'Extra options to pass to "git diff"')]
 
-def person_opts(person, short):
+def _person_opts(person, short):
     """Sets options.<person> to a function that modifies a Person
     according to the commandline options."""
     def short_callback(option, opt_str, value, parser, field):
@@ -92,15 +195,14 @@ def person_opts(person, short):
         name, email = ne
         short_callback(option, opt_str, name, parser, 'name')
         short_callback(option, opt_str, email, parser, 'email')
-    return ([optparse.make_option(
-                '--%s' % person, metavar = '"NAME <EMAIL>"', type = 'string',
-                action = 'callback', callback = full_callback, dest = person,
-                default = lambda p: p, help = 'set the %s details' % person)]
-            + [optparse.make_option(
-                '--%s%s' % (short, f), metavar = f.upper(), type = 'string',
-                action = 'callback', callback = short_callback, dest = person,
-                callback_args = (f,), help = 'set the %s %s' % (person, f))
-               for f in ['name', 'email', 'date']])
+    return (
+        [opt('--%s' % person, metavar = '"NAME <EMAIL>"', type = 'string',
+             action = 'callback', callback = full_callback, dest = person,
+             default = lambda p: p, short = 'Set the %s details' % person)] +
+        [opt('--%s%s' % (short, f), metavar = f.upper(), type = 'string',
+             action = 'callback', callback = short_callback, dest = person,
+             callback_args = (f,), short = 'Set the %s %s' % (person, f))
+         for f in ['name', 'email', 'date']])
 
 def author_committer_options():
-    return person_opts('author', 'auth') + person_opts('committer', 'comm')
+    return _person_opts('author', 'auth') + _person_opts('committer', 'comm')
index 50684bb..33a8afe 100644 (file)
@@ -1,6 +1,3 @@
-"""Branch command
-"""
-
 __copyright__ = """
 Copyright (C) 2005, Chuck Lever <cel@netapp.com>
 
@@ -19,55 +16,92 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os, time, re
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git, basedir
 
-
-help = 'manage patch stacks'
-usage = """%prog [options] branch-name [commit-id]
-
+help = 'Branch operations: switch, list, create, rename, delete, ...'
+usage = ['',
+         '<branch>',
+         '--list',
+         '--create <new-branch> [<committish>]',
+         '--clone [<new-branch>]',
+         '--rename <old-name> <new-name>',
+         '--protect [<branch>]',
+         '--unprotect [<branch>]',
+         '--delete [--force] <branch>',
+         '--description=<description> [<branch>]']
+description = """
 Create, clone, switch between, rename, or delete development branches
-within a git repository.  By default, a single branch called 'master'
-is always created in a new repository.  This subcommand allows you to
-manage several patch series in the same repository via GIT branches.
-
-When displaying the branches, the names can be prefixed with
-'s' (StGIT managed) or 'p' (protected).
-
-If not given any options, switch to the named branch."""
+within a git repository.
+
+'stg branch'::
+        Display the name of the current branch.
+
+'stg branch' <branch>::
+        Switch to the given branch."""
+
+options = [
+    opt('-l', '--list', action = 'store_true',
+        short = 'List the branches contained in this repository', long = """
+        List each branch in the current repository, followed by its
+        branch description (if any). The current branch is prefixed
+        with '>'. Branches that have been initialized for StGit (with
+        stglink:init[]) are prefixed with 's'. Protected branches are
+        prefixed with 'p'."""),
+    opt('-c', '--create', action = 'store_true',
+        short = 'Create (and switch to) a new branch', long = """
+        Create (and switch to) a new branch. The new branch is already
+        initialized as an StGit patch stack, so you do not have to run
+        stglink:init[] manually. If you give a committish argument,
+        the new branch is based there; otherwise, it is based at the
+        current HEAD.
+
+        StGit will try to detect the branch off of which the new
+        branch is forked, as well as the remote repository from which
+        that parent branch is taken (if any), so that running
+        stglink:pull[] will automatically pull new commits from the
+        correct branch. It will warn if it cannot guess the parent
+        branch (e.g. if you do not specify a branch name as
+        committish)."""),
+    opt('--clone', action = 'store_true',
+        short = 'Clone the contents of the current branch', long = """
+        Clone the current branch, under the name <new-branch> if
+        specified, or using the current branch's name plus a
+        timestamp.
+
+        The description of the new branch is set to tell it is a clone
+        of the current branch. The parent information of the new
+        branch is copied from the current branch."""),
+    opt('-r', '--rename', action = 'store_true',
+        short = 'Rename an existing branch'),
+    opt('-p', '--protect', action = 'store_true',
+        short = 'Prevent StGit from modifying a branch', long = """
+        Prevent StGit from modifying a branch -- either the current
+        one, or one named on the command line."""),
+    opt('-u', '--unprotect', action = 'store_true',
+        short = 'Allow StGit to modify a branch', long = """
+        Allow StGit to modify a branch -- either the current one, or
+        one named on the command line. This undoes the effect of an
+        earlier 'stg branch --protect' command."""),
+    opt('--delete', action = 'store_true',
+        short = 'Delete a branch', long = """
+        Delete the named branch. If there are any patches left in the
+        branch, StGit will refuse to delete it unless you give the
+        '--force' flag.
+
+        A protected branch cannot be deleted; it must be unprotected
+        first (see '--unprotect' above).
+
+        If you delete the current branch, you are switched to the
+        "master" branch, if it exists."""),
+    opt('-d', '--description', short = 'Set the branch description'),
+    opt('--force', action = 'store_true',
+        short = 'Force a delete when the series is not empty')]
 
 directory = DirectoryGotoToplevel()
-options = [make_option('-c', '--create',
-                       help = 'create a new development branch',
-                       action = 'store_true'),
-           make_option('--clone',
-                       help = 'clone the contents of the current branch',
-                       action = 'store_true'),
-           make_option('--delete',
-                       help = 'delete an existing development branch',
-                       action = 'store_true'),
-           make_option('-d', '--description',
-                       help = 'set the branch description'),
-           make_option('--force',
-                       help = 'force a delete when the series is not empty',
-                       action = 'store_true'),
-           make_option('-l', '--list',
-                       help = 'list branches contained in this repository',
-                       action = 'store_true'),
-           make_option('-p', '--protect',
-                       help = 'prevent StGIT from modifying this branch',
-                       action = 'store_true'),
-           make_option('-r', '--rename',
-                       help = 'rename an existing development branch',
-                       action = 'store_true'),
-           make_option('-u', '--unprotect',
-                       help = 'allow StGIT to modify this branch',
-                       action = 'store_true')]
-
 
 def __is_current_branch(branch_name):
     return crt_series.get_name() == branch_name
index a5effb6..5334704 100644 (file)
@@ -15,26 +15,25 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
+from stgit.argparse import opt
 from stgit.out import *
 from stgit.commands import common
 from stgit.lib import transaction
 
-help = 'delete the empty patches in the series'
-usage = """%prog [options]
-
+help = 'Delete the empty patches in the series'
+usage = ['']
+description = """
 Delete the empty patches in the whole series or only those applied or
 unapplied. A patch is considered empty if the two commit objects
 representing its boundaries refer to the same tree object."""
 
-directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-a', '--applied',
-                       help = 'delete the empty applied patches',
-                       action = 'store_true'),
-           make_option('-u', '--unapplied',
-                       help = 'delete the empty unapplied patches',
-                       action = 'store_true')]
+options = [
+    opt('-a', '--applied', action = 'store_true',
+        short = 'Delete the empty applied patches'),
+    opt('-u', '--unapplied', action = 'store_true',
+        short = 'Delete the empty unapplied patches')]
 
+directory = common.DirectoryHasRepositoryLib()
 
 def _clean(stack, clean_applied, clean_unapplied):
     trans = transaction.StackTransaction(stack, 'clean', allow_conflicts = True)
index c3b0bbe..d2c68bb 100644 (file)
@@ -16,22 +16,27 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit import stack, git
 
+help = 'Make a local clone of a remote repository'
+usage = ['<repository> <dir>']
+description = """
+Clone a git repository into the local directory <dir> (using
+gitlink:clone[]) and initialise the local branch "master".
 
-help = 'make a local clone of a remote repository'
-usage = """%prog [options] <repository> <dir>
+This operation is for example suitable to start working using the
+"tracking branch" workflow (see gitlink:stg[1]). Other means to setup
+an StGit stack are stglink:init[] and the '--create' and '--clone'
+commands of stglink:branch[].
 
-Clone a GIT <repository> into the local <dir> and initialise the
-patch stack."""
+The target directory <dir> will be created by this command, and must
+not already exist."""
 
-directory = DirectoryAnywhere(needs_current_series = False)
 options = []
 
+directory = DirectoryAnywhere(needs_current_series = False)
 
 def func(parser, options, args):
     """Clone the <repository> into the local <dir> and initialises the
index 2d672bb..b390584 100644 (file)
@@ -17,15 +17,15 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
+from stgit.argparse import opt
 from stgit.out import *
 from stgit import argparse, utils
 from stgit.commands import common
 from stgit.lib import git, transaction
 
-help = 'coalesce two or more patches into one'
-usage = """%prog [options] <patches>
-
+help = 'Coalesce two or more patches into one'
+usage = ['[options] <patches>']
+description = """
 Coalesce two or more patches, creating one big patch that contains all
 their changes.
 
@@ -33,10 +33,11 @@ If there are conflicts when reordering the patches to match the order
 you specify, you will have to resolve them manually just as if you had
 done a sequence of pushes and pops yourself."""
 
-directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-n', '--name', help = 'name of coalesced patch')
+options = [opt('-n', '--name', short = 'Name of coalesced patch')
            ] + argparse.message_options()
 
+directory = common.DirectoryHasRepositoryLib()
+
 class SaveTemplateDone(Exception):
     pass
 
index df7fa67..7d46724 100644 (file)
@@ -15,14 +15,17 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
+from stgit.argparse import opt
 from stgit.commands import common
 from stgit.lib import transaction
 from stgit.out import *
 
-help = 'permanently store the applied patches into stack base'
-usage = """%prog [<patchnames>] | -n NUM | --all
-
+help = 'Permanently store the applied patches into the stack base'
+usage = ['',
+         '<patchnames>',
+         '-n NUM',
+         '--all']
+description = """
 Merge one or more patches into the base of the current stack and
 remove them from the series while advancing the base. This is the
 opposite of 'stg uncommit'. Use this command if you no longer want to
@@ -36,11 +39,13 @@ The -n/--number option specifies the number of applied patches to
 commit (counting from the bottom of the stack). If -a/--all is given,
 all applied patches are committed."""
 
+options = [
+    opt('-n', '--number', type = 'int',
+        short = 'Commit the specified number of patches'),
+    opt('-a', '--all', action = 'store_true',
+        short = 'Commit all applied patches')]
+
 directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-n', '--number', type = 'int',
-                       help = 'commit the specified number of patches'),
-           make_option('-a', '--all', action = 'store_true',
-                       help = 'commit all applied patches')]
 
 def func(parser, options, args):
     """Commit a number of patches."""
index c5d3754..3ba7fc2 100644 (file)
@@ -16,21 +16,22 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
-
+from stgit.argparse import opt
 from stgit.commands import common
 from stgit.lib import transaction
 
-help = 'delete patches'
-usage = """%prog [options] <patch1> [<patch2>] [<patch3>..<patch4>]
-
+help = 'Delete patches'
+usage = ['[options] <patch1> [<patch2>] [<patch3>..<patch4>]']
+description = """
 Delete the patches passed as arguments.
 
 Note that the 'delete' operation is irreversible."""
 
+options = [
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default branch')]
+
 directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
 
 def func(parser, options, args):
     """Delete one or more patches."""
index 4f3e2c4..47e2e7f 100644 (file)
@@ -17,17 +17,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
 from pydoc import pager
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import argparse, stack, git
 
-help = 'show the tree diff'
-usage = """%prog [options] [<files or dirs>]
-
+help = 'Show the tree diff'
+usage = ['[options] [<files or dirs>]']
+description = """
 Show the diff (default) or diffstat between the current working copy
 or a tree-ish object and another tree-ish object (defaulting to HEAD).
 File names can also be given to restrict the diff output. The
@@ -35,17 +34,16 @@ tree-ish object can be an StGIT patch, a standard git commit, tag or
 tree. In addition to these, the command also supports '{base}',
 representing the bottom of the current stack.
 
-rev = '[branch:](<patch>|{base}) | <tree-ish>'
-"""
+rev = '[branch:](<patch>|{base}) | <tree-ish>'"""
+
+options = [
+    opt('-r', '--range', metavar = 'rev1[..[rev2]]', dest = 'revs',
+        short = 'Show the diff between revisions'),
+    opt('-s', '--stat', action = 'store_true',
+        short = 'Show the stat instead of the diff'),
+    ] + argparse.diff_opts_option()
 
 directory = DirectoryHasRepository()
-options = [make_option('-r', '--range',
-                       metavar = 'rev1[..[rev2]]', dest = 'revs',
-                       help = 'show the diff between revisions'),
-           make_option('-s', '--stat',
-                       help = 'show the stat instead of the diff',
-                       action = 'store_true')
-           ] + argparse.diff_opts_option()
 
 def func(parser, options, args):
     """Show the tree diff
index 92447a8..0db3254 100644 (file)
@@ -18,16 +18,15 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
-
+from stgit.argparse import opt
 from stgit import argparse, git, utils
 from stgit.commands import common
 from stgit.lib import git as gitlib, transaction
 from stgit.out import *
 
 help = 'edit a patch description or diff'
-usage = """%prog [options] [<patch>]
-
+usage = ['[options] [<patch>]']
+description = """
 Edit the description and author information of the given patch (or the
 current patch if no patch name was given). With --diff, also edit the
 diff.
@@ -54,15 +53,15 @@ If the patch diff is edited but does not apply, no changes are made to
 the patch at all. The edited patch is saved to a file which you can
 feed to "stg edit --file", once you have made sure it does apply."""
 
+options = [
+    opt('-d', '--diff', action = 'store_true',
+        short = 'Edit the patch diff'),
+    opt('-e', '--edit', action = 'store_true',
+        short = 'Invoke interactive editor'),
+    ] + (argparse.sign_options() + argparse.message_options() +
+         argparse.author_committer_options() + argparse.diff_opts_option())
+
 directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-d', '--diff',
-                       help = 'edit the patch diff',
-                       action = 'store_true'),
-           make_option('-e', '--edit', action = 'store_true',
-                       help = 'invoke interactive editor'),
-           ] + (argparse.sign_options() + argparse.message_options()
-                + argparse.author_committer_options()
-                + argparse.diff_opts_option())
 
 def patch_diff(repository, cd, diff, diff_flags):
     if diff:
index fb373a9..3d74cc8 100644 (file)
@@ -19,16 +19,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import os
-from optparse import make_option
-
+from stgit.argparse import opt
 from stgit.commands import common
 from stgit import argparse, git, templates
 from stgit.out import out
 from stgit.lib import git as gitlib
 
-help = 'exports patches to a directory'
-usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
-
+help = 'Export patches to a directory'
+usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]']
+description = """
 Export a range of applied patches to a given directory (defaults to
 'patches-<branch>') in a standard unified GNU diff format. A template
 file (defaulting to '.git/patchexport.tmpl' or
@@ -45,28 +44,26 @@ file:
   %(authemail)s   - author's e-mail
   %(authdate)s    - patch creation date
   %(commname)s    - committer's name
-  %(commemail)s   - committer's e-mail
-"""
+  %(commemail)s   - committer's e-mail"""
+
+options = [
+    opt('-d', '--dir',
+        short = 'Export patches to DIR instead of the default'),
+    opt('-p', '--patch', action = 'store_true',
+        short = 'Append .patch to the patch names'),
+    opt('-e', '--extension',
+        short = 'Append .EXTENSION to the patch names'),
+    opt('-n', '--numbered', action = 'store_true',
+        short = 'Prefix the patch names with order numbers'),
+    opt('-t', '--template', metavar = 'FILE',
+        short = 'Use FILE as a template'),
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default branch'),
+    opt('-s', '--stdout', action = 'store_true',
+        short = 'Dump the patches to the standard output'),
+    ] + argparse.diff_opts_option()
 
 directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-d', '--dir',
-                       help = 'export patches to DIR instead of the default'),
-           make_option('-p', '--patch',
-                       help = 'append .patch to the patch names',
-                       action = 'store_true'),
-           make_option('-e', '--extension',
-                       help = 'append .EXTENSION to the patch names'),
-           make_option('-n', '--numbered',
-                       help = 'prefix the patch names with order numbers',
-                       action = 'store_true'),
-           make_option('-t', '--template', metavar = 'FILE',
-                       help = 'Use FILE as a template'),
-           make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one'),
-           make_option('-s', '--stdout',
-                       help = 'dump the patches to the standard output',
-                       action = 'store_true')
-           ] + argparse.diff_opts_option()
 
 def func(parser, options, args):
     """Export a range of patches.
index cdb0b52..08f882c 100644 (file)
@@ -17,30 +17,29 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import argparse, stack, git
 
-help = 'show the files modified by a patch (or the current patch)'
-usage = """%prog [options] [[<branch>:]<patch>]
-
+help = 'Show the files modified by a patch (or the current patch)'
+usage = ['[options] [[<branch>:]<patch>]']
+description = """
 List the files modified by the given patch (defaulting to the current
 one). Passing the '--stat' option shows the diff statistics for the
 given patch. Note that this command doesn't show the files modified in
 the working tree and not yet included in the patch by a 'refresh'
 command. Use the 'diff' or 'status' commands for these files."""
 
+options = [
+    opt('-s', '--stat', action = 'store_true',
+        short = 'Show the diffstat'),
+    opt('--bare', action = 'store_true',
+        short = 'Bare file names (useful for scripting)'),
+    ] + argparse.diff_opts_option()
+
 directory = DirectoryHasRepository()
-options = [make_option('-s', '--stat',
-                       help = 'show the diff stat',
-                       action = 'store_true'),
-           make_option('--bare',
-                       help = 'bare file names (useful for scripting)',
-                       action = 'store_true')
-           ] + argparse.diff_opts_option()
 
 def func(parser, options, args):
     """Show the files modified by a patch (or the current patch)
index 5af7e85..ac8eaea 100644 (file)
@@ -17,24 +17,25 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit import stack, git
 
-help = 'push patches to the top, even if applied'
-usage = """%prog [<patches> | -s [<series>] ]
-
+help = 'Push patches to the top, even if applied'
+usage = ['<patches>',
+         '-s <series>']
+description = """
 Push a patch or a range of patches to the top even if applied. The
 necessary pop and push operations will be performed to accomplish
 this. The '--series' option can be used to rearrange the (top) patches
 as specified by the given series file (or the standard input)."""
 
+options = [
+    opt('-s', '--series', action = 'store_true',
+        short = 'Rearrange according to a series file')]
+
 directory = DirectoryGotoToplevel()
-options = [make_option('-s', '--series',
-                       help = 'rearrange according to a series file',
-                       action = 'store_true')]
 
 def func(parser, options, args):
     """Pops and pushed to make the named patch the topmost patch
index 3930a1f..6ddaea9 100644 (file)
@@ -16,17 +16,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 
-
-help = 'integrate a GNU diff patch into the current patch'
-usage = """%prog [options] [<file>]
-
+help = 'Integrate a GNU diff patch into the current patch'
+usage = ['[options] [<file>]']
+description = """
 Apply the given GNU diff file (or the standard input) onto the top of
 the current patch. With the '--threeway' option, the patch is applied
 onto the bottom of the current patch and a three-way merge is
@@ -34,13 +32,13 @@ performed with the current top. With the --base option, the patch is
 applied onto the specified base and a three-way merged is performed
 with the current top."""
 
-directory = DirectoryHasRepository()
-options = [make_option('-t', '--threeway',
-                       help = 'perform a three-way merge with the current patch',
-                       action = 'store_true'),
-           make_option('-b', '--base',
-                       help = 'use BASE instead of HEAD applying the patch')]
+options = [
+    opt('-t', '--threeway', action = 'store_true',
+        short = 'Perform a three-way merge with the current patch'),
+    opt('-b', '--base',
+        short = 'Use BASE instead of HEAD applying the patch')]
 
+directory = DirectoryHasRepository()
 
 def func(parser, options, args):
     """Integrate a GNU diff patch into the current patch
index 99ae6c0..33b20ed 100644 (file)
@@ -15,20 +15,20 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import OptionParser, make_option
 from stgit.commands import common
 from stgit.lib import transaction
 
-help = 'push or pop patches to the given one'
-usage = """%prog [options] <name>
-
+help = 'Push or pop patches to the given one'
+usage = ['<patch-name>']
+description = """
 Push/pop patches to/from the stack until the one given on the command
 line becomes current. There is no '--undo' option for 'goto'. Use the
 'push --undo' command for this."""
 
-directory = common.DirectoryHasRepositoryLib()
 options = []
 
+directory = common.DirectoryHasRepositoryLib()
+
 def func(parser, options, args):
     if len(args) != 1:
         parser.error('incorrect number of arguments')
index 1a38907..488ea18 100644 (file)
@@ -16,23 +16,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 
-
-help = 'hide a patch in the series'
-usage = """%prog [options] <patch-range>
-
+help = 'Hide a patch in the series'
+usage = ['[options] <patch-range>']
+description = """
 Hide a range of unapplied patches so that they are no longer shown in
 the plain 'series' command output."""
 
+options = [
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default branch')]
+
 directory = DirectoryHasRepository()
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
 
 def func(parser, options, args):
     """Hide a range of patch in the series
index 3819acc..18bab97 100644 (file)
@@ -15,15 +15,13 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import OptionParser, make_option
-
 from stgit.out import out
 from stgit.commands import common
 from stgit.lib import stack
 
-help = 'print the GIT hash value of a StGIT reference'
-usage = """%prog [options] [id]
-
+help = 'Print the git hash value of a StGit reference'
+usage = ['[options] [id]']
+description = """
 Print the SHA1 value of a Git id (defaulting to HEAD). In addition to
 the standard Git id's like heads and tags, this command also accepts
 '[<branch>:]<patch>' and '[<branch>:]{base}' showing the id of a patch
@@ -31,9 +29,10 @@ or the base of the stack. If no branch is specified, it defaults to the
 current one. The bottom of a patch is accessible with the
 '[<branch>:]<patch>^' format."""
 
-directory = common.DirectoryHasRepositoryLib()
 options = []
 
+directory = common.DirectoryHasRepositoryLib()
+
 def func(parser, options, args):
     """Show the applied patches
     """
index 5fc83e9..e97b01d 100644 (file)
@@ -18,16 +18,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 import sys, os, re, email
 from mailbox import UnixMailbox
 from StringIO import StringIO
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import argparse, stack, git
 
-help = 'import a GNU diff file as a new patch'
-usage = """%prog [options] [<file>|<url>]
-
+name = 'import'
+help = 'Import a GNU diff file as a new patch'
+usage = ['[options] [<file>|<url>]']
+description = """
 Create a new patch and apply the given GNU diff file (or the standard
 input). By default, the file name is used as the patch name but this
 can be overridden with the '--name' option. The patch can either be a
@@ -43,52 +43,44 @@ stack.
 The patch description has to be separated from the data with a '---'
 line."""
 
-directory = DirectoryHasRepository()
-options = [make_option('-m', '--mail',
-                       help = 'import the patch from a standard e-mail file',
-                       action = 'store_true'),
-           make_option('-M', '--mbox',
-                       help = 'import a series of patches from an mbox file',
-                       action = 'store_true'),
-           make_option('-s', '--series',
-                       help = 'import a series of patches',
-                       action = 'store_true'),
-           make_option('-u', '--url',
-                       help = 'import a patch from a URL',
-                       action = 'store_true'),
-           make_option('-n', '--name',
-                       help = 'use NAME as the patch name'),
-           make_option('-t', '--strip',
-                       help = 'strip numbering and extension from patch name',
-                       action = 'store_true'),
-           make_option('-i', '--ignore',
-                       help = 'ignore the applied patches in the series',
-                       action = 'store_true'),
-           make_option('--replace',
-                       help = 'replace the unapplied patches in the series',
-                       action = 'store_true'),
-           make_option('-b', '--base',
-                       help = 'use BASE instead of HEAD for file importing'),
-           make_option('-e', '--edit',
-                       help = 'invoke an editor for the patch description',
-                       action = 'store_true'),
-           make_option('-p', '--showpatch',
-                       help = 'show the patch content in the editor buffer',
-                       action = 'store_true'),
-           make_option('-a', '--author', metavar = '"NAME <EMAIL>"',
-                       help = 'use "NAME <EMAIL>" as the author details'),
-           make_option('--authname',
-                       help = 'use AUTHNAME as the author name'),
-           make_option('--authemail',
-                       help = 'use AUTHEMAIL as the author e-mail'),
-           make_option('--authdate',
-                       help = 'use AUTHDATE as the author date'),
-           make_option('--commname',
-                       help = 'use COMMNAME as the committer name'),
-           make_option('--commemail',
-                       help = 'use COMMEMAIL as the committer e-mail')
-           ] + argparse.sign_options()
+options = [
+    opt('-m', '--mail', action = 'store_true',
+        short = 'Import the patch from a standard e-mail file'),
+    opt('-M', '--mbox', action = 'store_true',
+        short = 'Import a series of patches from an mbox file'),
+    opt('-s', '--series', action = 'store_true',
+        short = 'Import a series of patches'),
+    opt('-u', '--url', action = 'store_true',
+        short = 'Import a patch from a URL'),
+    opt('-n', '--name',
+        short = 'Use NAME as the patch name'),
+    opt('-t', '--strip', action = 'store_true',
+        short = 'Strip numbering and extension from patch name'),
+    opt('-i', '--ignore', action = 'store_true',
+        short = 'Ignore the applied patches in the series'),
+    opt('--replace', action = 'store_true',
+        short = 'Replace the unapplied patches in the series'),
+    opt('-b', '--base',
+        short = 'Use BASE instead of HEAD for file importing'),
+    opt('-e', '--edit', action = 'store_true',
+        short = 'Invoke an editor for the patch description'),
+    opt('-p', '--showpatch', action = 'store_true',
+        short = 'Show the patch content in the editor buffer'),
+    opt('-a', '--author', metavar = '"NAME <EMAIL>"',
+        short = 'Use "NAME <EMAIL>" as the author details'),
+    opt('--authname',
+        short = 'Use AUTHNAME as the author name'),
+    opt('--authemail',
+        short = 'Use AUTHEMAIL as the author e-mail'),
+    opt('--authdate',
+        short = 'Use AUTHDATE as the author date'),
+    opt('--commname',
+        short = 'Use COMMNAME as the committer name'),
+    opt('--commemail',
+        short = 'Use COMMEMAIL as the committer e-mail'),
+    ] + argparse.sign_options()
 
+directory = DirectoryHasRepository()
 
 def __strip_patch_name(name):
     stripped = re.sub('^[0-9]+-(.*)$', '\g<1>', name)
index b68acd7..f7f7a21 100644 (file)
@@ -19,15 +19,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 from stgit.commands import common
 from stgit.lib import stack
 
-help = 'initialise the current branch for use with StGIT'
-usage = """%prog [options]
+help = 'Initialise the current branch for use with StGIT'
+usage = ['']
+description = """
+Initialise the current git branch to be used as an StGIT stack. The
+branch (and the git repository it is in) must already exist and
+contain at least one commit."""
 
-Initialise the current GIT branch to be used as an StGIT stack. Note
-that you must already be in a GIT repository and .git/HEAD must point
-to a valid file in refs/heads/."""
+options = []
 
 directory = common.DirectoryHasRepositoryLib()
-options = []
 
 def func(parser, options, args):
     """Performs the repository initialisation
index 52d55a5..b505ed5 100644 (file)
@@ -16,16 +16,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os, time
-from optparse import OptionParser, make_option
 from pydoc import pager
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit import stack, git
 from stgit.out import *
 from stgit.run import Run
 
-help = 'display the patch changelog'
-usage = """%prog [options] [patch]
-
+help = 'Display the patch changelog'
+usage = ['[options] [patch]']
+description = """
 List all the current and past commit ids of the given patch. The
 --graphical option invokes gitk instead of printing. The changelog
 commit messages have the form '<action> <new-patch-id>'. The <action>
@@ -44,20 +44,19 @@ represent the changes to the entire base of the current
 patch. Conflicts reset the patch content and a subsequent 'refresh'
 will show the entire patch."""
 
+options = [
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default one'),
+    opt('-p', '--patch', action = 'store_true',
+        short = 'Show the refresh diffs'),
+    opt('-n', '--number', type = 'int',
+        short = 'Limit the output to NUMBER commits'),
+    opt('-f', '--full', action = 'store_true',
+        short = 'Show the full commit ids'),
+    opt('-g', '--graphical', action = 'store_true',
+        short = 'Run gitk instead of printing')]
+
 directory = DirectoryHasRepository()
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one'),
-           make_option('-p', '--patch',
-                       help = 'show the refresh diffs',
-                       action = 'store_true'),
-           make_option('-n', '--number', type = 'int',
-                       help = 'limit the output to NUMBER commits'),
-           make_option('-f', '--full',
-                       help = 'show the full commit ids',
-                       action = 'store_true'),
-           make_option('-g', '--graphical',
-                       help = 'run gitk instead of printing',
-                       action = 'store_true')]
 
 def show_log(log, options):
     """List the patch changelog
index 521c8eb..83acc86 100644 (file)
@@ -17,8 +17,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 import sys, os, re, time, datetime, socket, smtplib, getpass
 import email, email.Utils, email.Header
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
@@ -26,10 +25,9 @@ from stgit import argparse, stack, git, version, templates
 from stgit.config import config
 from stgit.run import Run
 
-
-help = 'send a patch or series of patches by e-mail'
-usage = r"""%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
-
+help = 'Send a patch or series of patches by e-mail'
+usage = [' [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]']
+description = r"""
 Send a patch or a range of patches by e-mail using the SMTP server
 specified by the 'stgit.smtpserver' configuration option, or the
 '--smtp-server' command line option. This option can also be an
@@ -93,65 +91,54 @@ the following:
   %(prefix)s       - 'prefix ' string passed on the command line
   %(shortdescr)s   - the first line of the patch description"""
 
+options = [
+    opt('-a', '--all', action = 'store_true',
+        short = 'E-mail all the applied patches'),
+    opt('--to', action = 'append',
+        short = 'Add TO to the To: list'),
+    opt('--cc', action = 'append',
+        short = 'Add CC to the Cc: list'),
+    opt('--bcc', action = 'append',
+        short = 'Add BCC to the Bcc: list'),
+    opt('--auto', action = 'store_true',
+        short = 'Automatically cc the patch signers'),
+    opt('--noreply', action = 'store_true',
+        short = 'Do not send subsequent messages as replies'),
+    opt('--unrelated', action = 'store_true',
+        short = 'Send patches without sequence numbering'),
+    opt('--attach', action = 'store_true',
+        short = 'Send a patch as attachment'),
+    opt('-v', '--version', metavar = 'VERSION',
+        short = 'Add VERSION to the [PATCH ...] prefix'),
+    opt('--prefix', metavar = 'PREFIX',
+        short = 'Add PREFIX to the [... PATCH ...] prefix'),
+    opt('-t', '--template', metavar = 'FILE',
+        short = 'Use FILE as the message template'),
+    opt('-c', '--cover', metavar = 'FILE',
+        short = 'Send FILE as the cover message'),
+    opt('-e', '--edit-cover', action = 'store_true',
+        short = 'Edit the cover message before sending'),
+    opt('-E', '--edit-patches', action = 'store_true',
+        short = 'Edit each patch before sending'),
+    opt('-s', '--sleep', type = 'int', metavar = 'SECONDS',
+        short = 'Sleep for SECONDS between e-mails sending'),
+    opt('--refid',
+        short = 'Use REFID as the reference id'),
+    opt('--smtp-server', metavar = 'HOST[:PORT] or "/path/to/sendmail -t -i"',
+        short = 'SMTP server or command to use for sending mail'),
+    opt('-u', '--smtp-user', metavar = 'USER',
+        short = 'Username for SMTP authentication'),
+    opt('-p', '--smtp-password', metavar = 'PASSWORD',
+        short = 'Password for SMTP authentication'),
+    opt('-T', '--smtp-tls', action = 'store_true',
+        short = 'Use SMTP with TLS encryption'),
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default branch'),
+    opt('-m', '--mbox', action = 'store_true',
+        short = 'Generate an mbox file instead of sending')
+    ] + argparse.diff_opts_option()
+
 directory = DirectoryHasRepository()
-options = [make_option('-a', '--all',
-                       help = 'e-mail all the applied patches',
-                       action = 'store_true'),
-           make_option('--to',
-                       help = 'add TO to the To: list',
-                       action = 'append'),
-           make_option('--cc',
-                       help = 'add CC to the Cc: list',
-                       action = 'append'),
-           make_option('--bcc',
-                       help = 'add BCC to the Bcc: list',
-                       action = 'append'),
-           make_option('--auto',
-                       help = 'automatically cc the patch signers',
-                       action = 'store_true'),
-           make_option('--noreply',
-                       help = 'do not send subsequent messages as replies',
-                       action = 'store_true'),
-           make_option('--unrelated',
-                       help = 'send patches without sequence numbering',
-                       action = 'store_true'),
-           make_option('--attach',
-                       help = 'send a patch as attachment',
-                       action = 'store_true'),
-           make_option('-v', '--version', metavar = 'VERSION',
-                       help = 'add VERSION to the [PATCH ...] prefix'),
-           make_option('--prefix', metavar = 'PREFIX',
-                       help = 'add PREFIX to the [... PATCH ...] prefix'),
-           make_option('-t', '--template', metavar = 'FILE',
-                       help = 'use FILE as the message template'),
-           make_option('-c', '--cover', metavar = 'FILE',
-                       help = 'send FILE as the cover message'),
-           make_option('-e', '--edit-cover',
-                       help = 'edit the cover message before sending',
-                       action = 'store_true'),
-           make_option('-E', '--edit-patches',
-                       help = 'edit each patch before sending',
-                       action = 'store_true'),
-           make_option('-s', '--sleep', type = 'int', metavar = 'SECONDS',
-                       help = 'sleep for SECONDS between e-mails sending'),
-           make_option('--refid',
-                       help = 'use REFID as the reference id'),
-           make_option('--smtp-server',
-                       metavar = 'HOST[:PORT] or "/path/to/sendmail -t -i"',
-                       help = 'SMTP server or command to use for sending mail'),
-           make_option('-u', '--smtp-user', metavar = 'USER',
-                       help = 'username for SMTP authentication'),
-           make_option('-p', '--smtp-password', metavar = 'PASSWORD',
-                       help = 'username for SMTP authentication'),
-           make_option('-T', '--smtp-tls',
-                       help = 'use SMTP with TLS encryption',
-                       action = 'store_true'),
-           make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one'),
-           make_option('-m', '--mbox',
-                       help = 'generate an mbox file instead of sending',
-                       action = 'store_true')
-           ] + argparse.diff_opts_option()
 
 def __get_sender():
     """Return the 'authname <authemail>' string as read from the
index 4a58d52..4ed2079 100644 (file)
@@ -16,30 +16,33 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
-
 from stgit import argparse, utils
 from stgit.commands import common
 from stgit.lib import git as gitlib, transaction
 from stgit.config import config
 
-help = 'create a new patch and make it the topmost one'
-usage = """%prog [options] [name]
+help = 'Create a new, empty patch'
+usage = ['[options] [<name>]']
+description = """
+Create a new, empty patch on the current stack. The new patch is
+created on top of the currently applied patches, and is made the new
+top of the stack. Uncommitted changes in the work tree are not
+included in the patch -- that is handled by stglink:refresh[].
 
-Create a new, empty patch and make it the topmost one. If the
-'--message' option is not passed, an editor is invoked with the
-.git/patchdescr.tmpl, ~/.stgit/templates/patchdescr.tmpl or
-/usr/share/stgit/templates/patchdescr.tmpl file used a as template,
-together with generated lines. The local changes in the working tree
-are not included in the patch; an "stg refresh" command is needed for
-this.
+The given name must be unique in the stack, and may only contain
+alphanumeric characters, dashes and underscores. If no name is given,
+one is generated from the first line of the patch's commit message.
 
-If no name is given for the new patch, one is generated from the first
-line of the commit message."""
+An editor will be launched to edit the commit message to be used for
+the patch, unless the '--message' flag already specified one. The
+'patchdescr.tmpl' template file (if available) is used to pre-fill the
+editor."""
 
-directory = common.DirectoryHasRepositoryLib()
 options = (argparse.author_committer_options()
-           + argparse.message_options() + argparse.sign_options())
+           + argparse.message_options()
+           + argparse.sign_options())
+
+directory = common.DirectoryHasRepositoryLib()
 
 def func(parser, options, args):
     """Create a new patch."""
index 140699d..656a4a1 100644 (file)
@@ -16,29 +16,28 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
 from pydoc import pager
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 
-
-help = 'show the applied patches modifying a file'
-usage = """%prog [options] [<files or dirs>]
-
+help = 'Show the applied patches modifying a file'
+usage = ['[options] [<files or dirs>]']
+description = """
 Show the applied patches modifying the given files. Without arguments,
 it shows the patches affected by the local tree modifications. The
 '--diff' option also lists the patch log and the diff for the given
 files."""
 
+options = [
+    opt('-d', '--diff', action = 'store_true',
+        short = 'Show the diff for the given files'),
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default branch')]
+
 directory = DirectoryHasRepository()
-options = [make_option('-d', '--diff',
-                       help = 'show the diff for the given files',
-                       action = 'store_true'),
-           make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
 
 diff_tmpl = \
           '-------------------------------------------------------------------------------\n' \
index 44b461e..72b2359 100644 (file)
@@ -16,18 +16,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 from stgit.stack import Series
 
-
-help = 'import a patch from a different branch or a commit object'
-usage = """%prog [options] ([<patch1>] [<patch2>] [<patch3>..<patch4>])|<commit>
-
+help = 'Import a patch from a different branch or a commit object'
+usage = ['[options] ([<patch1>] [<patch2>] [<patch3>..<patch4>])|<commit>']
+description = """
 Import one or more patches from a different branch or a commit object
 into the current series. By default, the name of the imported patch is
 used as the name of the current patch. It can be overridden with the
@@ -35,28 +33,25 @@ used as the name of the current patch. It can be overridden with the
 option. The log and author information are those of the commit
 object."""
 
+options = [
+    opt('-n', '--name',
+        short = 'Use NAME as the patch name'),
+    opt('-B', '--ref-branch',
+        short = 'Pick patches from BRANCH'),
+    opt('-r', '--reverse', action = 'store_true',
+        short = 'Reverse the commit object before importing'),
+    opt('-p', '--parent', metavar = 'COMMITID',
+        short = 'Use COMMITID as parent'),
+    opt('-x', '--expose', action = 'store_true',
+        short = 'Append the imported commit id to the patch log'),
+    opt('--fold', action = 'store_true',
+        short = 'Fold the commit object into the current patch'),
+    opt('--update', action = 'store_true',
+        short = 'Like fold but only update the current patch files'),
+    opt('--unapplied', action = 'store_true',
+        short = 'Keep the patch unapplied')]
+
 directory = DirectoryGotoToplevel()
-options = [make_option('-n', '--name',
-                       help = 'use NAME as the patch name'),
-           make_option('-B', '--ref-branch',
-                       help = 'pick patches from BRANCH'),
-           make_option('-r', '--reverse',
-                       help = 'reverse the commit object before importing',
-                       action = 'store_true'),
-           make_option('-p', '--parent', metavar = 'COMMITID',
-                       help = 'use COMMITID as parent'),
-           make_option('-x', '--expose',
-                       help = 'append the imported commit id to the patch log',
-                       action = 'store_true'),
-           make_option('--fold',
-                       help = 'fold the commit object into the current patch',
-                       action = 'store_true'),
-           make_option('--update',
-                       help = 'like fold but only update the current patch files',
-                       action = 'store_true'),
-           make_option('--unapplied',
-                       help = 'keep the patch unapplied',
-                       action = 'store_true')]
 
 def __pick_commit(commit_id, patchname, options):
     """Pick a commit id.
index dedf41b..b3c4008 100644 (file)
@@ -17,16 +17,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit import stack, git
 
-
-help = 'pop one or more patches from the stack'
-usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
-
+help = 'Pop one or more patches from the stack'
+usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]']
+description = """
 Pop the topmost patch or a range of patches from the stack. The
 command fails if there are conflicts or local changes (and --keep was
 not specified).
@@ -36,16 +34,15 @@ patches passed on the command line are popped from the stack. Some of
 the push operations may fail because of conflicts (push --undo would
 revert the last push operation)."""
 
-directory = DirectoryGotoToplevel()
-options = [make_option('-a', '--all',
-                       help = 'pop all the applied patches',
-                       action = 'store_true'),
-           make_option('-n', '--number', type = 'int',
-                       help = 'pop the specified number of patches'),
-           make_option('-k', '--keep',
-                       help = 'keep the local changes',
-                       action = 'store_true')]
+options = [
+    opt('-a', '--all', action = 'store_true',
+        short = 'Pop all the applied patches'),
+    opt('-n', '--number', type = 'int',
+        short = 'Pop the specified number of patches'),
+    opt('-k', '--keep', action = 'store_true',
+        short = 'Keep the local changes')]
 
+directory = DirectoryGotoToplevel()
 
 def func(parser, options, args):
     """Pop the topmost patch from the stack
index bec7fd7..3801bf2 100644 (file)
@@ -16,18 +16,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit.config import GitConfigException
 from stgit import stack, git
 
-
-help = 'pull the changes from the remote repository'
-usage = """%prog [options] [<repository>]
-
+help = 'Pull changes from a remote repository'
+usage = ['[options] [<repository>]']
+description = """
 Pull the latest changes from the given remote repository (defaulting
 to branch.<name>.remote, or 'origin' if not set). This command works
 by popping all the patches from the stack, pulling the changes in the
@@ -38,13 +36,13 @@ resolved and the patch pushed again.
 
 Check the 'git fetch' documentation for the <repository> format."""
 
+options = [
+    opt('-n', '--nopush', action = 'store_true',
+        short = 'Do not push the patches back after pulling'),
+    opt('-m', '--merged', action = 'store_true',
+        short = 'Check for patches merged upstream')]
+
 directory = DirectoryGotoToplevel()
-options = [make_option('-n', '--nopush',
-                       help = 'do not push the patches back after pulling',
-                       action = 'store_true'),
-           make_option('-m', '--merged',
-                       help = 'check for patches merged upstream',
-                       action = 'store_true')]
 
 def func(parser, options, args):
     """Pull the changes from a remote repository
index 979835b..ee7b56e 100644 (file)
@@ -17,17 +17,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 
-
-help = 'push one or more patches onto of the stack'
-usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
-
+help = 'Push one or more patches onto the 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 the result of the 'push'
@@ -39,22 +37,19 @@ command run.
 The command also notifies when the patch becomes empty (fully merged
 upstream) or is modified (three-way merged) by the 'push' operation."""
 
-directory = DirectoryGotoToplevel()
-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('--reverse',
-                       help = 'push the patches in reverse order',
-                       action = 'store_true'),
-           make_option('-m', '--merged',
-                       help = 'check for patches merged upstream',
-                       action = 'store_true'),
-           make_option('--undo',
-                       help = 'undo the last patch pushing',
-                       action = 'store_true')]
+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'),
+    opt('--undo', action = 'store_true',
+        short = 'Undo the last patch pushing')]
 
+directory = DirectoryGotoToplevel()
 
 def func(parser, options, args):
     """Pushes the given patch or all onto the series
index ec2e04c..ffec329 100644 (file)
@@ -16,16 +16,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit import stack, git
 
-
-help = 'move the stack base to another point in history'
-usage = """%prog [options] <new-base-id>
-
+help = 'Move the stack base to another point in history'
+usage = ['[options] <new-base-id>']
+description = """
 Pop all patches from current stack, move the stack base to the given
 <new-base-id> and push the patches back.
 
@@ -41,13 +39,13 @@ Or if you want to skip that patch:
         $ stg push --undo
         $ stg push next-patch..top-patch"""
 
+options = [
+    opt('-n', '--nopush', action = 'store_true',
+        short = 'Do not push the patches back after rebasing'),
+    opt('-m', '--merged', action = 'store_true',
+        short = 'Check for patches merged upstream')]
+
 directory = DirectoryGotoToplevel()
-options = [make_option('-n', '--nopush',
-                       help = 'do not push the patches back after rebasing',
-                       action = 'store_true'),
-           make_option('-m', '--merged',
-                       help = 'check for patches merged upstream',
-                       action = 'store_true')]
 
 def func(parser, options, args):
     """Rebase the current stack
index 73e4ee0..e30085b 100644 (file)
@@ -17,43 +17,39 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 from stgit.config import config
 
-
-help = 'generate a new commit for the current patch'
-usage = """%prog [options] [<files or dirs>]
-
+help = 'Generate a new commit for the current patch'
+usage = ['[options] [<files or dirs>]']
+description = """
 Include the latest tree changes in the current patch. This command
 generates a new GIT commit object with the patch details, the previous
 one no longer being visible. The '--force' option is useful
 when a commit object was created with a different tool
 but the changes need to be included in the current patch."""
 
+options = [
+    opt('-f', '--force', action = 'store_true',
+        short = 'Force the refresh even if HEAD and top differ'),
+    opt('--update', action = 'store_true',
+        short = 'Only update the current patch files'),
+    opt('--index', action = 'store_true',
+        short = 'Refresh from index instead of worktree', long = """
+        Instead of setting the patch top to the current contents of
+        the worktree, set it to the current contents of the index."""),
+    opt('--undo', action = 'store_true',
+        short = 'Revert the commit generated by the last refresh'),
+    opt('-a', '--annotate', metavar = 'NOTE',
+        short = 'Annotate the patch log entry'),
+    opt('-p', '--patch',
+        short = 'Refresh (applied) PATCH instead of the top patch')]
+
 directory = DirectoryHasRepository()
-options = [make_option('-f', '--force',
-                       help = 'force the refresh even if HEAD and '\
-                       'top differ',
-                       action = 'store_true'),
-           make_option('--update',
-                       help = 'only update the current patch files',
-                       action = 'store_true'),
-           make_option('--index',
-                       help = 'use the current contents of the index instead of looking at the working directory',
-                       action = 'store_true'),
-           make_option('--undo',
-                       help = 'revert the commit generated by the last refresh',
-                       action = 'store_true'),
-           make_option('-a', '--annotate', metavar = 'NOTE',
-                       help = 'annotate the patch log entry'),
-           make_option('-p', '--patch',
-                       help = 'refresh (applied) PATCH instead of the top one')
-           ]
 
 def func(parser, options, args):
     """Generate a new commit for the current or given patch.
index 1d7c43b..b978ecf 100644 (file)
@@ -16,24 +16,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 
+help = 'Rename a patch'
+usage = ['[options] [oldpatch] <newpatch>']
+description = """
+Rename <oldpatch> into <newpatch> in a series. If <oldpatch> is not
+given, the top-most patch will be renamed."""
 
-help = 'rename a patch in the series'
-usage = """%prog [options] [oldpatch] <newpatch>
-
-Rename <oldpatch> into <newpatch> in a series. If <oldpatch> is not given, the
-top-most patch will be renamed. """
+options = [
+    opt('-b', '--branch',
+        short = 'use BRANCH instead of the default one')]
 
 directory = DirectoryHasRepository()
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
-
 
 def func(parser, options, args):
     """Rename a patch in the series
index aa34792..a5156cd 100644 (file)
@@ -18,8 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
@@ -27,8 +26,8 @@ from stgit.run import *
 from stgit import stack, git
 
 help = 'Fix StGit metadata if branch was modified with git commands'
-usage = """%prog [options]
-
+usage = ['']
+description = """
 If you modify an StGit stack (branch) with some git commands -- such
 as commit, pull, merge, and rebase -- you will leave the StGit
 metadata in an inconsistent state. In that situation, you have two
@@ -68,9 +67,10 @@ NOTE: If using git commands on the stack was a mistake, running "stg
 repair" is _not_ what you want. In that case, what you want is option
 (1) above."""
 
-directory = DirectoryGotoToplevel()
 options = []
 
+directory = DirectoryGotoToplevel()
+
 class Commit(object):
     def __init__(self, id):
         self.id = id
index 4ee75b8..5643da8 100644 (file)
@@ -17,31 +17,29 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit import stack, git, basedir
 from stgit.config import config, file_extensions
 from stgit.gitmergeonefile import interactive_merge
 
-
-help = 'mark a file conflict as solved'
-usage = """%prog [options] [<files...>]
-
+help = 'Mark a file conflict as solved'
+usage = ['[options] [<files...>]']
+description = """
 Mark a merge conflict as resolved. The conflicts can be seen with the
 'status' command, the corresponding files being prefixed with a
 'C'."""
 
+options = [
+    opt('-a', '--all', action = 'store_true',
+        short = 'Mark all conflicts as solved'),
+    opt('-r', '--reset', metavar = '(ancestor|current|patched)',
+        short = 'Reset the file(s) to the given state'),
+    opt('-i', '--interactive', action = 'store_true',
+        short = 'Run the interactive merging tool')]
+
 directory = DirectoryHasRepository(needs_current_series = False)
-options = [make_option('-a', '--all',
-                       help = 'mark all conflicts as solved',
-                       action = 'store_true'),
-           make_option('-r', '--reset', metavar = '(ancestor|current|patched)',
-                       help = 'reset the file(s) to the given state'),
-           make_option('-i', '--interactive',
-                       help = 'run the interactive merging tool',
-                       action = 'store_true')]
 
 def func(parser, options, args):
     """Mark the conflict as resolved
index f705d00..da31061 100644 (file)
@@ -16,62 +16,49 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
-
+from stgit.argparse import opt
 from stgit.commands import common
 from stgit.commands.common import parse_patches
 from stgit.out import out
 from stgit.config import config
 
-help = 'print the patch series'
-usage = """%prog [options] [<patch-range>]
-
+help = 'Print the patch series'
+usage = ['[options] [<patch-range>]']
+description = """
 Show all the patches in the series or just those in the given
 range. The applied patches are prefixed with a '+', the unapplied ones
 with a '-' and the hidden ones with a '!'. The current patch is
 prefixed with a '>'. Empty patches are prefixed with a '0'."""
 
-directory = common.DirectoryHasRepositoryLib()
-
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one'),
-           make_option('-a', '--all',
-                       help = 'show all patches, including the hidden ones',
-                       action = 'store_true'),
-           make_option('-A', '--applied',
-                       help = 'show the applied patches only',
-                       action = 'store_true'),
-           make_option('-U', '--unapplied',
-                       help = 'show the unapplied patches only',
-                       action = 'store_true'),
-           make_option('-H', '--hidden',
-                       help = 'show the hidden patches only',
-                       action = 'store_true'),
-           make_option('-m', '--missing', metavar = 'BRANCH',
-                       help = 'show patches in BRANCH missing in current'),
-           make_option('-c', '--count',
-                       help = 'print the number of patches in the series',
-                       action = 'store_true'),
-           make_option('-d', '--description',
-                       help = 'show a short description for each patch',
-                       action = 'store_true'),
-           make_option('--author',
-                       help = 'show the author name for each patch',
-                       action = 'store_true'),
-           make_option('-e', '--empty',
-                       help = 'check whether patches are empty '
-                       '(much slower)',
-                       action = 'store_true'),
-           make_option('--showbranch',
-                       help = 'append the branch name to the listed patches',
-                       action = 'store_true'),
-           make_option('--noprefix',
-                       help = 'do not show the patch status prefix',
-                       action = 'store_true'),
-           make_option('-s', '--short',
-                       help = 'list just the patches around the topmost patch',
-                       action = 'store_true')]
+options = [
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default branch'),
+    opt('-a', '--all', action = 'store_true',
+        short = 'Show all patches, including the hidden ones'),
+    opt('-A', '--applied', action = 'store_true',
+        short = 'Show the applied patches only'),
+    opt('-U', '--unapplied', action = 'store_true',
+        short = 'Show the unapplied patches only'),
+    opt('-H', '--hidden', action = 'store_true',
+        short = 'Show the hidden patches only'),
+    opt('-m', '--missing', metavar = 'BRANCH',
+        short = 'Show patches in BRANCH missing in current'),
+    opt('-c', '--count', action = 'store_true',
+        short = 'Print the number of patches in the series'),
+    opt('-d', '--description', action = 'store_true',
+        short = 'Show a short description for each patch'),
+    opt('--author', action = 'store_true',
+        short = 'Show the author name for each patch'),
+    opt('-e', '--empty', action = 'store_true',
+        short = 'Check whether patches are empty'),
+    opt('--showbranch', action = 'store_true',
+        short = 'Append the branch name to the listed patches'),
+    opt('--noprefix', action = 'store_true',
+        short = 'Do not show the patch status prefix'),
+    opt('-s', '--short', action = 'store_true',
+        short = 'List just the patches around the topmost patch')]
 
+directory = common.DirectoryHasRepositoryLib()
 
 def __get_description(stack, patch):
     """Extract and return a patch's short description
index 36361d6..c12793f 100644 (file)
@@ -16,29 +16,27 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
 from pydoc import pager
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit import argparse, git
 
-help = 'show the commit corresponding to a patch (or the current patch)'
-usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
+help = 'Show the commit corresponding to a patch'
+usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]']
+description = """
+Show the commit log and the diff corresponding to the given patches.
+The output is similar to that generated by 'git show'."""
 
-Show the commit log and the diff corresponding to the given
-patches. The output is similar to that generated by the 'git show'
-command."""
+options = [
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default branch'),
+    opt('-a', '--applied', action = 'store_true',
+        short = 'Show the applied patches'),
+    opt('-u', '--unapplied', action = 'store_true',
+        short = 'Show the unapplied patches'),
+    ] + argparse.diff_opts_option()
 
 directory = DirectoryHasRepository()
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one'),
-           make_option('-a', '--applied',
-                       help = 'show the applied patches',
-                       action = 'store_true'),
-           make_option('-u', '--unapplied',
-                       help = 'show the unapplied patches',
-                       action = 'store_true')
-           ] + argparse.diff_opts_option()
 
 def func(parser, options, args):
     """Show commit log and diff
index 7e5c955..bf13f2b 100644 (file)
@@ -17,27 +17,40 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit import stack, git
 
-
-help = 'send patches deeper down the stack'
-usage = """%prog [-t <target patch>] [-n] [<patches>]
-
-Pop all patches (or all patches including <target patch>), then
-push the specified <patches> (the current patch by default), and
-then push back into place the formerly-applied patches (unless -n
-is also given)."""
+help = 'Send patches deeper down the stack'
+usage = ['[-t <target patch>] [-n] [<patches>]']
+description = """
+This is the opposite operation of stglink:float[]: move the specified
+patches down the stack.  It is for example useful to group stable
+patches near the bottom of the stack, where they are less likely to be
+impacted by the push of another patch, and from where they can be more
+easily committed or pushed.
+
+If no patch is specified on command-line, the current patch gets sunk.
+By default patches are sunk to the bottom of the stack, but the '--to'
+option allows to place them under any applied patch.
+
+Sinking internally involves popping all patches (or all patches
+including <target patch>), then pushing the patches to sink, and then
+(unless '--nopush' is also given) pushing back into place the
+formerly-applied patches."""
+
+options = [
+    opt('-n', '--nopush', action = 'store_true',
+        short = 'Do not push the patches back after sinking', long = """
+        Do not push back on the stack the formerly-applied patches.
+        Only the patches to sink are pushed."""),
+    opt('-t', '--to', metavar = 'TARGET',
+        short = 'Sink patches below the TARGET patch', long = """
+        Specify a target patch to place the patches below, instead of
+        sinking them to the bottom of the stack.""")]
 
 directory = DirectoryGotoToplevel()
-options = [make_option('-n', '--nopush',
-                       help = 'do not push the patches back after sinking',
-                       action = 'store_true'),
-           make_option('-t', '--to', metavar = 'TARGET',
-                       help = 'sink patches below TARGET patch')]
 
 def func(parser, options, args):
     """Sink patches down the stack.
index a84ff6c..eadb507 100644 (file)
@@ -17,16 +17,14 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit import stack, git
 
-
-help = 'show the tree status'
-usage = """%prog [options] [<files or dirs>]
-
+help = 'Show the tree status'
+usage = ['[options] [<files or dirs>]']
+description = """
 Show the status of the whole working copy or the given files. The
 command also shows the files in the current directory which are not
 under revision control. The files are prefixed as follows:
@@ -37,32 +35,26 @@ under revision control. The files are prefixed as follows:
   C - conflict
   ? - unknown
 
-A 'refresh' command clears the status of the modified, new and deleted
-files."""
+An 'stg refresh' command clears the status of the modified, new and
+deleted files."""
+
+options = [
+    opt('-m', '--modified', action = 'store_true',
+        short = 'Show modified files only'),
+    opt('-n', '--new', action = 'store_true',
+        short = 'Show new files only'),
+    opt('-d', '--deleted', action = 'store_true',
+        short = 'Show deleted files only'),
+    opt('-c', '--conflict', action = 'store_true',
+        short = 'Show conflict files only'),
+    opt('-u', '--unknown', action = 'store_true',
+        short = 'Show unknown files only'),
+    opt('-x', '--noexclude', action = 'store_true',
+        short = 'Do not exclude any files from listing'),
+    opt('--reset', action = 'store_true',
+        short = 'Reset the current tree changes')]
 
 directory = DirectoryHasRepository(needs_current_series = False)
-options = [make_option('-m', '--modified',
-                       help = 'show modified files only',
-                       action = 'store_true'),
-           make_option('-n', '--new',
-                       help = 'show new files only',
-                       action = 'store_true'),
-           make_option('-d', '--deleted',
-                       help = 'show deleted files only',
-                       action = 'store_true'),
-           make_option('-c', '--conflict',
-                       help = 'show conflict files only',
-                       action = 'store_true'),
-           make_option('-u', '--unknown',
-                       help = 'show unknown files only',
-                       action = 'store_true'),
-           make_option('-x', '--noexclude',
-                       help = 'do not exclude any files from listing',
-                       action = 'store_true'),
-           make_option('--reset',
-                       help = 'reset the current tree changes',
-                       action = 'store_true')]
-
 
 def status(files, modified, new, deleted, conflict, unknown, noexclude):
     """Show the tree status
index 0e2c18f..ef94439 100644 (file)
@@ -16,18 +16,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
 import stgit.commands.common
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 
-
-help = 'synchronise patches with a branch or a series'
-usage = """%prog [options] [<patch1>] [<patch2>] [<patch3>..<patch4>]
-
+help = 'Synchronise patches with a branch or a series'
+usage = ['[options] [<patch1>] [<patch2>] [<patch3>..<patch4>]']
+description = """
 For each of the specified patches perform a three-way merge with the
 same patch in the specified branch or series. The command can be used
 for keeping patches on several branches in sync. Note that the
@@ -36,17 +34,17 @@ in the series must apply cleanly.
 
 The sync operation can be reverted for individual patches with --undo."""
 
+options = [
+    opt('-a', '--all', action = 'store_true',
+        short = 'Synchronise all the applied patches'),
+    opt('-B', '--ref-branch',
+        short = 'Syncronise patches with BRANCH'),
+    opt('-s', '--series',
+        short = 'Syncronise patches with SERIES'),
+    opt('--undo', action = 'store_true',
+        short = 'Undo the synchronisation of the current patch')]
+
 directory = DirectoryGotoToplevel()
-options = [make_option('-a', '--all',
-                       help = 'synchronise all the applied patches',
-                       action = 'store_true'),
-           make_option('-B', '--ref-branch',
-                       help = 'syncronise patches with BRANCH'),
-           make_option('-s', '--series',
-                       help = 'syncronise patches with SERIES'),
-           make_option('--undo',
-                       help = 'undo the synchronisation of the current patch',
-                       action = 'store_true')]
 
 def __check_all():
     check_local_changes()
index c8fbba4..f4962e7 100644 (file)
@@ -16,19 +16,20 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
-
+from stgit.argparse import opt
 from stgit.commands import common
 from stgit.out import out
 
-help = 'print the name of the top patch'
-usage = """%prog [options]
-
+help = 'Print the name of the top patch'
+usage = ['']
+description = """
 Print the name of the current (topmost) patch."""
 
+options = [
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default branch')]
+
 directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
 
 def func(parser, options, args):
     """Show the name of the topmost patch
index c21306b..19ec3c9 100644 (file)
@@ -17,15 +17,17 @@ along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
-from optparse import make_option
+from stgit.argparse import opt
 from stgit.commands import common
 from stgit.lib import transaction
 from stgit.out import *
 from stgit import utils
 
-help = 'turn regular GIT commits into StGIT patches'
-usage = """%prog [<patchnames>] | -n NUM [<prefix>]] | -t <committish> [-x]
-
+help = 'Turn regular git commits into StGit patches'
+usage = ['<patch-name-1> [<patch-name-2> ...]',
+         '-n NUM [<prefix>]',
+         '-t <committish> [-x]']
+description = """
 Take one or more git commits at the base of the current stack and turn
 them into StGIT patches. The new patches are created as applied patches
 at the bottom of the stack. This is the opposite of 'stg commit'.
@@ -46,14 +48,14 @@ given commit should be uncommitted.
 Only commits with exactly one parent can be uncommitted; in other
 words, you can't uncommit a merge."""
 
+options = [
+    opt('-n', '--number', type = 'int',
+        short = 'Uncommit the specified number of commits'),
+    opt('-t', '--to', short = 'Uncommit to the specified commit'),
+    opt('-x', '--exclusive', action = 'store_true',
+        short = 'Exclude the commit specified by the --to option')]
+
 directory = common.DirectoryHasRepositoryLib()
-options = [make_option('-n', '--number', type = 'int',
-                       help = 'uncommit the specified number of commits'),
-           make_option('-t', '--to',
-                       help = 'uncommit to the specified commit'),
-           make_option('-x', '--exclusive',
-                       help = 'exclude the commit specified by the --to option',
-                       action = 'store_true')]
 
 def func(parser, options, args):
     """Uncommit a number of patches.
index 665d664..6c624d0 100644 (file)
@@ -16,23 +16,23 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os
-from optparse import OptionParser, make_option
-
+from stgit.argparse import opt
 from stgit.commands.common import *
 from stgit.utils import *
 from stgit.out import *
 from stgit import stack, git
 
-
-help = 'unhide a hidden patch in the series'
-usage = """%prog [options] <patch-range>
-
+help = 'Unhide a hidden patch'
+usage = ['[options] <patch-range>']
+description = """
 Unhide a hidden range of patches so that they are shown in the plain
-'series' command output."""
+'stg series' command output."""
+
+options = [
+    opt('-b', '--branch',
+        short = 'Use BRANCH instead of the default branch')]
 
 directory = DirectoryHasRepository()
-options = [make_option('-b', '--branch',
-                       help = 'use BRANCH instead of the default one')]
 
 def func(parser, options, args):
     """Unhide a range of patches in the series
index a98fe49..55c467c 100644 (file)
@@ -19,11 +19,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 """
 
 import sys, os, traceback
-from optparse import OptionParser
 
 import stgit.commands
 from stgit.out import *
-from stgit import run, utils
+from stgit import argparse, run, utils
 
 #
 # The commands map
@@ -219,8 +218,7 @@ def _main():
 
             sys.argv[0] += ' %s' % cmd
             command = commands[cmd]
-            parser = OptionParser(usage = command.usage,
-                                  option_list = command.options)
+            parser = argparse.make_option_parser(command)
             from pydoc import pager
             pager(parser.format_help())
         else:
@@ -242,8 +240,7 @@ def _main():
     del(sys.argv[1])
 
     command = commands[cmd]
-    usage = command.usage.split('\n')[0].strip()
-    parser = OptionParser(usage = usage, option_list = command.options)
+    parser = argparse.make_option_parser(command)
     options, args = parser.parse_args()
     directory = command.directory