Project

General

Profile

« Previous | Next » 

Revision 9214

lib/sh/util.sh: command(): use just one control var $cmd_log_fd instead of three flags (limit_log_fd, limit_stdout, stderr_is_errors) that indicated various common fd configurations. this is much clearer (you state which fd the common uses as its logging fd), more configurable (the logging fd can be any fd, not just 1 or 2), and more automatic (redirecting fd 2 to err_fd happens automatically if it isn't used for logging).

View differences:

lib/sh/local.sh
51 51
\set table_str '''"$table"'''
52 52
SET search_path TO "$schema", util;
53 53
EOF
54
	cat)|limit_stdout=1 \
54
	cat)|cmd_log_fd=1 \
55 55
	env no_search_path=1 "$psql_cmd" --output /dev/fd/11 "$@" 11>&1
56 56
}
57 57

  
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=1 self "$@"; }
26
make() { echo_func; cmd_log_fd=1 self "$@"; }
27 27

  
28 28
if false; then ## usage:
29 29
inline_make 10<<'EOF'
lib/sh/util.sh
230 230
## external commands
231 231

  
232 232
function command()
233
# usage: [limit_log_fd=1] [limit_stdout=1] [stderr_is_errors=1] command \
234
# extern_cmd...
233
# usage: [cmd_log_fd=|1|2|#] command extern_cmd...
235 234
# to view only explicitly-displayed errors: explicit_errors_only=1 script...
236 235
{
237
	if test "$limit_stdout"; then local stdout2log_fd=1 limit_log_fd=1; fi
238
	local stderr_is_errors="${stderr_is_errors-$stdout2log_fd}"
239
	
240 236
	cmd2rel_path; (echo_params; can_log) && indent || true
241 237
	(
242 238
		# the following redirections must happen in exactly this order
243
		if test "$limit_log_fd"; then limit_log_fd; fi
244
		if test "$stdout2log_fd"; then stdout2log_fd; fi
245
		if test "$stderr_is_errors"; then exec 2>&"$err_fd"; fi
239
		limit_log_fd
240
		if test "$cmd_log_fd"; then echo_eval exec "$cmd_log_fd>&$log_fd"; fi
241
		if test "$cmd_log_fd" != 2; then # fd 2 not used for logging
242
			exec 2>&"$err_fd" # assume fd 2 used for errors
243
		fi
246 244
		
247 245
		exec -- "$@" # -- so cmd name not treated as `exec` option
248 246
	) || return
lib/sh/archives.sh
7 7

  
8 8
zip()
9 9
{
10
	limit_stdout=1 try self "$@"
10
	cmd_log_fd=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=1 self "$@"; }
15
unzip() { cmd_log_fd=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=1 mysql_cmd --verbose "$@"
67
	else cmd_log_fd=1 mysql_cmd --verbose "$@"
68 68
	fi
69 69
}
70 70

  

Also available in: Unified diff