| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,7 @@ require ( | |||
| 6 | 6 | github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 | |
| 7 | 7 | github.com/pkg/errors v0.8.1 // indirect | |
| 8 | 8 | github.com/stretchr/testify v1.3.0 | |
| 9 | + go.coder.com/cli v0.1.0 | ||
| 9 | 10 | go.coder.com/flog v0.0.0-20190129195112-eaed154a0db8 | |
| 10 | 11 | go.coder.com/retry v0.0.0-20180926062817-cf12c95974ac | |
| 11 | 12 | golang.org/x/crypto v0.0.0-20190422183909-d864b10871cd | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17,6 +17,8 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ | |||
| 17 | 17 | github.com/stretchr/testify v1.1.4/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= | |
| 18 | 18 | github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q= | |
| 19 | 19 | github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= | |
| 20 | + go.coder.com/cli v0.1.0 h1:ZAjpjXJxMnwj1TqXUi7nnXXuxiPRfwfoC2kViN93oMM= | ||
| 21 | + go.coder.com/cli v0.1.0/go.mod h1:pbVagI9YH/HHMManxPFML4P527GDREwsb+yciZ7mtB8= | ||
| 20 | 22 | go.coder.com/flog v0.0.0-20190129195112-eaed154a0db8 h1:PtQ3moPi4EAz3cyQhkUs1IGIXa2QgJpP60yMjOdu0kk= | |
| 21 | 23 | go.coder.com/flog v0.0.0-20190129195112-eaed154a0db8/go.mod h1:83JsYgXYv0EOaXjIMnaZ1Fl6ddNB3fJnDZ/8845mUJ8= | |
| 22 | 24 | go.coder.com/retry v0.0.0-20180926062817-cf12c95974ac h1:ekdpsuykRy/E+SDq5BquFomNhRCk8OOyhtnACW9Bi50= | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,9 +6,9 @@ import ( | |||
| 6 | 6 | "math/rand" | |
| 7 | 7 | "os" | |
| 8 | 8 | "strings" | |
| 9 | - "text/tabwriter" | ||
| 10 | 9 | "time" | |
| 11 | 10 | ||
| 11 | + "go.coder.com/cli" | ||
| 12 | 12 | "go.coder.com/flog" | |
| 13 | 13 | ) | |
| 14 | 14 | ||
@@ -18,98 +18,91 @@ func init() { | |||
| 18 | 18 | ||
| 19 | 19 | const helpTabWidth = 5 | |
| 20 | 20 | ||
| 21 | - var helpTab = strings.Repeat(" ", helpTabWidth) | ||
| 22 | - | ||
| 23 | - // version is overwritten by ci/build.sh. | ||
| 24 | - var version string | ||
| 21 | + var ( | ||
| 22 | + helpTab = strings.Repeat(" ", helpTabWidth) | ||
| 23 | + // version is overwritten by ci/build.sh. | ||
| 24 | + version string | ||
| 25 | + ) | ||
| 25 | 26 | ||
| 26 | 27 | func main() { | |
| 27 | - var ( | ||
| 28 | - skipSyncFlag = flag.Bool("skipsync", false, "skip syncing local settings and extensions to remote host") | ||
| 29 | - sshFlags = flag.String("ssh-flags", "", "custom SSH flags") | ||
| 30 | - syncBack = flag.Bool("b", false, "sync extensions back on termination") | ||
| 31 | - printVersion = flag.Bool("version", false, "print version information and exit") | ||
| 32 | - ) | ||
| 28 | + cli.RunRoot(&rootCmd{}) | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + var _ interface { | ||
| 32 | + cli.Command | ||
| 33 | + cli.FlaggedCommand | ||
| 34 | + } = new(rootCmd) | ||
| 33 | 35 | ||
| 34 | - flag.Usage = usage | ||
| 36 | + type rootCmd struct { | ||
| 37 | + skipSync bool | ||
| 38 | + syncBack bool | ||
| 39 | + printVersion bool | ||
| 40 | + sshFlags string | ||
| 41 | + } | ||
| 42 | + | ||
| 43 | + func (c *rootCmd) Spec() cli.CommandSpec { | ||
| 44 | + return cli.CommandSpec{ | ||
| 45 | + Name: "sshcode", | ||
| 46 | + Usage: c.usage(), | ||
| 47 | + Desc: c.description(), | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + func (c *rootCmd) RegisterFlags(fl *flag.FlagSet) { | ||
| 52 | + fl.BoolVar(&c.skipSync, "skipsync", false, "skip syncing local settings and extensions to remote host") | ||
| 53 | + fl.BoolVar(&c.syncBack, "b", false, "sync extensions back on termination") | ||
| 54 | + fl.BoolVar(&c.printVersion, "version", false, "print version information and exit") | ||
| 55 | + fl.StringVar(&c.sshFlags, "ssh-flags", "", "custom SSH flags") | ||
| 56 | + } | ||
| 35 | 57 | ||
| 36 | - flag.Parse() | ||
| 37 | - if *printVersion { | ||
| 58 | + func (c *rootCmd) Run(fl *flag.FlagSet) { | ||
| 59 | + if c.printVersion { | ||
| 38 | 60 | fmt.Printf("%v\n", version) | |
| 39 | 61 | os.Exit(0) | |
| 40 | 62 | } | |
| 41 | 63 | ||
| 42 | - host := flag.Arg(0) | ||
| 43 | - | ||
| 64 | + host := fl.Arg(0) | ||
| 44 | 65 | if host == "" { | |
| 45 | 66 | // If no host is specified output the usage. | |
| 46 | - flag.Usage() | ||
| 67 | + fl.Usage() | ||
| 47 | 68 | os.Exit(1) | |
| 48 | 69 | } | |
| 49 | 70 | ||
| 50 | - dir := flag.Arg(1) | ||
| 71 | + dir := fl.Arg(1) | ||
| 51 | 72 | if dir == "" { | |
| 52 | 73 | dir = "~" | |
| 53 | 74 | } | |
| 54 | 75 | ||
| 55 | 76 | err := sshCode(host, dir, options{ | |
| 56 | - skipSync: *skipSyncFlag, | ||
| 57 | - sshFlags: *sshFlags, | ||
| 58 | - syncBack: *syncBack, | ||
| 77 | + skipSync: c.skipSync, | ||
| 78 | + sshFlags: c.sshFlags, | ||
| 79 | + syncBack: c.syncBack, | ||
| 59 | 80 | }) | |
| 60 | 81 | ||
| 61 | 82 | if err != nil { | |
| 62 | 83 | flog.Fatal("error: %v", err) | |
| 63 | 84 | } | |
| 64 | 85 | } | |
| 65 | 86 | ||
| 66 | - func usage() { | ||
| 67 | - fmt.Printf(`Usage: %v [FLAGS] HOST [DIR] | ||
| 68 | - Start VS Code via code-server over SSH. | ||
| 87 | + func (c *rootCmd) usage() string { | ||
| 88 | + return "[FLAGS] HOST [DIR]" | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + func (c *rootCmd) description() string { | ||
| 92 | + return fmt.Sprintf(`Start VS Code via code-server over SSH. | ||
| 69 | 93 | ||
| 70 | 94 | Environment variables: | |
| 71 | - %v use special VS Code settings dir. | ||
| 72 | - %v use special VS Code extensions dir. | ||
| 95 | + %v%v use special VS Code settings dir. | ||
| 96 | + %v%v use special VS Code extensions dir. | ||
| 73 | 97 | ||
| 74 | 98 | More info: https://github.com/cdr/sshcode | |
| 75 | 99 | ||
| 76 | 100 | Arguments: | |
| 77 | 101 | %vHOST is passed into the ssh command. Valid formats are '<ip-address>' or 'gcp:<instance-name>'. | |
| 78 | - %vDIR is optional. | ||
| 79 | - | ||
| 80 | - %v`, | ||
| 81 | - os.Args[0], | ||
| 82 | - vsCodeConfigDirEnv, | ||
| 83 | - vsCodeExtensionsDirEnv, | ||
| 102 | + %vDIR is optional.`, | ||
| 103 | + helpTab, vsCodeConfigDirEnv, | ||
| 104 | + helpTab, vsCodeExtensionsDirEnv, | ||
| 84 | 105 | helpTab, | |
| 85 | 106 | helpTab, | |
| 86 | - flagHelp(), | ||
| 87 | 107 | ) | |
| 88 | - | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - // flagHelp generates a friendly help string for all globally registered command | ||
| 92 | - // line flags. | ||
| 93 | - func flagHelp() string { | ||
| 94 | - var bd strings.Builder | ||
| 95 | - | ||
| 96 | - w := tabwriter.NewWriter(&bd, 3, 10, helpTabWidth, ' ', 0) | ||
| 97 | - | ||
| 98 | - fmt.Fprintf(w, "Flags:\n") | ||
| 99 | - var count int | ||
| 100 | - flag.VisitAll(func(f *flag.Flag) { | ||
| 101 | - count++ | ||
| 102 | - if f.DefValue == "" { | ||
| 103 | - fmt.Fprintf(w, "\t-%v\t%v\n", f.Name, f.Usage) | ||
| 104 | - } else { | ||
| 105 | - fmt.Fprintf(w, "\t-%v\t%v\t(%v)\n", f.Name, f.Usage, f.DefValue) | ||
| 106 | - } | ||
| 107 | - }) | ||
| 108 | - if count == 0 { | ||
| 109 | - return "\n" | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - w.Flush() | ||
| 113 | - | ||
| 114 | - return bd.String() | ||
| 115 | 108 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments