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             if (File.isDirectory(this.src[i])) {
109                 throw {
110                     name: "ArgumentError", 
111                     message: "invalid Source Directory : " +  v;
112                 };
113             }
114         }
115         
116         
117         if (!this.template) {
118             throw {
119                 name: "ArgumentError", 
120                 message: "No template Directory specified" 
121             };
122         }
123          
124         if (!this.target) {
125             throw {
126                 name: "ArgumentError", 
127                 message: "No directory specified" 
128             };
129         }
130       
131         
132         // should cacheDirectory be a subdirectory of target??
133         // if not set..
134         //if (!this.cacheDirectory) {
135         //    throw {
136         //        name: "ArgumentError", 
137         //        message: "No cacheDirectory specified" 
138         //    };
139         // }
140         
141     },
142     /** 
143      *  this might be nice as a standard bit of code..
144      */
145        
146     parseArgv : function() 
147     {
148         
149         var args = Array.prototype.slice.call(Seed.argv);
150         args.shift(); //seed
151         args.shift(); // pack.js
152         
153         for(var i =0; i < args.length;i++) {
154             if (args[i].substring(0,2) != '--') {
155                 
156                 throw {
157                     name: "ArgumentError", 
158                     message: "Unknown argument: " + args[i] 
159                 };
160             }
161             var a = arg[i].substring(2);
162             if (typeof(argTypes[arg[i]]) == 'undefined') {
163                 throw {
164                     name: "ArgumentError", 
165                     message: "Unknown argument: " + args[i] 
166                 };
167             }
168             // type!!?!?
169             if (typeof(this[a]) == 'string') {
170                 this[a] = args[i+1];
171                 i++;
172                 continue;
173             }
174             if (typeof(this[a]) == 'boolean') {
175                 if (['false', 'true'].indexOf(args[i+1]) < 0) {
176                     throw {
177                         name: "ArgumentError", 
178                         message: "Unknown value for : " + args[i] + ' : ' +  args[i+1] 
179                     };
180                 }
181                 this[a] = args[i+1] == 'true';
182                 i++;
183                 continue;
184             }
185             if (typeof(this[a]) == 'object') { // tecnically an array.
186                 i++;
187                 while(i < args.length)
188                 {
189                     if (args[i].substring(0,2) != '--'){
190                         
191                         break;
192                     }
193                     this[a].push(args[i]);
194                 }
195                 i--;
196             }
197             throw {
198                 name: "ArgumentError", 
199                 message: "Do not know how to handle: " + a
200             };  
201         }
202         
203         
204     },
205     
206     
207     function showHelp()
208     {
209         print ("Usage: ");
210         for(var i in this) {
211             if (i.substring(0,2) != '--') {
212                 continue;
213             }
214             print( i + '  ARG  : ' + this[i]);
215             throw "DONE";
216         }
217     }
218 }