reset to working status
[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     LOG : {
71         warn : function(str) {
72             print("Warn: " +str );
73         },
74         inform : function(str) {
75             print("Inform: " +str );
76         },
77         close : function() { },
78         flush : function() { },
79         out: false,
80         warnings : [],
81         verbose : false    
82     },
83     init : function()
84     {
85         
86         if (this.help) {
87             this.showHelp();
88           
89         }
90         
91         // the reset of this is specific to JSDOC - and can not be moved to a generic handler..
92         
93          
94         this.LOG.verbose = this.verbose;
95         
96         if (!this.baseDir) { // should we set this to cwd?
97             throw {
98                 name: "ArgumentError", 
99                 message: "No baseDir specified" 
100             };
101         }
102         
103         // this is most likely to come from the command line..
104         if (this.conf) {
105             var conf = this.conf[0] == '/' ? this.conf : this.baseDir + '/' + this.conf;
106         
107             XObject.extend(this, JSON.parse(File.read(conf)));;
108         }
109         // help ?? -- usage..
110        
111         if (!this.src.length) {
112             throw {
113                 name: "ArgumentError", 
114                 message: "No source directories specified" 
115             };
116         }
117         // append full path to source directories.
118         var _this= this;
119         var src = this.src;
120         this.src = [];
121         src.forEach(function(v, i) {
122             if (!v.length || v[0] != '/') {
123                 v = _this.baseDir + (v.length ?  '/' + v : '');
124             }
125             if (!File.isDirectory(v)) {
126                 throw {
127                     name: "ArgumentError", 
128                     message: "invalid Source Directory : " +  v
129                 };
130             }
131             _this.src.push(v);
132         });
133         
134         
135         if (!this.templateDir) {
136             throw {
137                 name: "ArgumentError", 
138                 message: "No templateDir Directory specified" 
139             };
140         }
141         if (this.templateDir[0] !='/') {
142             this.templateDir = this.baseDir + '/' + this.templateDir;
143         }
144         
145         
146         if (!this.target) {
147             throw {
148                 name: "ArgumentError", 
149                 message: "No directory specified" 
150             };
151         }
152       
153         
154         // should cacheDirectory be a subdirectory of target??
155         // if not set..
156         //if (!this.cacheDirectory) {
157         //    throw {
158         //        name: "ArgumentError", 
159         //        message: "No cacheDirectory specified" 
160         //    };
161         // }
162         
163     },
164     /** 
165      *  this might be nice as a standard bit of code..
166      */
167        
168     parseArgv : function() 
169     {
170         
171         var args = Array.prototype.slice.call(Seed.argv);
172         args.shift(); //seed
173         args.shift(); // pack.js
174         
175         for(var i =0; i < args.length;i++) {
176             if (args[i].substring(0,2) != '--') {
177                 
178                 throw {
179                     name: "ArgumentError", 
180                     message: "Unknown argument: " + args[i] 
181                 };
182             }
183             var a = args[i].substring(2);
184             if (typeof(this[args[i]]) == 'undefined') {
185                 throw {
186                     name: "ArgumentError", 
187                     message: "Unknown argument: " + args[i] 
188                 };
189             }
190             // type!!?!?
191             if (typeof(this[a]) == 'string') {
192                 this[a] = args[i+1];
193                 i++;
194                 continue;
195             }
196             if (typeof(this[a]) == 'boolean') {
197                 if (['false', 'true'].indexOf(args[i+1]) < 0) {
198                     throw {
199                         name: "ArgumentError", 
200                         message: "Unknown value for : " + args[i] + ' : ' +  args[i+1] 
201                     };
202                 }
203                 this[a] = args[i+1] == 'true';
204                 i++;
205                 continue;
206             }
207             if (typeof(this[a]) == 'object') { // tecnically an array.
208                 i++;
209                 while(i < args.length)
210                 {
211                     if (args[i].substring(0,2) != '--'){
212                         
213                         break;
214                     }
215                     this[a].push(args[i]);
216                 }
217                 i--;
218             }
219             throw {
220                 name: "ArgumentError", 
221                 message: "Do not know how to handle: " + a
222             };  
223         }
224         
225         
226     },
227     
228     
229     showHelp: function()
230     {
231         print(this.usage);
232         for(var i in this) {
233             if (i.substring(0,2) != '--') {
234                 continue;
235             }
236             print( i + '  ARG  : ' + this[i]);
237             throw "DONE";
238         }
239     }
240 }