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

Commit 7d359fc

Browse files
committed
Update help and auto-generate flag help
Resolves #37
1 parent 302943d commit 7d359fc

File tree

1 file changed

+39
-4
lines changed

1 file changed

+39
-4
lines changed

main.go

+39-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"runtime"
1515
"strconv"
1616
"strings"
17+
"text/tabwriter"
1718
"time"
1819

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

29+
const helpTabWidth = 5
30+
31+
var helpTab = strings.Repeat(" ", helpTabWidth)
32+
33+
// flagHelp generates a friendly help string for all globally registered command
34+
// line flags.
35+
func flagHelp() string {
36+
var bd strings.Builder
37+
38+
w := tabwriter.NewWriter(&bd, 3, 10, helpTabWidth, ' ', 0)
39+
40+
fmt.Fprintf(w, "Flags:\n")
41+
var count int
42+
flag.VisitAll(func(f *flag.Flag) {
43+
count++
44+
if f.DefValue == "" {
45+
fmt.Fprintf(w, "\t-%v\t%v\n", f.Name, f.Usage)
46+
} else {
47+
fmt.Fprintf(w, "\t-%v\t%v\t(%v)\n", f.Name, f.Usage, f.DefValue)
48+
}
49+
})
50+
if count == 0 {
51+
return "\n"
52+
}
53+
54+
w.Flush()
55+
56+
return bd.String()
57+
}
58+
2859
func main() {
2960
var (
3061
skipSyncFlag = flag.Bool("skipsync", false, "skip syncing local settings and extensions to remote host")
@@ -33,11 +64,15 @@ func main() {
3364
)
3465

3566
flag.Usage = func() {
36-
fmt.Printf(`Usage: [-skipsync] %v HOST [DIR] [SSH ARGS...]
37-
38-
Start code-server over SSH.
67+
fmt.Printf(`Usage: %v [FLAGS] HOST [DIR]
68+
Start VS Code via code-server over SSH.
3969
More info: https://github.com/codercom/sshcode
40-
`, os.Args[0],
70+
71+
Arguments:
72+
`+helpTab+`HOST is passed into the ssh command.
73+
`+helpTab+`DIR is optional.
74+
75+
%v`, os.Args[0], flagHelp(),
4176
)
4277
}
4378

0 commit comments

Comments
 (0)