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