Patchwork help: exclude debug commands

login
register
mail settings
Submitter timeless@mozdev.org
Date Oct. 16, 2015, 6:51 p.m.
Message ID <c90f848222a9acd1ecf6.1445021489@waste.org>
Download mbox | patch
Permalink /patch/11149/
State Deferred
Headers show

Comments

timeless@mozdev.org - Oct. 16, 2015, 6:51 p.m.
# HG changeset patch
# User timeless <timeless@mozdev.org>
# Date 1444979541 14400
#      Fri Oct 16 03:12:21 2015 -0400
# Node ID c90f848222a9acd1ecf6f5b9273cf7b7ef727ef7
# Parent  e8f1b728591786143174515ea18089db0df4af90
help: exclude debug commands
Gilles Moris - Oct. 17, 2015, 7:31 a.m.
Le 16/10/2015 20:51, timeless a écrit :
> help: exclude debug commands
>
> diff --git a/mercurial/help.py b/mercurial/help.py
> --- a/mercurial/help.py
> +++ b/mercurial/help.py
> @@ -105,6 +105,8 @@
>               results['topics'].append((names[0], header))
>       import commands # avoid cycle
>       for cmd, entry in commands.table.iteritems():
> +        if not ui.verbose and cmd.startswith('debug'):
Or should we look at the debug flag instead to display

> +            continue
>           if len(entry) == 3:
>               summary = entry[2]
>           else:
> @@ -123,10 +125,14 @@
>           # extensions.load ignores the UI argument
>           mod = extensions.load(None, name, '')
>           name = name.split('.')[-1]
> +        if not ui.verbose and name.startswith('debug'):
> +            continue
>           if lowercontains(name) or lowercontains(docs):
>               # extension docs are already translated
>               results['extensions'].append((name, docs.splitlines()[0]))
>           for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
> +            if not ui.verbose and cmd.startswith('debug'):
> +                continue
timeless - Oct. 18, 2015, 2:43 p.m.
The debug flag turns on verbose, I don't really care which we use. If
someone has a preference, they can change in flight.

I should probably factor the filtering into a function...
On Oct 17, 2015 3:32 AM, "Gilles Moris" <gilles.moris@free.fr> wrote:

>
>
> Le 16/10/2015 20:51, timeless a écrit :
>
>> help: exclude debug commands
>>
>> diff --git a/mercurial/help.py b/mercurial/help.py
>> --- a/mercurial/help.py
>> +++ b/mercurial/help.py
>> @@ -105,6 +105,8 @@
>>               results['topics'].append((names[0], header))
>>       import commands # avoid cycle
>>       for cmd, entry in commands.table.iteritems():
>> +        if not ui.verbose and cmd.startswith('debug'):
>>
> Or should we look at the debug flag instead to display
>
> +            continue
>>           if len(entry) == 3:
>>               summary = entry[2]
>>           else:
>> @@ -123,10 +125,14 @@
>>           # extensions.load ignores the UI argument
>>           mod = extensions.load(None, name, '')
>>           name = name.split('.')[-1]
>> +        if not ui.verbose and name.startswith('debug'):
>> +            continue
>>           if lowercontains(name) or lowercontains(docs):
>>               # extension docs are already translated
>>               results['extensions'].append((name, docs.splitlines()[0]))
>>           for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
>> +            if not ui.verbose and cmd.startswith('debug'):
>> +                continue
>>
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> https://selenic.com/mailman/listinfo/mercurial-devel
>
Matt Mackall - Oct. 18, 2015, 11:15 p.m.
On Fri, 2015-10-16 at 13:51 -0500, timeless wrote:
> # HG changeset patch
> # User timeless <timeless@mozdev.org>
> # Date 1444979541 14400
> #      Fri Oct 16 03:12:21 2015 -0400
> # Node ID c90f848222a9acd1ecf6f5b9273cf7b7ef727ef7
> # Parent  e8f1b728591786143174515ea18089db0df4af90
> help: exclude debug commands

..from keyword search, apparently.

Don't know that I'm convinced it's a good idea to hide these here.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/help.py b/mercurial/help.py
--- a/mercurial/help.py
+++ b/mercurial/help.py
@@ -105,6 +105,8 @@ 
             results['topics'].append((names[0], header))
     import commands # avoid cycle
     for cmd, entry in commands.table.iteritems():
+        if not ui.verbose and cmd.startswith('debug'):
+            continue
         if len(entry) == 3:
             summary = entry[2]
         else:
@@ -123,10 +125,14 @@ 
         # extensions.load ignores the UI argument
         mod = extensions.load(None, name, '')
         name = name.split('.')[-1]
+        if not ui.verbose and name.startswith('debug'):
+            continue
         if lowercontains(name) or lowercontains(docs):
             # extension docs are already translated
             results['extensions'].append((name, docs.splitlines()[0]))
         for cmd, entry in getattr(mod, 'cmdtable', {}).iteritems():
+            if not ui.verbose and cmd.startswith('debug'):
+                continue
             if kw in cmd or (len(entry) > 2 and lowercontains(entry[2])):
                 cmdname = cmd.split('|')[0].lstrip('^')
                 if entry[0].__doc__:
@@ -483,7 +489,19 @@ 
     rst = []
     kw = opts.get('keyword')
     if kw:
+        def hasmatches(m):
+            for l in m.values():
+                if l:
+                    return True
+            return False
         matches = topicmatch(ui, name)
+        debughidden = False
+        if not ui.verbose and not hasmatches(matches):
+            ui.verbose = True
+            try:
+                debughidden = hasmatches(topicmatch(ui, name))
+            finally:
+                ui.verbose = False
         helpareas = []
         if opts.get('extension'):
             helpareas += [('extensions', _('Extensions'))]
@@ -501,7 +519,12 @@ 
                 rst.append('\n')
         if not rst:
             msg = _('no matches')
-            hint = _('try "hg help" for a list of topics')
+            if debughidden:
+                args = ['--%s' % a for a in opts.keys() if opts[a]]
+                args = ' '.join(args+[repr(name)])
+                hint = _('try "hg help -v %s"') % args
+            else:
+                hint = _('try "hg help" for a list of topics')
             raise error.Abort(msg, hint=hint)
     elif name and name != 'shortlist':
         queries = []
diff --git a/tests/test-help.t b/tests/test-help.t
--- a/tests/test-help.t
+++ b/tests/test-help.t
@@ -1043,6 +1043,12 @@ 
   abort: no such help topic: commit
   (try "hg help --keyword commit")
   [255]
+  $ hg help -k 'find the ancestor revision' |grep debugancestor
+  abort: no matches
+  (try "hg help -v --keyword 'find the ancestor revision'")
+  [1]
+  $ hg help -v -k 'find the ancestor revision' |grep debugancestor
+   debugancestor find the ancestor revision of two revisions in a given index
 
 Test keyword search help