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     // options get defined like this..
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     // and now the defaults.. (which type can be infered from..)
37     "src" : [],
38     "baseDir" :  '',  // base directory - 
39     "target" : '',   // was d. ?? source directory (needed to put temporary files..)
40     "cacheDirectory" : '',
41     "conf" : '',       // was c. - configuration file.. - parsed with JSON.parse
42     "template": '',   // was t.
43     // "recurse": false,   // was r. - not supported..
44     "ext": 'js',   // was x.
45     "publishExt" : 'html',
46     "private": '',   // was p
47     "allfunctions": '',   // was a
48     "encoding": '',   // was e.
49     "nocode": '',  // was n
50     "out": '',   // was o.
51     "suppress": '',  // was s ??? used?
52     "outputSource" : true,
53     "testmode": '',  // was t
54     "help": false,   // was h;se
55     "verbose": '',   // was v
56     "disablecache": '',   // was C
57     "define" : [],   // was D.
58     "handler" : [],  // was H -- not supported..
59     LOG : {
60         warn : function(str) {
61             print("Warn: " +str );
62         },
63         inform : function(str) {
64             print("Inform: " +str );
65         },
66         close : function() { },
67         flush : function() { },
68         out: false,
69         warnings : [],
70         verbose : false    
71     },
72     init : function()
73     {
74         
75         if (this.help) {
76             this.showHelp();
77           
78         }
79         
80         // the reset of this is specific to JSDOC - and can not be moved to a generic handler..
81         
82          
83         this.LOG.verbose = this.verbose;
84         
85         // this is most likely to come from the command line..
86         if (this.conf) {
87             XObject.extend(this, JSON.parse(File.read(this.conf)));;
88         }
89         // help ?? -- usage..
90         if (!this.baseDir) {
91             throw {
92                 name: "ArgumentError", 
93                 message: "No baseDir specified" 
94             };
95         }
96         if (!this.src.length) {
97             throw {
98                 name: "ArgumentError", 
99                 message: "No source directories specified" 
100             };
101         }
102         // append full path to source directories.
103         var _this= this;
104         this.src.forEach(function(v, i) {
105             if (v[0] != '/') {
106                 this.src[i] = _this.baseDir + '/' + v;
107             }
108         }
109         
110         
111         if (!this.template) {
112             throw {
113                 name: "ArgumentError", 
114                 message: "No template specified" 
115             };
116         }
117          
118         if (!this.target) {
119             throw {
120                 name: "ArgumentError", 
121                 message: "No directory specified" 
122             };
123         }
124       
125         
126         // should cacheDirectory be a subdirectory of target??
127         // if not set..
128         if (!this.cacheDirectory) {
129             throw {
130                 name: "ArgumentError", 
131                 message: "No cacheDirectory specified" 
132             };
133         }
134         
135     },
136     /** 
137      *  this might be nice as a standard bit of code..
138      */
139        
140     parseArgv : function() 
141     {
142         
143         var args = Array.prototype.slice.call(Seed.argv);
144         args.shift(); //seed
145         args.shift(); // pack.js
146         
147         for(var i =0; i < args.length;i++) {
148             if (args[i].substring(0,2) != '--') {
149                 
150                 throw {
151                     name: "ArgumentError", 
152                     message: "Unknown argument: " + args[i] 
153                 };
154             }
155             var a = arg[i].substring(2);
156             if (typeof(argTypes[arg[i]]) == 'undefined') {
157                 throw {
158                     name: "ArgumentError", 
159                     message: "Unknown argument: " + args[i] 
160                 };
161             }
162             // type!!?!?
163             if (typeof(this[a]) == 'string') {
164                 this[a] = args[i+1];
165                 i++;
166                 continue;
167             }
168             if (typeof(this[a]) == 'boolean') {
169                 if (['false', 'true'].indexOf(args[i+1]) < 0) {
170                     throw {
171                         name: "ArgumentError", 
172                         message: "Unknown value for : " + args[i] + ' : ' +  args[i+1] 
173                     };
174                 }
175                 this[a] = args[i+1] == 'true';
176                 i++;
177                 continue;
178             }
179             if (typeof(this[a]) == 'object') { // tecnically an array.
180                 i++;
181                 while(i < args.length)
182                 {
183                     if (args[i].substring(0,2) != '--'){
184                         
185                         break;
186                     }
187                     this[a].push(args[i]);
188                 }
189                 i--;
190             }
191             throw {
192                 name: "ArgumentError", 
193                 message: "Do not know how to handle: " + a
194             };  
195         }
196         
197         
198     },
199     
200     
201     function showHelp()
202     {
203         print ("Usage: ");
204         for(var i in this) {
205             if (i.substring(0,2) != '--') {
206                 continue;
207             }
208             print( i + '  ARG  : ' + this[i]);
209             throw "DONE";
210         }
211     }
212 }