[texdoc-commits] [SCM] texdoc updated: r16 - trunk/script

karl at gnu.org.ua karl at gnu.org.ua
Fri Oct 27 00:28:24 CEST 2017


Author: karl
Date: 2017-10-27 01:28:24 +0300 (Fri, 27 Oct 2017)
New Revision: 16

Modified:
   trunk/script/config.tlu
   trunk/script/main.tlu
Log:
* config.tlu (setup_config_from_cl): return action to take instead of boolean.
* main.tlu: change call.
(action_opts): no longer needed.
>From Reuben Thomas, http://puszcza.gnu.org.ua/bugs/?363.


Modified: trunk/script/config.tlu
===================================================================
--- trunk/script/config.tlu	2017-10-26 22:22:17 UTC (rev 15)
+++ trunk/script/config.tlu	2017-10-26 22:28:24 UTC (rev 16)
@@ -132,13 +132,24 @@
 -- and set a default value in setup_config_from_defaults() if relevant.
 function setup_config_from_cl(arg)
     local curr_arg
+    local action = true
     local function set_config_elt(key, val)
         set_config_element(key, val, {src='cl', name=curr_arg})
     end
     while arg[1] and string.match(arg[1],'^%-') do
         curr_arg = table.remove(arg,1)
+
+        -- action
+        if (curr_arg == '-h') or (curr_arg == '--help') then
+            action = 'help'
+        elseif (curr_arg == '-V') or (curr_arg == '--version') then
+            action = 'version'
+        elseif (curr_arg == '-f') or (curr_arg == '--files') then
+            action = 'files'
+        elseif curr_arg == '--just-view' then
+            action = 'view'
         -- mode
-        if (curr_arg == '-w') or (curr_arg == '--view') then
+        elseif (curr_arg == '-w') or (curr_arg == '--view') then
             set_config_elt('mode', 'view')
         elseif (curr_arg == '-m') or (curr_arg == '--mixed') then
             set_config_elt('mode', 'mixed')
@@ -175,7 +186,7 @@
             return false
         end
     end
-    return true
+    return action
 end
 
 -------------------------   config from environment   --------------------------

Modified: trunk/script/main.tlu
===================================================================
--- trunk/script/main.tlu	2017-10-26 22:22:17 UTC (rev 15)
+++ trunk/script/main.tlu	2017-10-26 22:28:24 UTC (rev 16)
@@ -10,31 +10,16 @@
 local exit_error = 1 -- apparently hard-coded in Lua
 local exit_usage = 2
 
--- action command-line options, not treated by setup_config_and_alias
+-- action command-line options
 local action_help = [[
   -h, --help            Print this help message.
   -V, --version         Print the version number.
   -f, --files           Print the list of configuration files used.
   --just-view file      Display file, given with full path (no searching).]]
-local action_opts = {
-    ['-h']          = 'help',
-    ['--help']      = 'help',
-    ['-V']          = 'version',
-    ['--version']   = 'version',
-    ['-f']          = 'files',
-    ['--files']     = 'files',
-    ['--just-view'] = 'view',
-}
 
--- detect action options, but do not act now (some need setup_config)
-local action
-if arg[1] then
-    action = action_opts[arg[1]]
-    if action then table.remove(arg, 1) end
-end
-
--- get configuration
-if not texdoc.setup_config_and_alias(arg) then
+-- get configuration and parse command line
+local action = texdoc.setup_config_and_alias(arg)
+if not action then
     os.exit(exit_usage)
 end
 
@@ -46,7 +31,7 @@
     print(texdoc.const.progname .. ' ' .. texdoc.const.version)
     print('\n' .. texdoc.const.copyright_msg)
     os.exit(exit_ok)
-elseif action =='files' then
+elseif action == 'files' then
     print(texdoc.const.fullname .. ' ' .. texdoc.const.version)
     texdoc.show_config_files(print, true)
     os.exit(exit_ok)



More information about the texdoc-commits mailing list