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