Project

General

Profile

« Previous | Next » 

Revision 9192

lib/sh/util.sh: merged limit_stderr_cmd/limit_stdout_cmd into command(), using flag vars to control what limiting actions it needs to perform. in command invocations, this involves setting the appropriate flag vars instead of using a limit_std*_cmd alias.

View differences:

lib/sh/make.sh
23 23
# usage: set_make_vars; to_target cmd...
24 24
alias to_target='stdout="$target" to_file ' # last space alias-expands next word
25 25

  
26
make() { echo_func; limit_stdout_cmd self "$@"; }
26
make() { echo_func; stdout2stderr=1 limit_stderr=1 self "$@"; }
27 27

  
28 28
if false; then ## usage:
29 29
inline_make 10<<'EOF'
lib/sh/util.sh
241 241

  
242 242
## external commands
243 243

  
244
function command() # usage: [stderr_is_errors=1] command extern_cmd...
244
function command()
245
# usage: [stdout2stderr=1] [stderr_is_errors=1] [limit_stderr=1] command \
246
# extern_cmd...
245 247
# to view only explicitly-displayed errors: explicit_errors_only=1 script...
246 248
{
247 249
	test "$cmd_echoed" || echo_run_prep
248
	set -- -- "$@" # prepend -- so command name not treated as `command` option
249
	set -- builtin command "$@"
250
	if test "$stderr_is_errors"; then "$@" 2>&22 # ensure errors are visible
251
	else "$@"; fi
250
	(
251
		if test "$limit_stderr"; then limit_stderr; fi
252
		if test "$stderr_is_errors"; then exec 2>&22; fi # ensure errors visible
253
		builtin command -- "$@" # -- so cmd name not treated as `command` option
254
	) || return
252 255
}
253 256

  
254 257
# auto-echo common external commands
......
285 288
fi
286 289

  
287 290

  
288
### external command verbose output
289

  
290
limit_stderr_cmd() # usage: [stdout2stderr=1] limit_stderr_cmd cmd...
291
{
292
	case "$1" in command) echo_run_prep; local cmd_echoed=1;; esac
293
	(limit_stderr; "$@") || return
294
}
295
alias limit_stderr_cmd='"limit_stderr_cmd" ' #last space alias-expands next word
296
alias limit_stdout_cmd='stdout2stderr=1 limit_stderr_cmd '
297
	# last space alias-expands next word
298

  
299

  
300 291
### external command input/output
301 292

  
302 293
# usage: cmd1 | { pipe_delay; cmd2; }
lib/sh/archives.sh
7 7

  
8 8
zip()
9 9
{
10
	stdout2stderr=1 try limit_stderr_cmd self "$@"
10
	stdout2stderr=1 limit_stderr=1 try self "$@"
11 11
	ignore 12 # "zip has nothing to do" (`man zip`)
12 12
	end_try
13 13
}
14 14

  
15
unzip() { limit_stdout_cmd self "$@"; }
15
unzip() { stdout2stderr=1 limit_stderr=1 self "$@"; }
16 16

  
17 17
set_inv force
18 18
alias zip_newer='zip ${no_force:+-u }'
lib/sh/db.sh
64 64
	
65 65
	set -- ${database:+--database="$database" }--column-names "$@"
66 66
	if test "$output_data"; then echo_stdin|mysql_cmd --batch "$@"
67
	else limit_stdout_cmd mysql_cmd --verbose "$@"
67
	else stdout2stderr=1 limit_stderr=1 mysql_cmd --verbose "$@"
68 68
	fi
69 69
}
70 70

  

Also available in: Unified diff