Fixing "cg-help typo" again
PATCH 1/1 Fixing "cg-help typo" again
Hello!
"cg-help typo" is broken again (same symptom - no output) because the print_help() output is piped through colorize(), which never fails.
I don't know any way to get return status of the first command in a pipeline, so I changed to code to put print_help() output in a variable, check status and then pipe the variable contents through colorize().
GNU bash can hold indefinitely much data in variables, and we need a few kilobytes at most.
cg-help +2 -1
@@ -59,7 +59,8 @@ colorize() { if [ "$ARGS" ]; then cmd=$(echo "${ARGS[0]}" | sed 's/^cg-//') - ( print_help $cmd | colorize ) && exit + helpdata="$(print_help $cmd)" + [ "$?" = 0 ] && { echo "$helpdata" | colorize; exit 0; } echo "cg-help: no help available for command \"${ARGS[0]}\"" echo "Call cg-help without any arguments for the list of available commands" exit 1
Signature · 2 lines
Regards, Pavel Roskin
Pavel Roskin <[email protected]> wrote Tue, Jun 14, 2005:
Quoted 1 line
Hello!
Hi,
Quoted 2 lines
"cg-help typo" is broken again (same symptom - no output) because the
print_help()output is piped throughcolorize(), which never fails.
Sorry, I broke it in the cg-help colorization patch, and has already sent a patch to pasky, off-list I am afraid ...
Quoted 4 lines
I don't know any way to get return status of the first command in a pipeline, so I changed to code to put
print_help()output in a variable, check status and then pipe the variable contents throughcolorize().
Use the PIPESTATUS aray as in the patch I sent:
@@ -59,7 +59,8 @@ colorize() {
if [ "$ARGS" ]; then
cmd=$(echo "${ARGS[0]}" | sed 's/^cg-//')
- ( print_help $cmd | colorize ) && exit
+ print_help $cmd | colorize
+ [ "${PIPESTATUS[0]}" -eq 0 ] && exit
echo "cg-help: no help available for command \"${ARGS[0]}\"" echo "Call cg-help without any arguments for the list of available commands" exit 1
Signature · 1 line
Jonas Fonseca
Pavel Roskin
Acked-byHi, Jonas!
Quoted 6 lines · Jonas Fonseca
Pavel Roskin <[email protected]> wrote Tue, Jun 14, 2005:
Quoted 3 lines
I don't know any way to get return status of the first command in a pipeline, so I changed to code to put
print_help()output in a variable, check status and then pipe the variable contents throughcolorize().Use the PIPESTATUS aray as in the patch I sent:
OK, your patch is better.
Signature · 2 lines
Regards, Pavel Roskin