Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#112): Support nonzero execute exit codes via --execute-non-zero #113

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions freeze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
2 changes: 1 addition & 1 deletion pty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pty_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test/golden/png/nonzero.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions test/golden/svg/nonzero.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.