From 8069ae4f4397a8f2437737f8061bb43d281f818a Mon Sep 17 00:00:00 2001 From: Wilken Rivera Date: Tue, 15 Sep 2020 10:19:56 -0400 Subject: [PATCH] Add flagset to init command --- command/cli.go | 13 +++++++++++++ command/init.go | 17 +++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/command/cli.go b/command/cli.go index fbf95dca1..a7c2d36cc 100644 --- a/command/cli.go +++ b/command/cli.go @@ -142,3 +142,16 @@ type HCL2UpgradeArgs struct { MetaArgs OutputFile string } + +func (ia *InitArgs) AddFlagSets(flags *flag.FlagSet) { + flags.StringVar(&ia.PluginDir, "plugin-dir", "", "") + flags.BoolVar(&ia.GetPlugins, "get-plugins", true, "") + ia.MetaArgs.AddFlagSets(flags) +} + +//InitArgs respresents a parsed cli line for packer init +type InitArgs struct { + MetaArgs + PluginDir string + GetPlugins bool +} diff --git a/command/init.go b/command/init.go index aa6e9ed92..74fa2310c 100644 --- a/command/init.go +++ b/command/init.go @@ -26,7 +26,7 @@ func (c *InitCommand) Run(args []string) int { func (c *InitCommand) ParseArgs(args []string) (*InitArgs, int) { var cfg InitArgs - flags := c.Meta.FlagSet("init", FlagSetNone) + flags := c.Meta.FlagSet("init", FlagSetVars) flags.Usage = func() { c.Ui.Say(c.Help()) } cfg.AddFlagSets(flags) if err := flags.Parse(args); err != nil { @@ -39,7 +39,7 @@ func (c *InitCommand) ParseArgs(args []string) (*InitArgs, int) { func (c *InitCommand) RunContext(ctx context.Context, cla *InitArgs) int { fmt.Printf(`%s -Packer initialized in an empty directory! +Packer initialized with no template! The directory has no Packer templates. You may begin working with Packer immediately by creating a Packer template. @@ -58,18 +58,19 @@ Usage: packer init [options] This is the first command that should be executed when working with a new or existing template. Running this command in an empty directory will will perform no operation, and will need to be executed once a template - has been added to the directory to initialize the working directory. + has been created to initialize the working directory. - It is safe to run init multiple times within a given directory. + It is safe to run init multiple times on a template to update the builders, + provisioners, post-processors with changes in the template configuration file. + +Options: + -get-plugins=false Skips plugin installation. + -plugin-dir=PATH Skips plugin installation and loads plugins only from the specified directory. ` return helpText } -type InitArgs struct { - MetaArgs -} - func (c *InitCommand) Synopsis() string { return "Initializes a Packer working directory" }