@@ -13,7 +13,9 @@ import (
1313)
1414
1515func NewCodeCmd () * cobra.Command {
16- return & cobra.Command {
16+ useInsiders := false
17+
18+ codeCmd := & cobra.Command {
1719 Use : "code [<codespace>]" ,
1820 Short : "Open a Codespace in VS Code" ,
1921 Args : cobra .MaximumNArgs (1 ),
@@ -22,16 +24,20 @@ func NewCodeCmd() *cobra.Command {
2224 if len (args ) > 0 {
2325 codespaceName = args [0 ]
2426 }
25- return Code (codespaceName )
27+ return Code (codespaceName , useInsiders )
2628 },
2729 }
30+
31+ codeCmd .Flags ().BoolVar (& useInsiders , "insiders" , false , "Use the insiders version of VS Code" )
32+
33+ return codeCmd
2834}
2935
3036func init () {
3137 rootCmd .AddCommand (NewCodeCmd ())
3238}
3339
34- func Code (codespaceName string ) error {
40+ func Code (codespaceName string , useInsiders bool ) error {
3541 apiClient := api .New (os .Getenv ("GITHUB_TOKEN" ))
3642 ctx := context .Background ()
3743
@@ -51,13 +57,17 @@ func Code(codespaceName string) error {
5157 codespaceName = codespace .Name
5258 }
5359
54- if err := open .Run (vscodeProtocolURL (codespaceName )); err != nil {
60+ if err := open .Run (vscodeProtocolURL (codespaceName , useInsiders )); err != nil {
5561 return fmt .Errorf ("error opening vscode URL" )
5662 }
5763
5864 return nil
5965}
6066
61- func vscodeProtocolURL (codespaceName string ) string {
62- return fmt .Sprintf ("vscode://github.codespaces/connect?name=%s" , url .QueryEscape (codespaceName ))
67+ func vscodeProtocolURL (codespaceName string , useInsiders bool ) string {
68+ application := "vscode"
69+ if useInsiders {
70+ application = "vscode-insiders"
71+ }
72+ return fmt .Sprintf ("%s://github.codespaces/connect?name=%s" , application , url .QueryEscape (codespaceName ))
6373}
0 commit comments