toolcontext: add --stub-man
authorJean Privat <jean@pryen.org>
Mon, 6 Oct 2014 12:48:32 +0000 (08:48 -0400)
committerJean Privat <jean@pryen.org>
Wed, 15 Oct 2014 19:00:53 +0000 (15:00 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/toolcontext.nit

index 33322d2..fd9ce98 100644 (file)
@@ -267,12 +267,15 @@ class ToolContext
        # Option --bash-completion
        var opt_bash_completion = new OptionBool("Generate bash_completion file for this program", "--bash-completion")
 
+       # Option --stub-man
+       var opt_stub_man = new OptionBool("Generate a stub manpage in pandoc markdown format", "--stub-man")
+
        # Verbose level
        var verbose_level: Int = 0
 
        init
        do
-               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)
+               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, opt_stub_man)
        end
 
        # Name, usage and synopsis of the tool.
@@ -323,6 +326,37 @@ class ToolContext
                        exit 0
                end
 
+               if opt_stub_man.value then
+                       print """
+% {{{toolname.to_upper}}}(1)
+
+# NAME
+
+{{{tooldescription.split("\n")[1]}}}
+
+# SYNOPSYS
+
+{{{toolname}}} [*options*]...
+
+# OPTIONS
+"""
+                       for o in option_context.options do
+                               var first = true
+                               for n in o.names do
+                                       if first then first = false else printn ", "
+                                       printn "`{n}`"
+                               end
+                               print ""
+                               print ":   {o.helptext}"
+                               print ""
+                       end
+                       print """
+# SEE ALSO
+
+The Nit language documentation and the source code of its tools and libraries may be downloaded from <http://nitlanguage.org>"""
+                       exit 0
+               end
+
                var errors = option_context.get_errors
                if not errors.is_empty then
                        for e in errors do print "Error: {e}"