Skip to content

Commit

Permalink
Allow to pass arbitrary arguments to Viceroy
Browse files Browse the repository at this point in the history
This is done via the --viceroy-args parameter, e.g.,

fastly compute serve \
  --viceroy-args="--unknown-import-behavior=zero-or-null"
  • Loading branch information
fgsch committed Apr 23, 2024
1 parent 9f33315 commit bb08f01
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 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 @@ -104,6 +104,7 @@ func TestFlagDivergenceServe(t *testing.T) {
"profile-guest",
"profile-guest-dir",
"skip-build",
"viceroy-args",
"viceroy-check",
"viceroy-path",
"watch",
Expand Down
9 changes: 9 additions & 0 deletions pkg/commands/compute/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type ServeCommand struct {

// Serve public fields (public for testing purposes)
ForceCheckViceroyLatest bool
ViceroyBinExtraArgs string
ViceroyBinPath string
ViceroyVersioner github.AssetVersioner

Expand Down Expand Up @@ -95,6 +96,7 @@ func NewServeCommand(parent argparser.Registerer, g *global.Data, build *BuildCo
c.CmdClause.Flag("profile-guest-dir", "The directory where the per-request profiles are saved to. Defaults to guest-profiles.").Action(c.profileGuestDir.Set).StringVar(&c.profileGuestDir.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-args", "Additional arguments to pass to the Viceroy binary, separated by space").StringVar(&c.ViceroyBinExtraArgs)
c.CmdClause.Flag("viceroy-check", "Force the CLI to check for a newer version of the Viceroy binary").BoolVar(&c.ForceCheckViceroyLatest)
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)
Expand Down Expand Up @@ -207,6 +209,7 @@ func (c *ServeCommand) Exec(in io.Reader, out io.Writer) (err error) {
bin: bin,
debug: c.debug,
errLog: c.Globals.ErrLog,
extraArgs: c.ViceroyBinExtraArgs,
file: c.file,
manifestPath: manifestPath,
out: out,
Expand Down Expand Up @@ -544,6 +547,7 @@ type localOpts struct {
bin string
debug bool
errLog fsterr.LogInterface
extraArgs string
file string
manifestPath string
out io.Writer
Expand Down Expand Up @@ -577,6 +581,11 @@ func local(opts localOpts) error {
}
}

if opts.extraArgs != "" {
extraArgs := strings.Split(opts.extraArgs, " ")
args = append(args, extraArgs...)
}

if opts.verbose {
if opts.restarted {
text.Break(opts.out)
Expand Down

0 comments on commit bb08f01

Please sign in to comment.