mirror of
https://github.com/thegeeklab/wp-opentofu.git
synced 2024-11-24 13:20:39 +00:00
fix: add back parsing for fmt_option and init_option (#13)
This commit is contained in:
parent
641b83d579
commit
4aa972e38e
@ -19,15 +19,15 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "init-options",
|
||||
Name: "init-option",
|
||||
Usage: "tofu init command options, see https://opentofu.org/docs/cli/commands/init/",
|
||||
EnvVars: []string{"PLUGIN_INIT_OPTIONS"},
|
||||
EnvVars: []string{"PLUGIN_INIT_OPTION"},
|
||||
Category: category,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "fmt-options",
|
||||
Name: "fmt-option",
|
||||
Usage: "options for the fmt command, see https://opentofu.org/docs/cli/commands/fmt/",
|
||||
EnvVars: []string{"PLUGIN_FMT_OPTIONS"},
|
||||
EnvVars: []string{"PLUGIN_FMT_OPTION"},
|
||||
Category: category,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
|
@ -7,13 +7,13 @@ properties:
|
||||
defaultValue: "validate,plan,apply"
|
||||
required: false
|
||||
|
||||
- name: fmt_options
|
||||
- name: fmt_option
|
||||
description: |
|
||||
Options for the fmt command, see the OpenTofu [fmt command](https://opentofu.org/docs/cli/commands/fmt/) documentation.
|
||||
type: string
|
||||
required: false
|
||||
|
||||
- name: init_options
|
||||
- name: init_option
|
||||
description: |
|
||||
Tofu init command options, see the OpenTofu [init command](https://opentofu.org/docs/cli/commands/init/) documentation.
|
||||
type: string
|
||||
|
@ -2,6 +2,7 @@ package plugin
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -24,6 +25,10 @@ const (
|
||||
|
||||
//nolint:revive
|
||||
func (p *Plugin) run(ctx context.Context) error {
|
||||
if err := p.FlagsFromContext(); err != nil {
|
||||
return fmt.Errorf("validation failed: %w", err)
|
||||
}
|
||||
|
||||
if err := p.Validate(); err != nil {
|
||||
return fmt.Errorf("validation failed: %w", err)
|
||||
}
|
||||
@ -35,6 +40,28 @@ func (p *Plugin) run(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Plugin) FlagsFromContext() error {
|
||||
if p.Context.String("init-option") != "" {
|
||||
initOptions := InitOptions{}
|
||||
if err := json.Unmarshal([]byte(p.Context.String("init-option")), &initOptions); err != nil {
|
||||
return fmt.Errorf("cannot unmarshal init_option: %w", err)
|
||||
}
|
||||
|
||||
p.Settings.InitOptions = initOptions
|
||||
}
|
||||
|
||||
if p.Context.String("fmt-option") != "" {
|
||||
fmtOptions := FmtOptions{}
|
||||
if err := json.Unmarshal([]byte(p.Context.String("fmt-option")), &fmtOptions); err != nil {
|
||||
return fmt.Errorf("cannot unmarshal fmt_option: %w", err)
|
||||
}
|
||||
|
||||
p.Settings.FmtOptions = fmtOptions
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Validate handles the settings validation of the plugin.
|
||||
func (p *Plugin) Validate() error {
|
||||
p.Settings.DataDir = ".terraform"
|
||||
|
Loading…
Reference in New Issue
Block a user