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.
25 try Sys.getenv "MCLU_CONFIG"
26 with Not_found -> Config.sysconfdir // "mclu.conf" in
29 let verbose = ref false
32 printf "%s %s\n" Config.package_name Config.package_version;
35 let global_speclist = Arg.align [
36 "--config-file", Arg.Set_string config_file, "FILE Set configuration file";
37 "-f", Arg.Set_string config_file, "FILE Set configuration file";
38 "-v", Arg.Set verbose, " Enable verbose/debugging messages";
39 "--verbose", Arg.Set verbose, " Enable verbose/debugging messages";
40 "-V", Arg.Unit show_version, " Display version and exit";
41 "--version", Arg.Unit show_version, " Display version and exit";
43 let speclist = ref global_speclist
44 let subcommand_run = ref (fun ~verbose _ -> assert false)
45 let anon_fun, get_anon_args =
53 speclist := Mclu_boot.get_arg_speclist ();
54 subcommand_run := Mclu_boot.run
56 speclist := Mclu_console.get_arg_speclist ();
57 subcommand_run := Mclu_console.run
59 speclist := Mclu_destroy.get_arg_speclist ();
60 subcommand_run := Mclu_destroy.run
62 speclist := Mclu_list.get_arg_speclist ();
63 subcommand_run := Mclu_list.run
65 speclist := Mclu_onoff.get_arg_speclist ();
66 subcommand_run := Mclu_onoff.run ~on:false
68 speclist := Mclu_onoff.get_arg_speclist ();
69 subcommand_run := Mclu_onoff.run ~on:true
71 speclist := Mclu_status.get_arg_speclist ();
72 subcommand_run := Mclu_status.run
74 eprintf "mclu: unknown subcommand '%s'
75 For help, use mclu --help or read the mclu(1) man page.\n" arg;
81 let get_anon_args () = List.rev !args in
82 anon_fun, get_anon_args
85 mclu [-f mclu.conf] [--options] [list|status|boot|...] ...
87 For more help, use mclu --help or read the mclu(1) man page.
92 (* Parse the command line and subcommand arguments. *)
93 Arg.parse_dynamic speclist anon_fun usage_msg;
95 (* Load the configuration file. *)
96 Mclu_conf.load_configuration !config_file;
98 (* Run the subcommand. *)
99 let verbose = !verbose in
100 !subcommand_run ~verbose (get_anon_args ())