JSDOC/Walker2.js
[gnome.introspection-doc-generator] / JSDOC / Options.js
1 //<script type="text/javascript">
2 /**
3  * Options management...
4  */
5 XObject = imports.XObject.XObject;
6 File = imports.File.File;
7
8 Options = {
9
10     // generic stuff...
11     "--help"          : 'Show help',   // was h
12     "help": false,   // was h;se
13     
14     
15     // configurable settings.. - 
16     "usage" : "Usage seed jsdocbuild.js OPTIONS \n",
17     
18     
19     // options get defined like this..
20     "--src"           :  "source directory (either absolute - starts with "/" or relative " + 
21                         "- without, in which case it's added to baseDir",
22     "--exclude-src"       : 'Ex',   
23     "--baseDir"       :  'Base Directory (root directory of code)',
24     "--target"        :  'Target Directory (where html files go)',
25     "--cacheDirectory": 'Cached Files Directory',
26     "--conf"          : 'Read From a Configuration file',       // was c. - configuration file.. - parsed with JSON.parse
27     "--templateDir"      : 'Template Directory',   // was t.
28     // "recurse": false,   // was r. - not supported..
29     "--ext"           :  'Extension of code files to read (normally js)',   // was x.
30     "--publishExt"    : 'Extension of html files to write (normally html)',
31     //"private": '',   // was p
32     //"allfunctions": '',   // was a
33     //"encoding": '',   // was e.
34     //"nocode": '',  // was n
35     //"out": '',   // was o.
36     //"suppress": '',  // was s ??? used?
37     "--outputSource" : 'Output the Source code to symbols/src/* (boolean)',
38     //"testmode": '',  // was t
39     
40     "--verbose"       : 'Show verbose messages',   // was v
41     //"disablecache": '',   // was C -- not needed? - see if cacheDirectory was set..
42     //"define" : [],   // was D.
43     //"handler" : [],  // was H -- not supported..
44
45     
46     // and now the defaults.. (which type can be infered from..)
47     "src" : [],
48     "exclude-src" : [],
49     "baseDir" :  '',  // base directory - 
50     "target" : '',   // was d. ?? source directory (needed to put temporary files..)
51     "cacheDirectory" : '',
52     "conf" : '',       // was c. - configuration file.. - parsed with JSON.parse
53     "templateDir": '',   // was t.
54     // "recurse": false,   // was r. - not supported..
55     "ext": 'js',   // was x.
56     "publishExt" : 'html',
57     "private": '',   // was p
58     "allfunctions": '',   // was a
59     "encoding": '',   // was e.
60     "nocode": '',  // was n
61     "out": '',   // was o.
62     "suppress": '',  // was s ??? used?
63     "outputSource" : true,
64     "testmode": '',  // was t
65     
66     "verbose": '',   // was v
67     "disablecache": '',   // was C
68     "define" : [],   // was D.
69     "handler" : [],  // was H -- not supported..
70     
71     
72     "version" : "1.0",
73     "copyright" : "LGPL",
74     
75     LOG : {
76         warn : function(str) {
77             print("Warn: " +str );
78         },
79         inform : function(str) {
80             print("Inform: " +str );
81         },
82         close : function() { },
83         flush : function() { },
84         out: false,
85         warnings : [],
86         verbose : false    
87     },
88     init : function()
89     {
90         
91         if (this.help) {
92             this.showHelp();
93           
94         }
95         
96         // the reset of this is specific to JSDOC - and can not be moved to a generic handler..
97         
98          
99         this.LOG.verbose = this.verbose;
100         
101         if (!this.baseDir) { // should we set this to cwd?
102             throw {
103                 name: "ArgumentError", 
104                 message: "No baseDir specified" 
105             };
106         }
107         
108         // this is most likely to come from the command line..
109         if (this.conf) {
110             var conf = this.conf[0] == '/' ? this.conf : this.baseDir + '/' + this.conf;
111         
112             XObject.extend(this, JSON.parse(File.read(conf)));;
113         }
114         // help ?? -- usage..
115        
116         if (!this.src.length) {
117             throw {
118                 name: "ArgumentError", 
119                 message: "No source directories specified" 
120             };
121         }
122         // append full path to source directories.
123         var _this= this;
124         var src = this.src;
125         this.src = [];
126         src.forEach(function(v, i) {
127             if (!v.length || v[0] != '/') {
128                 v = _this.baseDir + (v.length ?  '/' + v : '');
129             }
130             if (!File.isDirectory(v)) {
131                 throw {
132                     name: "ArgumentError", 
133                     message: "invalid Source Directory : " +  v
134                 };
135             }
136             _this.src.push(v);
137         });
138         
139         
140         if (!this.templateDir) {
141             throw {
142                 name: "ArgumentError", 
143                 message: "No templateDir Directory specified" 
144             };
145         }
146         if (this.templateDir[0] !='/') {
147             this.templateDir = this.baseDir + '/' + this.templateDir;
148         }
149         
150         
151         if (!this.target) {
152             throw {
153                 name: "ArgumentError", 
154                 message: "No directory specified" 
155             };
156         }
157       
158         
159         // should cacheDirectory be a subdirectory of target??
160         // if not set..
161         //if (!this.cacheDirectory) {
162         //    throw {
163         //        name: "ArgumentError", 
164         //        message: "No cacheDirectory specified" 
165         //    };
166         // }
167         
168     },
169     /** 
170      *  this might be nice as a standard bit of code..
171      */
172        
173     parseArgv : function() 
174     {
175         
176         var args = Array.prototype.slice.call(Seed.argv);
177         args.shift(); //seed
178         args.shift(); // pack.js
179         
180         for(var i =0; i < args.length;i++) {
181             if (args[i].substring(0,2) != '--') {
182                 
183                 throw {
184                     name: "ArgumentError", 
185                     message: "Unknown argument: " + args[i] 
186                 };
187             }
188             var a = args[i].substring(2);
189             if (typeof(this[args[i]]) == 'undefined') {
190                 throw {
191                     name: "ArgumentError", 
192                     message: "Unknown argument: " + args[i] 
193                 };
194             }
195             // type!!?!?
196             if (typeof(this[a]) == 'string') {
197                 this[a] = args[i+1];
198                 i++;
199                 continue;
200             }
201             if (typeof(this[a]) == 'boolean') {
202                 if (['false', 'true'].indexOf(args[i+1]) < 0) {
203                     throw {
204                         name: "ArgumentError", 
205                         message: "Unknown value for : " + args[i] + ' : ' +  args[i+1] 
206                     };
207                 }
208                 this[a] = args[i+1] == 'true';
209                 i++;
210                 continue;
211             }
212             if (typeof(this[a]) == 'object') { // tecnically an array.
213                 i++;
214                 while(i < args.length)
215                 {
216                     if (args[i].substring(0,2) != '--'){
217                         
218                         break;
219                     }
220                     this[a].push(args[i]);
221                 }
222                 i--;
223             }
224             throw {
225                 name: "ArgumentError", 
226                 message: "Do not know how to handle: " + a
227             };  
228         }
229         
230         
231     },
232     
233     
234     showHelp: function()
235     {
236         print(this.usage);
237         for(var i in this) {
238             if (i.substring(0,2) != '--') {
239                 continue;
240             }
241             print( i + '  ARG  : ' + this[i]);
242             throw "DONE";
243         }
244     }
245 }