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