Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion cqfd
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ while [ $# -gt 0 ]; do
has_to_release=true
fi

cqfd_command="$1"
shift

# No more args? run default command
Expand All @@ -877,7 +878,7 @@ while [ $# -gt 0 ]; do

if [ "$#" -lt 1 ]; then
usage
die "run -c: Missing arguments!"
die "$cqfd_command -c: Missing arguments!"
fi
break
fi
Expand All @@ -886,6 +887,28 @@ while [ $# -gt 0 ]; do
set_shell_histfile "$1"
# Run alternate command
has_alternate_command=true

# Display a warning message if using run with at least one quoted argument
show_error_message=false
if [ "$#" -gt 1 ]; then
# Rebuild the initial command with quotes only for arguments containing spaces
initial_command=""
for arg in "$@"; do
if [[ $arg = *" "* ]]; then
initial_command+="'$arg' "
show_error_message=true
else
initial_command+="$arg "
fi
done
initial_command=${initial_command%?}
if "$show_error_message"; then
warn "command '$cqfd_command' with multiple arguments is ambiguous," \
"please consider the commands 'exec' or 'shell' instead:"
echo " cqfd exec $initial_command" >&2
echo " cqfd shell -c \"$initial_command\"" >&2
fi
fi
break
;;
sh|ash|dash|bash|ksh|zsh|csh|tcsh|fish|shell)
Expand Down
11 changes: 11 additions & 0 deletions tests/05-cqfd_run_command.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,14 @@ teardown() {
run cqfd run /bin/sh -c 'printf "0=$0,*=$*,#=$#"' zero one two three
assert_line --regexp "0=(\/bin\/)?sh,\*=,#=0"
}

@test "cqfd run with a quoted argument triggers a warning message" {
run cqfd run touch "this is a filename"
assert_line --partial "cqfd exec touch 'this is a filename'"
assert_line --partial "cqfd shell -c \"touch 'this is a filename'\""
}

@test "cqfd run without a quoted argument DOES NOT trigger a warning message" {
run cqfd run touch these are multiple filenames
refute_output
}
Loading