Skip to content

Commit 2e1d4f0

Browse files
committed
Improve help output
1 parent 8ce3ea9 commit 2e1d4f0

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

main.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"errors"
54
"flag"
65
"fmt"
76
"os"
@@ -24,13 +23,15 @@ func run() error {
2423
var hostname string
2524
var repo string
2625
var branch string
26+
flag.Usage = usageFunc
2727
flag.StringVar(&branch, "branch", "", "Explore a specific branch of the repository")
2828
flag.StringVar(&hostname, "hostname", "", "The GitHub hostname for the request (default \"github.com\")")
2929
flag.Parse()
3030
repo = flag.Arg(0)
3131

32-
if repo == "" {
33-
return errors.New("repository argument required")
32+
if repo == "" || repo == "help" {
33+
usageFunc()
34+
return nil
3435
}
3536
if branch == "" {
3637
branch, err = explore.RetrieveDefaultBranch(hostname, repo)
@@ -67,3 +68,12 @@ func buildApplication(treeView *tview.TreeView, fileView *tview.TextView, search
6768
app.SetRoot(flex, true).EnableMouse(true).SetFocus(searchView)
6869
return app
6970
}
71+
72+
func usageFunc() {
73+
fmt.Fprintf(os.Stdout, "Interactively explore a repository.\n\n")
74+
fmt.Fprintf(os.Stdout, "USAGE\n")
75+
fmt.Fprintf(os.Stdout, " gh repo-explore <owner>/<repository>\n\n")
76+
fmt.Fprintf(os.Stdout, "FLAGS\n")
77+
fmt.Fprintf(os.Stdout, " --branch\tExplore a specific branch of the repository\n")
78+
fmt.Fprintf(os.Stdout, " --hostname\tThe GitHub host for the request (default \"github.com\")\n")
79+
}

0 commit comments

Comments
 (0)