Skip to content

Commit

Permalink
fix(compute/serve): allow overriding of viceroy binary
Browse files Browse the repository at this point in the history
  • Loading branch information
Integralist committed Mar 7, 2023
1 parent 6e6f68d commit 4ac2203
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
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-path",
"watch",
"watch-dir",
}
Expand Down
33 changes: 24 additions & 9 deletions pkg/commands/compute/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@ type ServeCommand struct {
timeout cmd.OptionalInt

// Serve fields
addr string
debug bool
env cmd.OptionalString
file string
skipBuild bool
watch bool
watchDir cmd.OptionalString
addr string
debug bool
env cmd.OptionalString
file string
skipBuild bool
viceroyBinPath string
watch bool
watchDir cmd.OptionalString
}

// NewServeCommand returns a usable command registered under the parent.
Expand All @@ -76,6 +77,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-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 @@ -109,7 +111,7 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
return err
}

bin, err := GetViceroy(spinner, out, c.av, c.Globals)
bin, err := GetViceroy(spinner, out, c.av, c.Globals, c.viceroyBinPath)
if err != nil {
return err
}
Expand Down Expand Up @@ -215,7 +217,20 @@ func (c *ServeCommand) setBackendsWithDefaultOverrideHostIfMissing(out io.Writer
//
// In the case of a network failure we fallback to the latest installed version of the
// Viceroy binary as long as one is installed and has the correct permissions.
func GetViceroy(spinner text.Spinner, out io.Writer, av github.AssetVersioner, g *global.Data) (bin string, err error) {
func GetViceroy(
spinner text.Spinner,
out io.Writer,
av github.AssetVersioner,
g *global.Data,
viceroyBinPath string,
) (bin string, err error) {
if viceroyBinPath != "" {
if g.Verbose() {
text.Info(out, "Using user provided install of Viceroy: %s", viceroyBinPath)
text.Break(out)
}
return filepath.Abs(viceroyBinPath)
}
bin = filepath.Join(InstallDir, av.BinaryName())

// NOTE: When checking if Viceroy is installed we don't use
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 @@ -95,7 +95,8 @@ func TestGetViceroy(t *testing.T) {
if err != nil {
t.Fatal(err)
}
_, err = compute.GetViceroy(spinner, &out, av, &g)
viceroyBinPath := "" // --viceroy-path flag for overriding CLI handling the Viceroy checks/downloads.
_, err = compute.GetViceroy(spinner, &out, av, &g, viceroyBinPath)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit 4ac2203

Please sign in to comment.