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