diff --git a/config.go b/config.go index cd572e6a..0a228d7b 100644 --- a/config.go +++ b/config.go @@ -35,6 +35,7 @@ type Config struct { Output string `json:"output,omitempty" help:"Output location for {{.svg}}, {{.png}}, or {{.webp}}." short:"o" group:"Settings" default:"" placeholder:"freeze.svg"` Execute string `json:"-" help:"Capture output of command execution." short:"x" group:"Settings" default:""` ExecuteTimeout time.Duration `json:"-" help:"Execution timeout." group:"Settings" default:"10s" prefix:"execute." name:"timeout" hidden:""` + ExecuteNonZero bool `json:"nonzero" help:"Don't error on command execution even if exit code is non-zero." group:"Settings"` // Decoration Border Border `json:"border" embed:"" prefix:"border." group:"Border"` diff --git a/freeze_test.go b/freeze_test.go index 06b4e439..c84dc464 100644 --- a/freeze_test.go +++ b/freeze_test.go @@ -129,6 +129,10 @@ func TestFreezeConfigurations(t *testing.T) { flags: []string{"--execute", `echo "Hello, world!"`}, output: "execute", }, + { + flags: []string{"--execute-non-zero", "--execute", `mkdir "."`}, + output: "nonzero", + }, { input: "test/input/bubbletea.model", flags: []string{"--language", "go", "--height", "800", "--width", "750", "--config", "full", "--window=false", "--show-line-numbers"}, diff --git a/pty.go b/pty.go index 7c782b8f..64942369 100644 --- a/pty.go +++ b/pty.go @@ -46,7 +46,7 @@ func executeCommand(config Config) (string, error) { }() err = cmd.Wait() - if err != nil { + if err != nil && !config.ExecuteNonZero { return "", err } return out.String(), nil diff --git a/pty_windows.go b/pty_windows.go index 1a7a0c02..edf6ee23 100644 --- a/pty_windows.go +++ b/pty_windows.go @@ -71,7 +71,7 @@ func executeCommand(config Config) (string, error) { err = r.error } - if err != nil { + if err != nil && !config.ExecuteNonZero { return "", err } return out.String(), nil diff --git a/test/golden/png/nonzero.png b/test/golden/png/nonzero.png new file mode 100644 index 00000000..f76bbe95 --- /dev/null +++ b/test/golden/png/nonzero.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fbe1c71334907ac8f904f11d37214379362ecd60052c5a83792b5e6fce2325a6 +size 55384 diff --git a/test/golden/svg/nonzero.svg b/test/golden/svg/nonzero.svg new file mode 100644 index 00000000..cd7fc1b0 --- /dev/null +++ b/test/golden/svg/nonzero.svg @@ -0,0 +1,15 @@ + + + + + +mkdir: cannot create directory ‘.’: File exists + +