[latex3-commits] [git/LaTeX3-latex3-l3build] master: Allow help() to be auto-generated from list of targets (d0d7c32)

Joseph Wright joseph.wright at morningstar2.co.uk
Sun Jul 29 11:35:03 CEST 2018


Repository : https://github.com/latex3/l3build
On branch  : master
Link       : https://github.com/latex3/l3build/commit/d0d7c32804991fd322b8e5fdd21514b11f703a4e

>---------------------------------------------------------------

commit d0d7c32804991fd322b8e5fdd21514b11f703a4e
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Sun Jul 29 10:27:02 2018 +0100

    Allow help() to be auto-generated from list of targets
    
    Currently these are no-ops, but will soon be "activated".


>---------------------------------------------------------------

d0d7c32804991fd322b8e5fdd21514b11f703a4e
 l3build-help.lua    |   52 +++++++++++++++++++++++++--------------------------
 l3build-stdmain.lua |   44 +++++++++++++++++++++++++++++++++++++++++++
 l3build.lua         |   19 ++++++++++---------
 3 files changed, 79 insertions(+), 36 deletions(-)

diff --git a/l3build-help.lua b/l3build-help.lua
index 41c1df4..18caf87 100644
--- a/l3build-help.lua
+++ b/l3build-help.lua
@@ -36,6 +36,22 @@ function version()
 end
 
 function help()
+  local function setup_list(list)
+    local longest = 0
+    for k,v in pairs(list) do
+      if k:len() > longest then
+        longest = k:len()
+      end
+    end
+    -- Sort the options
+    local t = { }
+    for k,_ in pairs(list) do
+      insert(t, k)
+    end
+    sort(t)
+    return longest,t
+  end
+
   local scriptname = "l3build"
   if not match(arg[0], "l3build(%.lua)$") then
     scriptname = arg[0]
@@ -43,39 +59,21 @@ function help()
   print("usage: " .. scriptname .. " <command> [<options>] [<names>]")
   print("")
   print("The most commonly used l3build commands are:")
-  if testfiledir ~= "" then
-    print("   check      Run all automated tests")
-  end
-  print("   clean      Clean out directory tree")
-  if module == "" or bundle == "" then
-    print("   ctan       Create CTAN-ready archive")
-  end
-  print("   doc        Typesets all documentation files")
-  print("   install    Installs files into the local texmf tree")
-  if module ~= "" and testfiledir ~= "" then
-    print("   save       Saves test validation log")
+  local longest,t = setup_list(target_list)
+  for _,k in ipairs(t) do
+    local target = target_list[k]
+    local filler = rep(" ", longest - k:len() + 1)
+    if target["desc"] then
+      print("   " .. k .. filler .. target["desc"])
+    end
   end
-  print("   tag        Update release tags in files")
-  print("   uninstall  Uninstalls files from the local texmf tree")
-  print("   unpack     Unpacks the source files into the build tree")
   print("")
   print("Valid options are:")
-  local longest = 0
-  for k,v in pairs(option_list) do
-    if k:len() > longest then
-      longest = k:len()
-    end
-  end
-  -- Sort the options
-  local t = { }
-  for k,_ in pairs(option_list) do
-    insert(t, k)
-  end
-  sort(t)
+  local longest,t = setup_list(option_list)
   for _,k in ipairs(t) do
     local opt = option_list[k]
     local filler = rep(" ", longest - k:len() + 1)
-    if opt["desc"] then -- Skip --help as it has no desc
+    if opt["desc"] then
       if opt["short"] then
         print("   --" .. k .. "|-" .. opt["short"] .. filler .. opt["desc"])
       else
diff --git a/l3build-stdmain.lua b/l3build-stdmain.lua
index 4da72b7..26dbd5e 100644
--- a/l3build-stdmain.lua
+++ b/l3build-stdmain.lua
@@ -43,6 +43,50 @@ function listmodules()
   return modules
 end
 
+target_list =
+  {
+    check =
+      {
+        desc = "Run all automated tests"
+      },
+    clean =
+      {
+        desc = "Clean out directory tree"
+      },
+    ctan =
+      {
+        desc = "Create CTAN-ready archive"
+      },
+    doc =
+      {
+        desc = "Typesets all documentation files"
+      },
+    install =
+      {
+        desc = "Installs files into the local textmf tree"
+      },
+    manifest =
+      {
+        desc = "Creates a manifest file"
+      },
+    save =
+      {
+        desc = "Saves test validation log"
+      },
+    tag =
+      {
+        desc = "Updates release tags in files"
+      },
+    uninstall =
+      {
+        desc = "Uninstalls files from the local textmf tree"
+      },
+    unpack=
+      {
+        desc = "Unpacks the source files into the build tree"
+      }
+  }
+
 --
 -- The overall main function
 --
diff --git a/l3build.lua b/l3build.lua
index a3bb332..c5091ff 100755
--- a/l3build.lua
+++ b/l3build.lua
@@ -53,15 +53,6 @@ end
 build_require("arguments")
 build_require("help")
 
--- Filter out special cases early
-if options["target"] == "help" then
-  help()
-  exit(0)
-elseif options["target"] == "version" then
-  version()
-  exit(0)
-end
-
 build_require("file-functions")
 build_require("typesetting")
 build_require("aux")
@@ -75,6 +66,16 @@ build_require("manifest-setup")
 build_require("tagging")
 build_require("stdmain")
 
+-- This has to come after stdmain(),
+-- and that has to come after the functions are defined
+if options["target"] == "help" then
+  help()
+  exit(0)
+elseif options["target"] == "version" then
+  version()
+  exit(0)
+end
+
 -- Allow main function to be disabled 'higher up'
 main = main or stdmain
 





More information about the latex3-commits mailing list