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