Skip to content
This repository was archived by the owner on Jan 17, 2021. It is now read-only.

Update help and auto-generate flag help #38

Merged
merged 1 commit into from
Apr 22, 2019
Merged
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
43 changes: 39 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"runtime"
"strconv"
"strings"
"text/tabwriter"
"time"

"github.com/pkg/browser"
Expand All @@ -25,6 +26,36 @@ func init() {
rand.Seed(time.Now().Unix())
}

const helpTabWidth = 5

var helpTab = strings.Repeat(" ", helpTabWidth)

// flagHelp generates a friendly help string for all globally registered command
// line flags.
func flagHelp() string {
var bd strings.Builder

w := tabwriter.NewWriter(&bd, 3, 10, helpTabWidth, ' ', 0)

fmt.Fprintf(w, "Flags:\n")
var count int
flag.VisitAll(func(f *flag.Flag) {
count++
if f.DefValue == "" {
fmt.Fprintf(w, "\t-%v\t%v\n", f.Name, f.Usage)
} else {
fmt.Fprintf(w, "\t-%v\t%v\t(%v)\n", f.Name, f.Usage, f.DefValue)
}
})
if count == 0 {
return "\n"
}

w.Flush()

return bd.String()
}

func main() {
var (
skipSyncFlag = flag.Bool("skipsync", false, "skip syncing local settings and extensions to remote host")
Expand All @@ -33,11 +64,15 @@ func main() {
)

flag.Usage = func() {
fmt.Printf(`Usage: [-skipsync] %v HOST [DIR] [SSH ARGS...]

Start code-server over SSH.
fmt.Printf(`Usage: %v [FLAGS] HOST [DIR]
Start VS Code via code-server over SSH.
More info: https://github.com/codercom/sshcode
`, os.Args[0],

Arguments:
`+helpTab+`HOST is passed into the ssh command.
`+helpTab+`DIR is optional.

%v`, os.Args[0], flagHelp(),
)
}

Expand Down