Skip to content

Commit 2ca3f90

Browse files
NikhilSharmaWealexellis
authored andcommitted
add new build flag in local-run command
Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
1 parent 0b1e92b commit 2ca3f90

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

commands/local_run.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ type runOptions struct {
2727
extraEnv map[string]string
2828
output io.Writer
2929
err io.Writer
30+
build bool
3031
}
3132

3233
func newLocalRunCmd() *cobra.Command {
3334
opts := runOptions{}
3435

3536
cmd := &cobra.Command{
36-
Use: `local-run NAME --port PORT -f YAML_FILE`,
37+
Use: `local-run NAME --port PORT -f YAML_FILE [flags from build]`,
3738
Short: "Start a function with docker for local testing (experimental feature)",
3839
Long: `Providing faas-cli build has already been run, this command will use the
3940
docker command to start a container on your local machine using its image.
@@ -62,6 +63,13 @@ services deployed within your OpenFaaS cluster.`,
6263
if len(args) > 1 {
6364
return fmt.Errorf("only one function name is allowed")
6465
}
66+
67+
if opts.build {
68+
if err := localBuild(cmd, args); err != nil {
69+
return err
70+
}
71+
}
72+
6573
return nil
6674
},
6775
RunE: func(cmd *cobra.Command, args []string) error {
@@ -82,13 +90,29 @@ services deployed within your OpenFaaS cluster.`,
8290
}
8391

8492
cmd.Flags().BoolVar(&opts.print, "print", false, "Print the docker command instead of running it")
93+
cmd.Flags().BoolVar(&opts.build, "build", true, "Build function prior to local-run")
8594
cmd.Flags().IntVarP(&opts.port, "port", "p", 8080, "port to bind the function to")
8695
cmd.Flags().StringVar(&opts.network, "network", "", "connect function to an existing network, use 'host' to access other process already running on localhost. When using this, '--port' is ignored, if you have port collisions, you may change the port using '-e port=NEW_PORT'")
8796
cmd.Flags().StringToStringVarP(&opts.extraEnv, "env", "e", map[string]string{}, "additional environment variables (ENVVAR=VALUE), use this to experiment with different values for your function")
8897

98+
build, _, _ := faasCmd.Find([]string{"build"})
99+
cmd.Flags().AddFlagSet(build.Flags())
100+
89101
return cmd
90102
}
91103

104+
func localBuild(cmd *cobra.Command, args []string) error {
105+
if err := preRunBuild(cmd, args); err != nil {
106+
return err
107+
}
108+
109+
if err := runBuild(cmd, args); err != nil {
110+
return err
111+
}
112+
113+
return nil
114+
}
115+
92116
func runFunction(ctx context.Context, name string, opts runOptions, args []string) error {
93117
var services *stack.Services
94118

0 commit comments

Comments
 (0)