Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/commands/compute/compute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func TestServeFlagDivergence(t *testing.T) {
"env",
"file",
"skip-build",
"viceroy-check",
"viceroy-path",
"watch",
"watch-dir",
Expand Down
18 changes: 16 additions & 2 deletions pkg/commands/compute/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ type ServeCommand struct {
file string
skipBuild bool
viceroyBinPath string
viceroyCheck bool
watch bool
watchDir cmd.OptionalString
}
Expand All @@ -77,6 +78,7 @@ func NewServeCommand(parent cmd.Registerer, g *global.Data, build *BuildCommand,
c.CmdClause.Flag("package-name", "Package name").Action(c.packageName.Set).StringVar(&c.packageName.Value)
c.CmdClause.Flag("skip-build", "Skip the build step").BoolVar(&c.skipBuild)
c.CmdClause.Flag("timeout", "Timeout, in seconds, for the build compilation step").Action(c.timeout.Set).IntVar(&c.timeout.Value)
c.CmdClause.Flag("viceroy-check", "Force the CLI to check for a newer version of the Viceroy binary").BoolVar(&c.viceroyCheck)
c.CmdClause.Flag("viceroy-path", "The path to a user installed version of the Viceroy binary").StringVar(&c.viceroyBinPath)
c.CmdClause.Flag("watch", "Watch for file changes, then rebuild project and restart local server").BoolVar(&c.watch)
c.CmdClause.Flag("watch-dir", "The directory to watch files from (can be relative or absolute). Defaults to current directory.").Action(c.watchDir.Set).StringVar(&c.watchDir.Value)
Expand Down Expand Up @@ -111,7 +113,7 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
return err
}

bin, err := GetViceroy(spinner, out, c.av, c.Globals, c.viceroyBinPath)
bin, err := GetViceroy(spinner, out, c.av, c.Globals, c.viceroyBinPath, c.viceroyCheck)
if err != nil {
return err
}
Expand Down Expand Up @@ -221,6 +223,7 @@ func GetViceroy(
av github.AssetVersioner,
g *global.Data,
viceroyBinPath string,
viceroyCheck bool,
) (bin string, err error) {
if viceroyBinPath != "" {
if g.Verbose() {
Expand Down Expand Up @@ -282,7 +285,7 @@ func GetViceroy(

// The latest_version value 0.0.0 means the property either has not been set
// or is now stale and needs to be refreshed.
if latest.String() == "0.0.0" {
if latest.String() == "0.0.0" || viceroyCheck {
err := spinner.Start()
if err != nil {
return bin, err
Expand Down Expand Up @@ -585,6 +588,17 @@ func local(bin, file, addr, env string, debug, watch bool, watchDir cmd.Optional
text.Output(out, "%s: %s", text.BoldYellow("Manifest"), manifestPath)
text.Output(out, "%s: %s", text.BoldYellow("Wasm binary"), file)
text.Output(out, "%s:\n%s", text.BoldYellow("Viceroy binary"), bin)

// gosec flagged this:
// G204 (CWE-78): Subprocess launched with function call as argument or cmd arguments
// Disabling as we trust the source of the variable.
// #nosec
// nosemgrep: go.lang.security.audit.dangerous-exec-command.dangerous-exec-command
cmd := exec.Command(bin, "--version")
if output, err := cmd.Output(); err == nil {
text.Output(out, "%s:\n%s", text.BoldYellow("Viceroy version"), string(output))
}

args = append(args, "-v")
} else {
// IMPORTANT: Viceroy 0.4.0 changed its INFO log output behind a -v flag.
Expand Down
3 changes: 2 additions & 1 deletion pkg/commands/compute/serve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func TestGetViceroy(t *testing.T) {
t.Fatal(err)
}
viceroyBinPath := "" // --viceroy-path flag for overriding CLI handling the Viceroy checks/downloads.
_, err = compute.GetViceroy(spinner, &out, av, &g, viceroyBinPath)
viceroyCheck := false
_, err = compute.GetViceroy(spinner, &out, av, &g, viceroyBinPath, viceroyCheck)
if err != nil {
t.Fatal(err)
}
Expand Down