Skip to content

Commit

Permalink
Fix srcenv src output when called with no arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
ins0mniaque committed Dec 10, 2024
1 parent 0e80c05 commit bf8ccfe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions srcenv
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ init() {
bash|\
ksh|pdksh|mksh|\
posix|sh|\
zsh) echo "$cmd() { eval \"\$($0 $shell --cmd \"$cmd\" $opts \"\$@\")\"; }" ;;
zsh) echo "$cmd() { eval \"\$($0 $shell $opts --cmd \"$cmd\" \"\$@\")\"; }" ;;
csh|tcsh|\
elvish|\
fish|\
Expand Down Expand Up @@ -325,9 +325,10 @@ run() {
setformat

while [ $# -gt 0 ] && [ "$1" != -- ]; do
cmd=
case $1 in
-c|--cmd) src=$(parse "$1" "$2") || exit $?; [ $# -gt 1 ] && shift; shift ;;
-c=*|--cmd=*) src=$(parse "${1%%=*}" "${1#*=}") || exit $?; shift ;;
-c|--cmd) src=$(parse "$1" "$2") || exit $?; [ $# -gt 1 ] && shift; cmd=1; shift ;;
-c=*|--cmd=*) src=$(parse "${1%%=*}" "${1#*=}") || exit $?; cmd=1; shift ;;

-f|--format) value=$(parse "$1" "$2") || exit $?; [ $# -gt 1 ] && shift
fmt "${value%\?\?*}" "${value#*\?\?}"; shift ;;
Expand Down Expand Up @@ -373,7 +374,7 @@ run() {
done

if [ $# = 0 ]; then
if [ -n "$src" ]; then
if [ -n "$cmd" ]; then
header; usage; desc; help; man; exit 0
elif [ -n "$backup" ] || [ -z "$restore" ]; then
noinput; usage; help; exit 2
Expand Down
2 changes: 1 addition & 1 deletion srcenv.tests
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ run_posix_tests() {
run "$1" "SRCENV_RESTORE='' $2 sh --restore" '' 5
run "$1" "$2 --restore" '' 2
run "$and_no_stdin" "$2 sh --backup --restore" '' 2
run "$1" "$2 sh --cmd src --backup --restore" ''
run "$1" "$2 sh --backup --restore --cmd src" ''

run "$1" "$2 sh --input 'echo something'" ''
run "$1" "$2 sh --input 'echo something; not_a_command'" '' 127
Expand Down

0 comments on commit bf8ccfe

Please sign in to comment.