fc18bbd50c7de38abdaa8a71362592249e2b7b46
[febootstrap.git] / src / febootstrap_cmdline.ml
1 (* febootstrap 3
2  * Copyright (C) 2009-2010 Red Hat Inc.
3  *
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.
8  *
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.
13  *
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
17  *)
18
19 open Printf
20
21 let excludes = ref []
22 let names_mode = ref false
23 let outputdir = ref "."
24 let packages = ref []
25 let save_temps = ref false
26 let use_installed = ref false
27 let verbose = ref false
28 let warnings = ref true
29 let yum_config = ref None
30
31 let print_version () =
32   printf "%s %s\n" Config.package_name Config.package_version;
33   exit 0
34
35 let add_exclude re =
36   excludes := Str.regexp re :: !excludes
37
38 let set_yum_config str =
39   yum_config := Some str
40
41 let argspec = Arg.align [
42   "--exclude", Arg.String add_exclude,
43     "regexp Exclude packages matching regexp";
44   "--names", Arg.Set names_mode,
45     " Specify set of root package names on command line";
46   "--no-warnings", Arg.Clear warnings,
47     " Suppress warnings";
48   "-o", Arg.Set_string outputdir,
49     "outputdir Set output directory (default: \".\")";
50   "--save-temp", Arg.Set save_temps,
51     " Don't delete temporary files and directories on exit.";
52   "--save-temps", Arg.Set save_temps,
53     " Don't delete temporary files and directories on exit.";
54   "--use-installed", Arg.Set use_installed,
55     " Inspect already installed packages for determining contents.";
56   "-v", Arg.Set verbose,
57     " Enable verbose output";
58   "--verbose", Arg.Set verbose,
59     " Enable verbose output";
60   "-V", Arg.Unit print_version,
61     " Print package name and version, and exit";
62   "--version", Arg.Unit print_version,
63     " Print package name and version, and exit";
64   "--yum-config", Arg.String set_yum_config,
65     "file Set alternate yum configuration file";
66 ]
67 let anon_fn str =
68   packages := str :: !packages
69
70 let usage_msg =
71   "\
72 febootstrap - bootstrapping tool for creating supermin appliances
73 Copyright (C) 2009-2010 Red Hat Inc.
74
75 Usage:
76  febootstrap [-o OUTPUTDIR] --names LIST OF PKGS ...
77  febootstrap [-o OUTPUTDIR] PKG FILE NAMES ...
78
79 For full instructions see the febootstrap(8) man page.
80
81 Options:\n"
82
83 let () =
84   Arg.parse argspec anon_fn usage_msg;
85   if !packages = [] then (
86     eprintf "febootstrap: no packages listed on the command line\n";
87     exit 1
88   )
89
90 let excludes = List.rev !excludes
91 let names_mode = !names_mode
92 let outputdir = !outputdir
93 let packages = List.rev !packages
94 let save_temps = !save_temps
95 let use_installed = !use_installed
96 let verbose = !verbose
97 let warnings = !warnings
98 let yum_config = !yum_config
99
100 let debug fs = ksprintf (fun str -> if verbose then print_endline str) fs