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     argTypes : {
11         "src"           :  'source directory'
12         "baseDir"       :  'Base Directory (root directory of code)',
13         "target"        :  'Target Directory (where html files go)',
14         "cacheDirectory": 'Cached Files Directory',
15         "conf"          : 'Read From a Configuration file',       // was c. - configuration file.. - parsed with JSON.parse
16         "template"      : 'Template Directory',   // was t.
17         // "recurse": false,   // was r. - not supported..
18         "ext"           :  'Extension of code files to read (normally js)',   // was x.
19         "publishExt"    : 'Extension of html files to write (normally html)',
20         //"private": '',   // was p
21         //"allfunctions": '',   // was a
22         //"encoding": '',   // was e.
23         //"nocode": '',  // was n
24         //"out": '',   // was o.
25         //"suppress": '',  // was s ??? used?
26         "outputSource" : 'Output the Source code to symbols/src/* (boolean)',
27         //"testmode": '',  // was t
28         "help"          : 'Show help',   // was h
29         "verbose"       : 'Show verbose messages',   // was v
30         //"disablecache": '',   // was C -- not needed? - see if cacheDirectory was set..
31         //"define" : [],   // was D.
32         //"handler" : [],  // was H -- not supported..
33     }
34     
35     
36     "baseDir" :  '',  // base directory - 
37     "target" : '',   // was d. ?? source directory (needed to put temporary files..)
38     "cacheDirectory" : '',
39     "conf" : '',       // was c. - configuration file.. - parsed with JSON.parse
40     "template": '',   // was t.
41     // "recurse": false,   // was r. - not supported..
42     "ext": 'js',   // was x.
43     "publishExt" : 'html',
44     "private": '',   // was p
45     "allfunctions": '',   // was a
46     "encoding": '',   // was e.
47     "nocode": '',  // was n
48     "out": '',   // was o.
49     "suppress": '',  // was s ??? used?
50     "outputSource" : true,
51     "testmode": '',  // was t
52     "help": '',   // was h
53     "verbose": '',   // was v
54     "disablecache": '',   // was C
55     "define" : [],   // was D.
56     "handler" : [],  // was H -- not supported..
57     LOG : {
58         warn : function(str) {
59             print("Warn: " +str );
60         },
61         inform : function(str) {
62             print("Inform: " +str );
63         },
64         close : function() { },
65         flush : function() { },
66         out: false,
67         warnings : [],
68         verbose : false    
69     },
70     init : function()
71     {
72         this.LOG.verbose = this.verbose;
73         
74         
75         if (this.conf) {
76             XObject.extend(this, JSON.parse(File.read(this.conf)));;
77         }
78         // help ?? -- usage..
79         
80         if (!this.src.length) {
81             throw {
82                 name: "ArgumentError", 
83                 message: "No source directories specified" 
84             };
85         }
86         if (!this.template) {
87             throw {
88                 name: "ArgumentError", 
89                 message: "No template specified" 
90             };
91         }
92          
93         if (!this.target) {
94             throw {
95                 name: "ArgumentError", 
96                 message: "No directory specified" 
97             };
98         }
99         f (!this.baseDir) {
100             throw {
101                 name: "ArgumentError", 
102                 message: "No baseDir specified" 
103             };
104         }
105         
106         // should cacheDirectory be a subdirectory of target??
107         // if not set..
108         if (!this.cacheDirectory) {
109             throw {
110                 name: "ArgumentError", 
111                 message: "No cacheDirectory specified" 
112             };
113         }
114         
115     },
116     /** 
117      *  this might be nice as a standard bit of code..
118      */
119        
120     parseArgv : function() 
121     {
122         
123         var args = Array.prototype.slice.call(Seed.argv);
124         args.shift(); //seed
125         args.shift(); // pack.js
126         
127         
128         
129         
130         
131
132         for(var i =0; i < args.length;i++) {
133             if (!args[i].match(/\-\-[a-z+]$/)) {
134                 throw {
135                     name: "ArgumentError", 
136                     message: "Unknown argument: " + args[i] 
137                 };
138             }
139             var a = arg[i].substring(2);
140             if (typeof(argTypes[a]) == 'undefined') {
141                 throw {
142                     name: "ArgumentError", 
143                     message: "Unknown argument: " + args[i] 
144                 };
145             }
146             // type!!?!?
147             if (typeof(this[a]) == 'string') {
148                 this[a] = args[i+1];
149                 i++;
150                 continue;
151             }
152             if (typeof(this[a]) == 'boolean') {
153                 if (['false', 'true'].indexOf(args[i+1]) < 0) {
154                     throw {
155                         name: "ArgumentError", 
156                         message: "Unknown value for : " + args[i] + ' : ' +  args[i+1] 
157                     };
158                 }
159                 this[a] = args[i+1] == 'true';
160                 i++;
161                 continue;
162             }
163             
164     
165 }