From 252249a348c9958875ce96a88d692715e61ab0b1 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 16 May 2021 13:23:27 +0300 Subject: [PATCH] tools: add a --silent option to `v watch` --- cmd/tools/vwatch.v | 8 ++++++-- cmd/v/help/watch.txt | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/tools/vwatch.v b/cmd/tools/vwatch.v index d5d4a21025..a2f108d402 100644 --- a/cmd/tools/vwatch.v +++ b/cmd/tools/vwatch.v @@ -77,6 +77,7 @@ mut: v_cycles int // how many times the worker has restarted the V compiler scan_cycles int // how many times the worker has scanned for source file changes clear_terminal bool // whether to clear the terminal before each re-run + silent bool // when true, watch will not print a timestamp line before each re-run add_files []string // path to additional files that have to be watched for changes ignore_exts []string // extensions of files that will be ignored, even if they change (useful for sqlite.db files for example) } @@ -214,7 +215,9 @@ fn (mut context Context) compilation_runner_loop() { if context.clear_terminal { term.clear() } - eprintln('$timestamp: $cmd | pid: ${context.child_process.pid:7d} | reload cycle: ${context.v_cycles:5d}') + if !context.silent { + eprintln('$timestamp: $cmd | pid: ${context.child_process.pid:7d} | reload cycle: ${context.v_cycles:5d}') + } for { mut cmds := []RerunCommand{} for { @@ -269,10 +272,11 @@ fn main() { } fp.version('0.0.2') fp.description('Collect all .v files needed for a compilation, then re-run the compilation when any of the source changes.') - fp.arguments_description('[--clear] [--ignore .db] [--add /path/to/a/file.v] [run] program.v') + fp.arguments_description('[--silent] [--clear] [--ignore .db] [--add /path/to/a/file.v] [run] program.v') fp.allow_unknown_args() fp.limit_free_args_to_at_least(1) context.is_worker = fp.bool('vwatchworker', 0, false, 'Internal flag. Used to distinguish vwatch manager and worker processes.') + context.silent = fp.bool('silent', `s`, false, 'Be more silent; do not print the watch timestamp before each re-run.') context.clear_terminal = fp.bool('clear', `c`, false, 'Clears the terminal before each re-run.') context.add_files = fp.string('add', `a`, '', 'Add more files to be watched. Useful with `v watch -add=/tmp/feature.v run cmd/v /tmp/feature.v`, when you want to change *both* the compiler, and the feature.v file.').split(',') context.ignore_exts = fp.string('ignore', `i`, '', 'Ignore files having these extensions. Useful with `v watch -ignore=.db run server.v`, if your server writes to an sqlite.db file in the same folder.').split(',') diff --git a/cmd/v/help/watch.txt b/cmd/v/help/watch.txt index f3c3e0a0cf..4fd3347d35 100644 --- a/cmd/v/help/watch.txt +++ b/cmd/v/help/watch.txt @@ -5,6 +5,8 @@ Description: any of the .v source files changes, it re-runs the compilation. Options: + -s, --silent Be more silent; do not print the watch timestamp before each re-run. + -c, --clear Clears the terminal before each re-run. -a, --add Add more files to be watched.