cmdline: Implement -s (--silent or --quiet) option.
authorRichard W.M. Jones <rjones@redhat.com>
Sun, 12 Jan 2020 18:42:47 +0000 (18:42 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Sun, 12 Jan 2020 18:45:53 +0000 (18:45 +0000)
docs/goals.pod
src/cmdline.ml
src/cmdline.mli
src/eval.ml
tests/20-option-silent.gl [new file with mode: 0644]
tests/20-option-silent.sh [new file with mode: 0755]

index e2b1af1..f21ae21 100644 (file)
@@ -9,6 +9,7 @@ goals - an experimental tool that generalizes “make”
  goals ['TARGET'] ['VAR=VALUE']
        [-C|--directory DIRECTORY] [-d] [-f|--file Goalfile]
        [-I|--include DIRECTORY] [-j|--jobs JOBS] [--no-prelude]
  goals ['TARGET'] ['VAR=VALUE']
        [-C|--directory DIRECTORY] [-d] [-f|--file Goalfile]
        [-I|--include DIRECTORY] [-j|--jobs JOBS] [--no-prelude]
+       [-s|--silent|--quiet]
 
  goals --help
 
 
  goals --help
 
@@ -92,6 +93,15 @@ prelude is always loaded automatically before any initial goal file
 (but you can redefine prelude definitions in your goal file if you
 want).
 
 (but you can redefine prelude definitions in your goal file if you
 want).
 
+=item B<-s>
+
+=item B<--silent>
+
+=item B<--quiet>
+
+Don't print the shell commands that are run.  This is the same as
+turning all S<C<{ CODE }>> sections into S<C<@{ CODE }>> sections.
+
 =back
 
 =head1 SEE ALSO
 =back
 
 =head1 SEE ALSO
index f83d5eb..ff71c9c 100644 (file)
@@ -52,6 +52,7 @@ let input_file = ref "Goalfile"
 let includes = ref [stdlibdir]
 let add_include dir = includes := dir :: !includes
 let nr_jobs = ref (nprocs ())
 let includes = ref [stdlibdir]
 let add_include dir = includes := dir :: !includes
 let nr_jobs = ref (nprocs ())
+let silent = ref false
 let use_prelude = ref true
 
 let parse () =
 let use_prelude = ref true
 
 let parse () =
@@ -82,6 +83,12 @@ let parse () =
                    jobshelp;
     "--no-prelude",Arg.Clear use_prelude,
                    " Do not automatically use prelude.gl from stdlib";
                    jobshelp;
     "--no-prelude",Arg.Clear use_prelude,
                    " Do not automatically use prelude.gl from stdlib";
+    "-s",          Arg.Set silent,
+                   " Silent operation";
+    "--silent",    Arg.Set silent,
+                   " Silent operation";
+    "--quiet",     Arg.Set silent,
+                   " Silent operation";
     "-v",          Arg.Unit print_version,
                    " Print version and exit";
     "--version",   Arg.Unit print_version,
     "-v",          Arg.Unit print_version,
                    " Print version and exit";
     "--version",   Arg.Unit print_version,
@@ -128,4 +135,5 @@ let input_file () = !input_file
 let includes () = !includes
 
 let nr_jobs () = !nr_jobs
 let includes () = !includes
 
 let nr_jobs () = !nr_jobs
+let silent () = !silent
 let use_prelude () = !use_prelude
 let use_prelude () = !use_prelude
index 3372684..9bc8ff9 100644 (file)
@@ -51,5 +51,8 @@ val includes : unit -> string list
 val nr_jobs : unit -> int
 (** Number of jobs (-j option). *)
 
 val nr_jobs : unit -> int
 (** Number of jobs (-j option). *)
 
+val silent : unit -> bool
+(** Silent operation (-s option). *)
+
 val use_prelude : unit -> bool
 (** True if we should load the prelude, or false if --no-prelude. *)
 val use_prelude : unit -> bool
 (** True if we should load the prelude, or false if --no-prelude. *)
index 59f4ca4..053d8bf 100644 (file)
@@ -190,7 +190,7 @@ and prepare_code env loc (code, quiet) =
   let code = to_shell_script env loc code in
   "source " ^ Filename.quote Cmdline.prelude_sh_file ^ "\n" ^
   "set -e\n" ^
   let code = to_shell_script env loc code in
   "source " ^ Filename.quote Cmdline.prelude_sh_file ^ "\n" ^
   "set -e\n" ^
-  (if not quiet then "set -x\n" else "") ^
+  (if not (Cmdline.silent ()) && not quiet then "set -x\n" else "") ^
   "\n" ^
   code
 
   "\n" ^
   code
 
diff --git a/tests/20-option-silent.gl b/tests/20-option-silent.gl
new file mode 100644 (file)
index 0000000..0b6e3ef
--- /dev/null
@@ -0,0 +1,19 @@
+# Goals test.
+# Copyright (C) 2020 Richard W.M. Jones
+# Copyright (C) 2020 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+goal all = { echo OK }
diff --git a/tests/20-option-silent.sh b/tests/20-option-silent.sh
new file mode 100755 (executable)
index 0000000..4b7d2c1
--- /dev/null
@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+# Goals test.
+# Copyright (C) 2020 Richard W.M. Jones
+# Copyright (C) 2020 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License along
+# with this program; if not, write to the Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+set -e
+
+goals -s -f 20-option-silent.gl > 20-option-silent.out 2>&1
+test "$(cat 20-option-silent.out)" = "OK"
+rm 20-option-silent.out