improve "usage" strings to include optional "--"
[stgit] / stgit / commands / status.py
index b2835ab..8ea6526 100644 (file)
@@ -17,16 +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 import stack, git
-
-
-help = 'show the tree status'
-usage = """%prog [options] [<files...>]
+from stgit import argparse, stack, git
 
+help = 'Show the tree status'
+kind = 'wc'
+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,43 +36,34 @@ 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."""
-
-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('-O', '--diff-opts',
-                       help = 'options to pass to git-diff'),
-           make_option('--reset',
-                       help = 'reset the current tree changes',
-                       action = 'store_true')]
-
-
-def status(files = None, modified = False, new = False, deleted = False,
-           conflict = False, unknown = False, noexclude = False,
-           diff_flags = []):
+An 'stg refresh' command clears the status of the modified, new and
+deleted files."""
+
+args = [argparse.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, log = False)
+
+def status(files, modified, new, deleted, conflict, unknown, noexclude):
     """Show the tree status
     """
     cache_files = git.tree_status(files,
-                                  unknown = (files == None),
-                                  noexclude = noexclude,
-                                  diff_flags = diff_flags)
+                                  unknown = (not files),
+                                  noexclude = noexclude)
     filtered = (modified or new or deleted or conflict or unknown)
 
     if filtered:
@@ -93,7 +83,6 @@ def status(files = None, modified = False, new = False, deleted = False,
 
     output = []
     for st, fn in cache_files:
-        assert files == None or fn in files
         if filtered:
             output.append(fn)
         else:
@@ -104,23 +93,18 @@ def status(files = None, modified = False, new = False, deleted = False,
 def func(parser, options, args):
     """Show the tree status
     """
+    args = git.ls_files(args)
+    directory.cd_to_topdir()
+
     if options.reset:
+        directory.log = True
         if args:
-            for f in args:
-                resolved(f)
+            conflicts = git.get_conflicts()
+            git.resolved([fn for fn in args if fn in conflicts])
             git.reset(args)
         else:
             resolved_all()
             git.reset()
     else:
-        if options.diff_opts:
-            diff_flags = options.diff_opts.split()
-        else:
-            diff_flags = []
-
-        # No args means all files
-        if not args:
-            args = None
         status(args, options.modified, options.new, options.deleted,
-               options.conflict, options.unknown, options.noexclude,
-               diff_flags = diff_flags)
+               options.conflict, options.unknown, options.noexclude)