Skip to content

Commit

Permalink
Improve help output
Browse files Browse the repository at this point in the history
  • Loading branch information
samcoe committed Aug 24, 2021
1 parent 8ce3ea9 commit 2e1d4f0
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"flag"
"fmt"
"os"
Expand All @@ -24,13 +23,15 @@ func run() error {
var hostname string
var repo string
var branch string
flag.Usage = usageFunc
flag.StringVar(&branch, "branch", "", "Explore a specific branch of the repository")
flag.StringVar(&hostname, "hostname", "", "The GitHub hostname for the request (default \"github.com\")")
flag.Parse()
repo = flag.Arg(0)

if repo == "" {
return errors.New("repository argument required")
if repo == "" || repo == "help" {
usageFunc()
return nil
}
if branch == "" {
branch, err = explore.RetrieveDefaultBranch(hostname, repo)
Expand Down Expand Up @@ -67,3 +68,12 @@ func buildApplication(treeView *tview.TreeView, fileView *tview.TextView, search
app.SetRoot(flex, true).EnableMouse(true).SetFocus(searchView)
return app
}

func usageFunc() {
fmt.Fprintf(os.Stdout, "Interactively explore a repository.\n\n")
fmt.Fprintf(os.Stdout, "USAGE\n")
fmt.Fprintf(os.Stdout, " gh repo-explore <owner>/<repository>\n\n")
fmt.Fprintf(os.Stdout, "FLAGS\n")
fmt.Fprintf(os.Stdout, " --branch\tExplore a specific branch of the repository\n")
fmt.Fprintf(os.Stdout, " --hostname\tThe GitHub host for the request (default \"github.com\")\n")
}

0 comments on commit 2e1d4f0

Please sign in to comment.