From f490ee1e2c099eadd3da0876f66819192c19a3cd Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Sun, 12 Jan 2020 18:42:47 +0000 Subject: [PATCH] cmdline: Implement -s (--silent or --quiet) option. --- docs/goals.pod | 10 ++++++++++ src/cmdline.ml | 8 ++++++++ src/cmdline.mli | 3 +++ src/eval.ml | 2 +- tests/20-option-silent.gl | 19 +++++++++++++++++++ tests/20-option-silent.sh | 24 ++++++++++++++++++++++++ 6 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 tests/20-option-silent.gl create mode 100755 tests/20-option-silent.sh diff --git a/docs/goals.pod b/docs/goals.pod index e2b1af1..f21ae21 100644 --- a/docs/goals.pod +++ b/docs/goals.pod @@ -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] + [-s|--silent|--quiet] 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). +=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> sections into S> sections. + =back =head1 SEE ALSO diff --git a/src/cmdline.ml b/src/cmdline.ml index f83d5eb..ff71c9c 100644 --- a/src/cmdline.ml +++ b/src/cmdline.ml @@ -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 silent = ref false 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"; + "-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, @@ -128,4 +135,5 @@ let input_file () = !input_file let includes () = !includes let nr_jobs () = !nr_jobs +let silent () = !silent let use_prelude () = !use_prelude diff --git a/src/cmdline.mli b/src/cmdline.mli index 3372684..9bc8ff9 100644 --- a/src/cmdline.mli +++ b/src/cmdline.mli @@ -51,5 +51,8 @@ val includes : unit -> string list 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. *) diff --git a/src/eval.ml b/src/eval.ml index 59f4ca4..053d8bf 100644 --- a/src/eval.ml +++ b/src/eval.ml @@ -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" ^ - (if not quiet then "set -x\n" else "") ^ + (if not (Cmdline.silent ()) && not quiet then "set -x\n" else "") ^ "\n" ^ code diff --git a/tests/20-option-silent.gl b/tests/20-option-silent.gl new file mode 100644 index 0000000..0b6e3ef --- /dev/null +++ b/tests/20-option-silent.gl @@ -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 index 0000000..4b7d2c1 --- /dev/null +++ b/tests/20-option-silent.sh @@ -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 -- 1.8.3.1