JSDOC/Options.js
[gnome.introspection-doc-generator] / JSDOC / Options.js
1 //<script type="text/javascript">
2 /**
3  * Options management...
4  */
5 XObject = import.XObject.XObject;
6 File = import.File.File;
7
8 Options = {
9     
10     argTypes : {
11         "src"           :  "source directory (either absolute - starts with "/" or relative " + 
12                             "- without, in which case it's added to baseDir"
13         "baseDir"       :  'Base Directory (root directory of code)',
14         "target"        :  'Target Directory (where html files go)',
15         "cacheDirectory": 'Cached Files Directory',
16         "conf"          : 'Read From a Configuration file',       // was c. - configuration file.. - parsed with JSON.parse
17         "template"      : 'Template Directory',   // was t.
18         // "recurse": false,   // was r. - not supported..
19         "ext"           :  'Extension of code files to read (normally js)',   // was x.
20         "publishExt"    : 'Extension of html files to write (normally html)',
21         //"private": '',   // was p
22         //"allfunctions": '',   // was a
23         //"encoding": '',   // was e.
24         //"nocode": '',  // was n
25         //"out": '',   // was o.
26         //"suppress": '',  // was s ??? used?
27         "outputSource" : 'Output the Source code to symbols/src/* (boolean)',
28         //"testmode": '',  // was t
29         "help"          : 'Show help',   // was h
30         "verbose"       : 'Show verbose messages',   // was v
31         //"disablecache": '',   // was C -- not needed? - see if cacheDirectory was set..
32         //"define" : [],   // was D.
33         //"handler" : [],  // was H -- not supported..
34     }
35     
36     
37     "baseDir" :  '',  // base directory - 
38     "target" : '',   // was d. ?? source directory (needed to put temporary files..)
39     "cacheDirectory" : '',
40     "conf" : '',       // was c. - configuration file.. - parsed with JSON.parse
41     "template": '',   // was t.
42     // "recurse": false,   // was r. - not supported..
43     "ext": 'js',   // was x.
44     "publishExt" : 'html',
45     "private": '',   // was p
46     "allfunctions": '',   // was a
47     "encoding": '',   // was e.
48     "nocode": '',  // was n
49     "out": '',   // was o.
50     "suppress": '',  // was s ??? used?
51     "outputSource" : true,
52     "testmode": '',  // was t
53     "help": '',   // was h
54     "verbose": '',   // was v
55     "disablecache": '',   // was C
56     "define" : [],   // was D.
57     "handler" : [],  // was H -- not supported..
58     LOG : {
59         warn : function(str) {
60             print("Warn: " +str );
61         },
62         inform : function(str) {
63             print("Inform: " +str );
64         },
65         close : function() { },
66         flush : function() { },
67         out: false,
68         warnings : [],
69         verbose : false    
70     },
71     init : function()
72     {
73         this.LOG.verbose = this.verbose;
74         
75         
76         if (this.conf) {
77             XObject.extend(this, JSON.parse(File.read(this.conf)));;
78         }
79         // help ?? -- usage..
80         
81         if (!this.src.length) {
82             throw {
83                 name: "ArgumentError", 
84                 message: "No source directories specified" 
85             };
86         }
87         if (!this.template) {
88             throw {
89                 name: "ArgumentError", 
90                 message: "No template specified" 
91             };
92         }
93          
94         if (!this.target) {
95             throw {
96                 name: "ArgumentError", 
97                 message: "No directory specified" 
98             };
99         }
100         f (!this.baseDir) {
101             throw {
102                 name: "ArgumentError", 
103                 message: "No baseDir specified" 
104             };
105         }
106         
107         // should cacheDirectory be a subdirectory of target??
108         // if not set..
109         if (!this.cacheDirectory) {
110             throw {
111                 name: "ArgumentError", 
112                 message: "No cacheDirectory specified" 
113             };
114         }
115         
116     },
117     /** 
118      *  this might be nice as a standard bit of code..
119      */
120        
121     parseArgv : function() 
122     {
123         
124         var args = Array.prototype.slice.call(Seed.argv);
125         args.shift(); //seed
126         args.shift(); // pack.js
127         
128         
129         
130         
131         
132
133         for(var i =0; i < args.length;i++) {
134             if (!args[i].match(/\-\-[a-z+]$/)) {
135                 throw {
136                     name: "ArgumentError", 
137                     message: "Unknown argument: " + args[i] 
138                 };
139             }
140             var a = arg[i].substring(2);
141             if (typeof(argTypes[a]) == 'undefined') {
142                 throw {
143                     name: "ArgumentError", 
144                     message: "Unknown argument: " + args[i] 
145                 };
146             }
147             // type!!?!?
148             if (typeof(this[a]) == 'string') {
149                 this[a] = args[i+1];
150                 i++;
151                 continue;
152             }
153             if (typeof(this[a]) == 'boolean') {
154                 if (['false', 'true'].indexOf(args[i+1]) < 0) {
155                     throw {
156                         name: "ArgumentError", 
157                         message: "Unknown value for : " + args[i] + ' : ' +  args[i+1] 
158                     };
159                 }
160                 this[a] = args[i+1] == 'true';
161                 i++;
162                 continue;
163             }
164             
165     
166 }