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