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