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