@@ -63,10 +63,27 @@ var (
6363 ErrSandboxNeedsUpgrade = errors .New ("The sandbox support needs to be upgraded (use `doctl sandbox upgrade`)" )
6464 // ErrSandboxNotConnected is the error returned to users when the sandbox is not connected to a namespace
6565 ErrSandboxNotConnected = errors .New ("A sandbox is installed but not connected to a function namespace (use `doctl sandbox connect`)" )
66- // ErrUndeployAllAndArgs is the error returned when the --all flag is used along with args on undeploy
66+ // errUndeployAllAndArgs is the error returned when the --all flag is used along with args on undeploy
6767 errUndeployAllAndArgs = errors .New ("command line arguments and the `--all` flag are mutually exclusive" )
68- // ErrUndeployTooFewArgs is the error returned when neither --all nor args are specified on undeploy
68+ // errUndeployTooFewArgs is the error returned when neither --all nor args are specified on undeploy
6969 errUndeployTooFewArgs = errors .New ("either command line arguments or `--all` must be specified" )
70+
71+ // languageKeywords maps the backend's runtime category names to keywords accepted as languages
72+ // Note: this table has all languages for which we possess samples. Only those with currently
73+ // active runtimes will display.
74+ languageKeywords map [string ][]string = map [string ][]string {
75+ "nodejs" : {"javascript" , "js" },
76+ "deno" : {"deno" },
77+ "go" : {"go" , "golang" },
78+ "java" : {"java" },
79+ "php" : {"php" },
80+ "python" : {"python" , "py" },
81+ "ruby" : {"ruby" },
82+ "rust" : {"rust" },
83+ "swift" : {"swift" },
84+ "dotnet" : {"csharp" , "cs" },
85+ "typescript" : {"typescript" , "ts" },
86+ }
7087)
7188
7289// Sandbox contains support for 'sandbox' commands provided by a hidden install of the Nimbella CLI
@@ -226,14 +243,38 @@ func RunSandboxStatus(c *CmdConfig) error {
226243 return errors .New ("Could not retrieve information about the connected namespace" )
227244 }
228245 mapResult := result .Entity .(map [string ]interface {})
229- fmt .Fprintf (c .Out , "Connected to function namespace '%s' on API host '%s'\n " , mapResult ["name" ], mapResult ["apihost" ])
246+ apiHost := mapResult ["apihost" ].(string )
247+ fmt .Fprintf (c .Out , "Connected to function namespace '%s' on API host '%s'\n " , mapResult ["name" ], apiHost )
230248 fmt .Fprintf (c .Out , "Sandbox version is %s\n \n " , minSandboxVersion )
231- displayRuntimes , _ := c .Doit .GetBool (c .NS , "languages" )
232- if displayRuntimes {
233- result , err = SandboxExec (c , "info" , "--runtimes" )
234- if result .Error == "" && err == nil {
235- fmt .Fprintf (c .Out , "Available runtimes:\n " )
236- c .PrintSandboxTextOutput (result )
249+ languages , _ := c .Doit .GetBool (c .NS , "languages" )
250+ if languages {
251+ return showLanguageInfo (c , apiHost )
252+ }
253+ return nil
254+ }
255+
256+ // showLanguageInfo is called by RunSandboxStatus when --languages is specified
257+ func showLanguageInfo (c * CmdConfig , APIHost string ) error {
258+ info , err := c .Sandbox ().GetHostInfo (APIHost )
259+ if err != nil {
260+ return err
261+ }
262+ fmt .Fprintf (c .Out , "Supported Languages:\n " )
263+ for language := range info .Runtimes {
264+ fmt .Fprintf (c .Out , "%s:\n " , language )
265+ keywords := strings .Join (languageKeywords [language ], ", " )
266+ fmt .Fprintf (c .Out , " Keywords: %s\n " , keywords )
267+ fmt .Fprintf (c .Out , " Runtime versions:\n " )
268+ runtimes := info .Runtimes [language ]
269+ for _ , runtime := range runtimes {
270+ tag := ""
271+ if runtime .Default {
272+ tag = fmt .Sprintf (" (%s:default)" , language )
273+ }
274+ if runtime .Deprecated {
275+ tag = " (deprecated)"
276+ }
277+ fmt .Fprintf (c .Out , " %s%s\n " , runtime .Kind , tag )
237278 }
238279 }
239280 return nil
0 commit comments