doc.lua 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/usr/bin/env lua
  2. -------------------------------------------------------------------------------
  3. -- LuaDoc launcher.
  4. -- @release $Id: luadoc.lua.in,v 1.1 2008/02/17 06:42:51 jasonsantos Exp $
  5. -------------------------------------------------------------------------------
  6. --local source = debug.getinfo(1).source or ""
  7. --local mypath = source:match("@(.+)/[^/]+")
  8. --package.path = package.path .. ";" .. mypath .. "/?.lua;" .. mypath .. "/?/init.lua"
  9. require "luadoc.init"
  10. -------------------------------------------------------------------------------
  11. -- Print version number.
  12. local function print_version ()
  13. print (string.format("%s\n%s\n%s",
  14. luadoc._VERSION,
  15. luadoc._DESCRIPTION,
  16. luadoc._COPYRIGHT))
  17. end
  18. -------------------------------------------------------------------------------
  19. -- Print usage message.
  20. local function print_help ()
  21. print ("Usage: "..arg[0]..[[ [options|files]
  22. Generate documentation from files. Available options are:
  23. -d path output directory path
  24. -t path template directory path
  25. -h, --help print this help and exit
  26. --noindexpage do not generate global index page
  27. --nofiles do not generate documentation for files
  28. --nomodules do not generate documentation for modules
  29. --doclet doclet_module doclet module to generate output
  30. --taglet taglet_module taglet module to parse input code
  31. -q, --quiet suppress all normal output
  32. -v, --version print version information]])
  33. end
  34. local function off_messages (arg, i, options)
  35. options.verbose = nil
  36. end
  37. -------------------------------------------------------------------------------
  38. -- Process options. TODO: use getopts.
  39. -- @class table
  40. -- @name OPTIONS
  41. local OPTIONS = {
  42. d = function (arg, i, options)
  43. local dir = arg[i+1]
  44. if string.sub (dir, -2) ~= "/" then
  45. dir = dir..'/'
  46. end
  47. options.output_dir = dir
  48. return 1
  49. end,
  50. t = function (arg, i, options)
  51. local dir = arg[i+1]
  52. if string.sub (dir, -2) ~= "/" then
  53. dir = dir..'/'
  54. end
  55. options.template_dir = dir
  56. return 1
  57. end,
  58. h = print_help,
  59. help = print_help,
  60. q = off_messages,
  61. quiet = off_messages,
  62. v = print_version,
  63. version = print_version,
  64. doclet = function (arg, i, options)
  65. options.doclet = arg[i+1]
  66. return 1
  67. end,
  68. taglet = function (arg, i, options)
  69. options.taglet = arg[i+1]
  70. return 1
  71. end,
  72. }
  73. -------------------------------------------------------------------------------
  74. local function process_options (arg)
  75. local files = {}
  76. local options = require "luadoc.config"
  77. local i = 1
  78. while i <= #arg do
  79. local argi = arg[i]
  80. if string.sub (argi, 1, 1) ~= '-' then
  81. table.insert (files, argi)
  82. else
  83. local opt = string.sub (argi, 2)
  84. if string.sub (opt, 1, 1) == '-' then
  85. opt = string.gsub (opt, "%-", "")
  86. end
  87. if OPTIONS[opt] then
  88. if OPTIONS[opt] (arg, i, options) then
  89. i = i + 1
  90. end
  91. else
  92. options[opt] = 1
  93. end
  94. end
  95. i = i+1
  96. end
  97. return files, options
  98. end
  99. -------------------------------------------------------------------------------
  100. -- Main function. Process command-line parameters and call luadoc processor.
  101. function main (arg)
  102. -- Process options
  103. local argc = #arg
  104. if argc < 1 then
  105. print_help ()
  106. return
  107. end
  108. local files, options = process_options (arg)
  109. return luadoc.main(files, options)
  110. end
  111. main(arg)