Add flagset to init command

poc/packer-init
Wilken Rivera 6 years ago
parent e8f7076416
commit 8069ae4f43

@ -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
}

@ -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"
}

Loading…
Cancel
Save