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