2 * Copyright (C) 2014-2015 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 let () = Random.self_init ()
27 try Sys.getenv "MCLU_CONFIG"
28 with Not_found -> Config.sysconfdir // "mclu.conf" in
31 let verbose = ref false
34 printf "%s %s\n" Config.package_name Config.package_version;
37 let global_speclist = Arg.align [
38 "--config-file", Arg.Set_string config_file, "FILE Set configuration file";
39 "-f", Arg.Set_string config_file, "FILE Set configuration file";
40 "-v", Arg.Set verbose, " Enable verbose/debugging messages";
41 "--verbose", Arg.Set verbose, " Enable verbose/debugging messages";
42 "-V", Arg.Unit show_version, " Display version and exit";
43 "--version", Arg.Unit show_version, " Display version and exit";
45 let speclist = ref global_speclist
46 let subcommand_run = ref (fun ~verbose _ -> assert false)
47 let anon_fun, get_anon_args =
55 speclist := Mclu_boot.get_arg_speclist ();
56 subcommand_run := Mclu_boot.run
58 speclist := Mclu_console.get_arg_speclist ();
59 subcommand_run := Mclu_console.run
61 speclist := Mclu_destroy.get_arg_speclist ();
62 subcommand_run := Mclu_destroy.run
64 speclist := Mclu_list.get_arg_speclist ();
65 subcommand_run := Mclu_list.run
67 speclist := Mclu_onoff.get_arg_speclist ();
68 subcommand_run := Mclu_onoff.run ~on:false
70 speclist := Mclu_onoff.get_arg_speclist ();
71 subcommand_run := Mclu_onoff.run ~on:true
73 speclist := Mclu_reboot.get_arg_speclist ();
74 subcommand_run := Mclu_reboot.run
76 speclist := Mclu_status.get_arg_speclist ();
77 subcommand_run := Mclu_status.run
79 speclist := Mclu_viewer.get_arg_speclist ();
80 subcommand_run := Mclu_viewer.run
82 eprintf "mclu: unknown subcommand '%s'
83 For help, use mclu --help or read the mclu(1) man page.\n" arg;
89 let get_anon_args () = List.rev !args in
90 anon_fun, get_anon_args
93 mclu [-f mclu.conf] [--options] [list|status|boot|...] ...
95 For more help, use mclu --help or read the mclu(1) man page.
100 (* Parse the command line and subcommand arguments. *)
101 Arg.parse_dynamic speclist anon_fun usage_msg;
103 (* Load the configuration file. *)
104 Mclu_conf.load_configuration !config_file;
106 (* Run the subcommand. *)
107 let verbose = !verbose in
108 !subcommand_run ~verbose (get_anon_args ())