Skip to content

Commit

Permalink
print help by default
Browse files Browse the repository at this point in the history
  • Loading branch information
myaaaaaaaaa committed Nov 25, 2024
1 parent c41101f commit dc75172
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 3 additions & 0 deletions prog.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ func (p *Program) Main() (rtErr error) {
defer catch[failError](&rtErr)

var f flags
if p.StdinIsTerminal && len(p.Args) == 0 {
p.Args = []string{"-h"}
}
f.populate(p.Args)

files := map[string]any{}
Expand Down
7 changes: 4 additions & 3 deletions prog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ func testRun(t *testing.T, stdin, want string, p *Program) {
}

func TestProgram(t *testing.T) {
testRun(t, "[] []", "[] []", &Program{})
testRun(t, "[] [}", "error", &Program{})
testRun(t, "[] []", "{}", &Program{StdinIsTerminal: true})
testRun(t, "[] []", "[] []", &Program{})
testRun(t, "[] []", "[] []", &Program{Args: []string{"."}})
testRun(t, "[] []", "{}", &Program{Args: []string{"."}, StdinIsTerminal: true})

testRun(t, "[10]", "[10]", &Program{})
testRun(t, "[10]", "[10]", &Program{Args: []string{"-j"}})
Expand Down Expand Up @@ -71,7 +72,7 @@ func TestOpen(t *testing.T) {
"e.txt": "q\nw\ne\nr\nt\ny",
}

p := Program{StdinIsTerminal: true}
p := Program{Args: []string{"."}, StdinIsTerminal: true}
testRun(t, "", "{}", &p)

p.Open = toFS(testFiles, nil).Open
Expand Down

0 comments on commit dc75172

Please sign in to comment.