JSDOC/PackerRun.vala
[gnome.introspection-doc-generator] / JSDOC / PackerRun.vala
1
2 /** 
3   the application
4   -- in theory this code  can be used as a library... but this is the standard command line version...
5 */
6
7 namespace JSDOC
8 {
9         // --------------- <<<<<<< <MAIN HERE....
10         
11
12         class PackerRun : Application  
13         {
14                 public static string opt_target = "";
15                 public static string opt_debug_target = "";
16                 public static string opt_tmpdir = "";
17                 
18                 
19                 private static string[]? opt_files = null;
20                 private static string[]? opt_files_from = null;
21                 public static bool opt_debug = false;
22                 
23
24                 
25                 const OptionEntry[] options = {
26                 
27                         { "jsfile", 'f', 0, OptionArg.FILENAME_ARRAY, ref opt_files ,"add a file to compile", null },
28                 //      { "target", 't', 0, OptionArg.STRING, ref opt_target, "Target File to write (eg. roojs.js)", null },
29                 //      { "debug-target", 'T', 0, OptionArg.STRING, ref opt_debug_target, "Target File to write debug code (eg. roojs-debug.js)", null },
30         //              { "tmpdir", 'm', 0, OptionArg.STRING, ref opt_tmpdir, "Temporary Directory to use", null },
31
32 //                      { "index-files", 'i', 0, OptionArg.FILENAME_ARRAY, ref opt_files_from ,"files that contain listing of files to compile", null },                 
33  
34                         { "debug", 0, 0, OptionArg.NONE, ref opt_debug, "Show debug messages", null },
35                         // fixme -- keepwhite.. cleanup 
36                         
37                         { null }
38                 };
39                 public static int main(string[] args) 
40                 {
41                         foreach(var a in arg) {
42                                 print("ARG: %s\n", a);
43                         }
44                         
45                         var opt_context = new OptionContext ("JSDOC Packer");
46                         
47                                 try {
48                                         opt_context.set_help_enabled (true);
49                                         opt_context.add_main_entries (options, null);
50                                         if (!opt_context.parse ( ref args)) {
51                                                 print("options parse error");
52                                                 GLib.Process.exit(Posix.EXIT_FAILURE);
53                                         }
54
55                                 
56                                          
57                                 
58                                 } catch (OptionError e) {
59                                         stdout.printf ("error: %s\n", e.message);
60                                         stdout.printf ("Run '%s --help' to see a full list of available command line options.\n %s", 
61                                                                  args[0], opt_context.get_help(true,null));
62                                         GLib.Process.exit(Posix.EXIT_FAILURE);
63                                          
64                                 }
65                 
66                         new PackerRun(args);
67                         return 0;
68                 }
69
70
71         
72                 public PackerRun (string[] args)
73                 {
74                 
75                         Object(
76                             application_id: "org.roojs.jsdoc.packerrun",
77                                 flags: ApplicationFlags.HANDLES_COMMAND_LINE 
78                         );
79                                          
80                          
81                         
82                         // what's required...
83                         if (opt_debug) {
84                                 GLib.Log.set_handler(null, 
85                                         GLib.LogLevelFlags.LEVEL_DEBUG | GLib.LogLevelFlags.LEVEL_WARNING, 
86                                         (dom, lvl, msg) => {
87                                         print("%s: %s\n", dom, msg);
88                                 });
89                         }
90                         
91                         // now run the Packer...
92                         var p = new Packer(opt_target, opt_debug_target);
93                         if (opt_files != null) {
94                                 GLib.debug("Adding File %s", string.join(", ",opt_files));
95                                 foreach (string f in opt_files) {
96                                         GLib.debug("Adding File %s", f);
97                                         p.loadFile(f);
98                                 }
99                         } else {
100                                 GLib.debug("No files added");
101                         }
102                         p.pack();
103                 }        
104                 
105         }
106         
107 }