Patchwork help: filter out deprecated options with untranslated descriptions

login
register
mail settings
Submitter Simon Heimberg
Date Feb. 17, 2014, 9:09 p.m.
Message ID <d4745c69913c70c0c7a4.1392671343@lapsi.heimberg.home>
Download mbox | patch
Permalink /patch/3686/
State Accepted
Commit 05267e6e94dd36461d9018743540506c65cabcf1
Headers show

Comments

Simon Heimberg - Feb. 17, 2014, 9:09 p.m.
# HG changeset patch
# User Simon Heimberg <simohe@besonet.ch>
# Date 1392619193 -3600
#      Mon Feb 17 07:39:53 2014 +0100
# Node ID d4745c69913c70c0c7a42e1cf974faf9afb50985
# Parent  0e2877f8605dcaf4fdf2ab7e0046f1f6f80161dd
help: filter out deprecated options with untranslated descriptions

When using a different language than English, deprecated options were only
removed from the output of `hg help anycmd` when "DEPRECATED" in the options
description was translated.
Mads Kiilerich - Feb. 22, 2014, 6:41 p.m.
On 02/17/2014 10:09 PM, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe@besonet.ch>
> # Date 1392619193 -3600
> #      Mon Feb 17 07:39:53 2014 +0100
> # Node ID d4745c69913c70c0c7a42e1cf974faf9afb50985
> # Parent  0e2877f8605dcaf4fdf2ab7e0046f1f6f80161dd
> help: filter out deprecated options with untranslated descriptions
>
> When using a different language than English, deprecated options were only
> removed from the output of `hg help anycmd` when "DEPRECATED" in the options
> description was translated.
>
> diff -r 0e2877f8605d -r d4745c69913c mercurial/help.py
> --- a/mercurial/help.py	Sat Feb 15 22:09:32 2014 -0600
> +++ b/mercurial/help.py	Mon Feb 17 07:39:53 2014 +0100
> @@ -38,7 +38,7 @@
>               shortopt, longopt, default, desc = option
>               optlabel = _("VALUE") # default label
>   
> -        if _("DEPRECATED") in desc and not verbose:
> +        if not verbose and ("DEPRECATED" in desc or _("DEPRECATED") in desc):

It seems a bit fragile to put semantics in having totally consistent 
translation of DEPRECATED. (And even more so to base the test on having 
it translated in the Swedish translation.)

BUT we do already check for the translated string elsewhere in help.py, 
so this is just making it consistent and not making it worse.

Another observation is that it is inconsistent whether the magic string 
is "DEPRECATED" or "(DEPRECATED)".

It seems like a better solution would be to only check for the magic 
word in the untranslated string - and either pass that or a flag around 
where it is needed. Alternatively, have a flag when defining an option 
and then add add the DEPRECATED string when relevant when the option 
description is shown to the user.

/Mads
Matt Mackall - March 14, 2014, 9:26 p.m.
On Mon, 2014-02-17 at 22:09 +0100, Simon Heimberg wrote:
> # HG changeset patch
> # User Simon Heimberg <simohe@besonet.ch>
> # Date 1392619193 -3600
> #      Mon Feb 17 07:39:53 2014 +0100
> # Node ID d4745c69913c70c0c7a42e1cf974faf9afb50985
> # Parent  0e2877f8605dcaf4fdf2ab7e0046f1f6f80161dd
> help: filter out deprecated options with untranslated descriptions

I've gone ahead and queued this for default, thanks.

Patch

diff -r 0e2877f8605d -r d4745c69913c mercurial/help.py
--- a/mercurial/help.py	Sat Feb 15 22:09:32 2014 -0600
+++ b/mercurial/help.py	Mon Feb 17 07:39:53 2014 +0100
@@ -38,7 +38,7 @@ 
             shortopt, longopt, default, desc = option
             optlabel = _("VALUE") # default label
 
-        if _("DEPRECATED") in desc and not verbose:
+        if not verbose and ("DEPRECATED" in desc or _("DEPRECATED") in desc):
             continue
 
         so = ''
diff -r 0e2877f8605d -r d4745c69913c tests/test-help.t
--- a/tests/test-help.t	Sat Feb 15 22:09:32 2014 -0600
+++ b/tests/test-help.t	Mon Feb 17 07:39:53 2014 +0100
@@ -569,6 +569,7 @@ 
   use "hg help" for the full list of commands or "hg -v" for details
   [255]
 
+
   $ cat > helpext.py <<EOF
   > import os
   > from mercurial import commands
@@ -578,6 +579,7 @@ 
   > 
   > cmdtable = {
   >     "nohelp": (nohelp, [], "hg nohelp"),
+  >     "debugoptDEP": (nohelp, [('', 'dopt', None, 'option is DEPRECATED')],),
   > }
   > 
   > commands.norepo += ' nohelp'
@@ -702,6 +704,33 @@ 
   
   use "hg -v help helpext" to show builtin aliases and global options
 
+
+test deprecated option is hidden in command help
+  $ hg help debugoptDEP
+  hg debugoptDEP
+  
+  (no help text available)
+  
+  options:
+  
+  use "hg -v help debugoptDEP" to show the global options
+
+test deprecated option is shown with -v
+  $ hg help -v debugoptDEP | grep dopt
+    --dopt option is DEPRECATED
+
+test deprecated option is hidden with translation with untranslated description
+(use many globy for not failing on changed transaction)
+  $ LANGUAGE=sv hg help debugoptDEP
+  hg debugoptDEP
+  
+  (*) (glob)
+  
+  flaggor:
+  
+  *"hg -v help debugoptDEP"* (glob)
+
+
 Test a help topic
 
   $ hg help revs