Merge: toolcontext: new option -w to enable/disable warning
authorJean Privat <jean@pryen.org>
Tue, 30 Sep 2014 10:51:52 +0000 (06:51 -0400)
committerJean Privat <jean@pryen.org>
Tue, 30 Sep 2014 10:51:52 +0000 (06:51 -0400)
The `-w` option takes the name of a warning (displayed at the end of message, between parentheses) to activate it; and "no-{name}" to disable it. It has precedence over -q and -W.

To show only missing-doc warnings in standard
~~~sh
$ nitg -q -w missing-doc standard
~~~

To show all warnings and advices, except missing-doc
~~~sh
$ nitg -W -w no-missing-doc standard
~~~

To show standard warnings except useless-type-test, but not advice except missing-doc
~~~sh
$ nitg -w missing-doc -w no-useless-type-test standard
~~~

Pull-Request: #790
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

src/toolcontext.nit
tests/sav/test_toolcontext_args1.res
tests/sav/test_toolcontext_args2.res

index 1bdcea5..64549ad 100644 (file)
@@ -161,7 +161,8 @@ class ToolContext
        # First-level warnings are displayed by default (except if option `-q` is given).
        fun warning(l: nullable Location, tag: String, text: String)
        do
-               if opt_warn.value == 0 then return
+               if opt_warning.value.has("no-{tag}") then return
+               if not opt_warning.value.has(tag) and opt_warn.value == 0 then return
                messages.add(new Message(l, tag, text))
                warning_count = warning_count + 1
                if opt_stop_on_first_error.value then check_errors
@@ -182,7 +183,8 @@ class ToolContext
        # default and require an additional option `-W`.
        fun advice(l: nullable Location, tag: String, text: String)
        do
-               if opt_warn.value <= 1 then return
+               if opt_warning.value.has("no-{tag}") then return
+               if not opt_warning.value.has(tag) and opt_warn.value <= 1 then return
                messages.add(new Message(l, tag, text))
                warning_count = warning_count + 1
                if opt_stop_on_first_error.value then check_errors
@@ -227,7 +229,10 @@ class ToolContext
        var option_context: OptionContext = new OptionContext
 
        # Option --warn
-       var opt_warn: OptionCount = new OptionCount("Show warnings", "-W", "--warn")
+       var opt_warn: OptionCount = new OptionCount("Show more warnings", "-W", "--warn")
+
+       # Option --warning
+       var opt_warning = new OptionArray("Show/hide a specific warning", "-w", "--warning")
 
        # Option --quiet
        var opt_quiet: OptionBool = new OptionBool("Do not show warnings", "-q", "--quiet")
@@ -264,7 +269,7 @@ class ToolContext
 
        init
        do
-               option_context.add_option(opt_warn, opt_quiet, opt_stop_on_first_error, opt_no_color, opt_log, opt_log_dir, opt_help, opt_version, opt_set_dummy_tool, opt_verbose, opt_bash_completion)
+               option_context.add_option(opt_warn, opt_warning, opt_quiet, opt_stop_on_first_error, opt_no_color, opt_log, opt_log_dir, opt_help, opt_version, opt_set_dummy_tool, opt_verbose, opt_bash_completion)
        end
 
        # Name, usage and synopsis of the tool.
index 3047835..5e997e3 100644 (file)
@@ -5,7 +5,7 @@ _DUMMY_TOOL()
        COMPREPLY=()
        cur="${COMP_WORDS[COMP_CWORD]}"
        prev="${COMP_WORDS[COMP_CWORD-1]}"
-       opts="--warn --quiet --stop-on-first-error --no-color --log --log-dir --help --version --set-dummy-tool --verbose --bash-completion --option-a --option-b"
+       opts="--warn --warning --quiet --stop-on-first-error --no-color --log --log-dir --help --version --set-dummy-tool --verbose --bash-completion --option-a --option-b"
        if [[ ${cur} == -* ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
                return 0
index 6d772d7..8757721 100644 (file)
@@ -1,6 +1,7 @@
 Usage: test_toolcontext [OPTION]...
 Test for ToolContext, try --bash-completion.
-  -W, --warn              Show warnings
+  -W, --warn              Show more warnings
+  -w, --warning           Show/hide a specific warning
   -q, --quiet             Do not show warnings
   --stop-on-first-error   Stop on first error
   --no-color              Do not use color to display errors and warnings