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