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