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