github.com/pluralsh/plural-cli@v0.9.5/cmd/plural/shell.go (about) 1 package plural 2 3 import ( 4 "os" 5 6 "github.com/pluralsh/plural-cli/pkg/api" 7 "github.com/pluralsh/plural-cli/pkg/config" 8 "github.com/pluralsh/plural-cli/pkg/crypto" 9 "github.com/pluralsh/plural-cli/pkg/utils" 10 "github.com/pluralsh/plural-cli/pkg/utils/git" 11 "github.com/urfave/cli" 12 ) 13 14 func shellCommands() []cli.Command { 15 return []cli.Command{ 16 { 17 Name: "sync", 18 Usage: "syncs the setup in your cloud shell locally", 19 Action: latestVersion(handleShellSync), 20 Flags: []cli.Flag{ 21 cli.StringFlag{ 22 Name: "endpoint", 23 Usage: "the endpoint for the plural installation you're working with", 24 }, 25 cli.StringFlag{ 26 Name: "service-account", 27 Usage: "email for the service account you'd like to use for this workspace", 28 }, 29 }, 30 }, 31 { 32 Name: "purge", 33 Usage: "deletes your cloud shell", 34 Action: latestVersion(handleShellPurge), 35 }, 36 } 37 } 38 39 func handleShellSync(c *cli.Context) error { 40 if !config.Exists() { 41 if err := handleLogin(c); err != nil { 42 return err 43 } 44 } 45 client := api.NewClient() 46 47 shell, err := client.GetShell() 48 if err != nil { 49 return api.GetErrorResponse(err, "GetShell") 50 } 51 52 if err := crypto.Setup(shell.AesKey); err != nil { 53 return err 54 } 55 56 utils.Highlight("Cloning your workspace repo locally:\n") 57 if err := utils.Exec("git", "clone", shell.GitUrl); err != nil { 58 return err 59 } 60 61 dir := git.RepoName(shell.GitUrl) 62 if err := os.Chdir(dir); err != nil { 63 return err 64 } 65 if err := cryptoInit(c); err != nil { 66 return err 67 } 68 69 return handleUnlock(c) 70 } 71 72 var destoryShellConfirm = "Are you sure you want to destroy your cloud shell (you should either `plural destroy` anything deployed or `plural shell sync` to sync the contents locally)?" 73 74 func handleShellPurge(c *cli.Context) error { 75 if ok := confirm(destoryShellConfirm, "PLURAL_SHELL_PURGE_CONFIRM"); !ok { 76 return nil 77 } 78 79 client := api.NewClient() 80 err := client.DeleteShell() 81 return api.GetErrorResponse(err, "DeleteShell") 82 }