Skip to content

Commit

Permalink
Always exit with the exit code of the command
Browse files Browse the repository at this point in the history
Previously, in case a command started successfully, but failed
eventually, pistol would not exit with the exit code of the command.

Fixes #52.
  • Loading branch information
doronbehar committed Mar 4, 2021
1 parent 2665155 commit 3a8dc11
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ test: pistol
@echo application/json \(issue '#'34\):
@echo -------------------
@./pistol --config tests/config tests/34.json
@tput sgr0
@echo -------------------
@echo exit code \(issue '#'52\):
@echo -------------------
@./tests/exit-code.sh

deps:
go get github.com/c4milo/github-release
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.8
0.1.9
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion previewer.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func (p *Previewer) Write(w io.Writer) (error) {
log.Fatalf("We've had issues running your command: %v, %s", p.Command, p.Args)
return err
}
cmd.Wait()
return cmd.Wait()
} else {
// try to match with internal writers
internal_writer, err := pistol.MatchInternalWriter(p.MimeType, p.FilePath)
Expand Down
Binary file added tests/34.json.bz2
Binary file not shown.
4 changes: 4 additions & 0 deletions tests/config
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ fpath .*/tests/fpath-with-sh$ sh: bat --map-syntax :Markdown --paging=never --st
text/html elinks -dump -dump-color-mode 1 %pistol-filename%
# detects: mimetype, sh: yes
text/plain sh: bat --map-syntax :Markdown --paging=never --style=numbers --color=always %pistol-filename% | head -1
# Test exit code is non-zero in case a command does not exist:
application/x-bzip2 not-a-real-command %pistol-filename%
# Test exit code is non-zero in case a command starts but fails to finish
fpath .*/tests$ bat %pistol-filename%
21 changes: 21 additions & 0 deletions tests/exit-code.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

if ./pistol --config tests/config tests/34.json.bz2; then
tput setaf 1
echo "exit code was not non-zero when testing a non real command"
exit 1
else
tput setaf 2
echo "exit code was not zero"
fi

if ./pistol --config tests/config tests; then
tput setaf 1
echo "exit code was not non-zero when testing a real command with invalid arguments for it"
exit 1
else
tput setaf 2
echo "exit code was not zero"
fi
tput sgr0
exit 0

0 comments on commit 3a8dc11

Please sign in to comment.