From c3ba15ba56aae69dd91d9a82a58d5351ad6f0285 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sat, 8 Aug 2015 21:28:41 +0200 Subject: [PATCH] Add --quiet option to rec command (closes #122) --- CHANGELOG.md | 1 + README.md | 1 + main.go | 11 +++++++++-- man/asciinema.1 | 3 +++ util/echo.go | 17 ++++++++++++++--- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0737eb..7ffd785 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## master * Added ability to replay asciicast from stdin by passing "-" as filename +* `-q/--quiet` option added to `rec` command ## 1.1.1 (2015-06-21) diff --git a/README.md b/README.md index fa2d104..90e829d 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,7 @@ Available options: * `-t, --title=` - Specify the title of the asciicast * `-w, --max-wait=<sec>` - Reduce recorded terminal inactivity to max <sec> seconds * `-y, --yes` - Answer "yes" to all prompts (e.g. upload confirmation) +* `-q, --quiet` - Be quiet, suppress all notices/warnings (implies -y) ### `play <filename>` diff --git a/main.go b/main.go index 04d5e62..7b4ef99 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ const Version = "1.1.1" var usage = `Record and share your terminal sessions, the right way. Usage: - asciinema rec [-c <command>] [-t <title>] [-w <sec>] [-y] [<filename>] + asciinema rec [-c <command>] [-t <title>] [-w <sec>] [-y] [-q] [<filename>] asciinema play [-w <sec>] <filename> asciinema upload <filename> asciinema auth @@ -34,7 +34,8 @@ Options: -c, --command=<command> Specify command to record, defaults to $SHELL -t, --title=<title> Specify title of the asciicast -w, --max-wait=<sec> Reduce recorded terminal inactivity to max <sec> seconds - -y, --yes Answer yes to all prompts (e.g. upload confirmation) + -y, --yes Answer "yes" to all prompts (e.g. upload confirmation) + -q, --quiet Be quiet, suppress all notices/warnings (implies -y) -h, --help Show this message --version Show version` @@ -113,6 +114,12 @@ func main() { command := util.FirstNonBlank(stringArg(args, "--command"), cfg.RecordCommand()) title := stringArg(args, "--title") assumeYes := cfg.RecordYes() || boolArg(args, "--yes") + + if boolArg(args, "--quiet") { + util.BeQuiet() + assumeYes = true + } + maxWait := uintArg(args, "--max-wait", cfg.RecordMaxWait()) filename := stringArg(args, "<filename>") cmd := commands.NewRecordCommand(api, env) diff --git a/man/asciinema.1 b/man/asciinema.1 index 4d9c209..1d96f40 100644 --- a/man/asciinema.1 +++ b/man/asciinema.1 @@ -46,6 +46,9 @@ reduce recorded terminal inactivity to max <sec> seconds .TP \-y, \-\-yes answer "yes" to all prompts (e.g. upload confirmation) +.TP +\-q, \-\-quiet +be quiet, suppress all notices/warnings (implies -y) .RE .RE .PP diff --git a/util/echo.go b/util/echo.go index 976a2ef..c48cbc1 100644 --- a/util/echo.go +++ b/util/echo.go @@ -1,11 +1,22 @@ package util -import "fmt" +import ( + "fmt" + "io" + "io/ioutil" + "os" +) + +var loggerOutput io.Writer = os.Stdout + +func BeQuiet() { + loggerOutput = ioutil.Discard +} func Printf(s string, args ...interface{}) { - fmt.Printf("\x1b[32m~ %v\x1b[0m\n", fmt.Sprintf(s, args...)) + fmt.Fprintf(loggerOutput, "\x1b[32m~ %v\x1b[0m\n", fmt.Sprintf(s, args...)) } func Warningf(s string, args ...interface{}) { - fmt.Printf("\x1b[33m~ %v\x1b[0m\n", fmt.Sprintf(s, args...)) + fmt.Fprintf(loggerOutput, "\x1b[33m~ %v\x1b[0m\n", fmt.Sprintf(s, args...)) }