Skip to content

Commit ad28c1a

Browse files
Add version info to 'sandbox status' (#1158)
1 parent 408d875 commit ad28c1a

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

commands/sandbox.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ The install operation is long-running, and a network connection is required.`,
104104
`This command reports the status of your sandbox and some details concerning its connected cloud portion.
105105
With the `+"`"+`--languages flag, it will report the supported languages.`, Writer)
106106
AddBoolFlag(status, "languages", "l", false, "show available languages (if connected to the cloud)")
107+
AddBoolFlag(status, "version", "", false, "just show the version, don't check status")
107108

108109
undeploy := CmdBuilder(cmd, RunSandboxUndeploy, "undeploy [<package|function>...]",
109110
"Removes resources from the cloud portion of your sandbox",
@@ -195,7 +196,21 @@ func RunSandboxConnect(c *CmdConfig) error {
195196
// RunSandboxStatus gives a report on the status of the sandbox (installed, up to date, connected)
196197
func RunSandboxStatus(c *CmdConfig) error {
197198
status := c.checkSandboxStatus(c)
198-
if status == ErrSandboxNeedsUpgrade || status == ErrSandboxNotInstalled || status == ErrSandboxNotConnected {
199+
if status == ErrSandboxNotInstalled {
200+
return status
201+
}
202+
version, _ := c.Doit.GetBool(c.NS, "version")
203+
if version {
204+
if status == ErrSandboxNeedsUpgrade {
205+
sandboxDir, _ := getSandboxDirectory() // we know it exists
206+
currentVersion := getCurrentSandboxVersion(sandboxDir)
207+
fmt.Fprintf(c.Out, "Current: %s, required: %s\n", currentVersion, getMinSandboxVersion())
208+
return nil
209+
}
210+
fmt.Fprintln(c.Out, getMinSandboxVersion())
211+
return nil
212+
}
213+
if status == ErrSandboxNeedsUpgrade || status == ErrSandboxNotConnected {
199214
return status
200215
}
201216
if status != nil {
@@ -211,7 +226,8 @@ func RunSandboxStatus(c *CmdConfig) error {
211226
return errors.New("Could not retrieve information about the connected namespace")
212227
}
213228
mapResult := result.Entity.(map[string]interface{})
214-
fmt.Fprintf(c.Out, "Connected to function namespace '%s' on API host '%s'\n\n", mapResult["name"], mapResult["apihost"])
229+
fmt.Fprintf(c.Out, "Connected to function namespace '%s' on API host '%s'\n", mapResult["name"], mapResult["apihost"])
230+
fmt.Fprintf(c.Out, "Sandbox version is %s\n\n", minSandboxVersion)
215231
displayRuntimes, _ := c.Doit.GetBool(c.NS, "languages")
216232
if displayRuntimes {
217233
result, err = SandboxExec(c, "info", "--runtimes")

commands/sandbox_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func TestSandboxStatusWhenConnected(t *testing.T) {
6969

7070
err := RunSandboxStatus(config)
7171
require.NoError(t, err)
72-
assert.Equal(t, "Connected to function namespace 'hello' on API host 'https://api.example.com'\n\n", buf.String())
72+
assert.Contains(t, buf.String(), "Connected to function namespace 'hello' on API host 'https://api.example.com'\nSandbox version is")
7373
})
7474
}
7575

0 commit comments

Comments
 (0)