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