mirror of
https://github.com/thegeeklab/wp-opentofu.git
synced 2024-11-22 00:30:40 +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,
|
Category: category,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "init-options",
|
Name: "init-option",
|
||||||
Usage: "tofu init command options, see https://opentofu.org/docs/cli/commands/init/",
|
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,
|
Category: category,
|
||||||
},
|
},
|
||||||
&cli.StringFlag{
|
&cli.StringFlag{
|
||||||
Name: "fmt-options",
|
Name: "fmt-option",
|
||||||
Usage: "options for the fmt command, see https://opentofu.org/docs/cli/commands/fmt/",
|
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,
|
Category: category,
|
||||||
},
|
},
|
||||||
&cli.IntFlag{
|
&cli.IntFlag{
|
||||||
|
@ -7,13 +7,13 @@ properties:
|
|||||||
defaultValue: "validate,plan,apply"
|
defaultValue: "validate,plan,apply"
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
- name: fmt_options
|
- name: fmt_option
|
||||||
description: |
|
description: |
|
||||||
Options for the fmt command, see the OpenTofu [fmt command](https://opentofu.org/docs/cli/commands/fmt/) documentation.
|
Options for the fmt command, see the OpenTofu [fmt command](https://opentofu.org/docs/cli/commands/fmt/) documentation.
|
||||||
type: string
|
type: string
|
||||||
required: false
|
required: false
|
||||||
|
|
||||||
- name: init_options
|
- name: init_option
|
||||||
description: |
|
description: |
|
||||||
Tofu init command options, see the OpenTofu [init command](https://opentofu.org/docs/cli/commands/init/) documentation.
|
Tofu init command options, see the OpenTofu [init command](https://opentofu.org/docs/cli/commands/init/) documentation.
|
||||||
type: string
|
type: string
|
||||||
|
@ -2,6 +2,7 @@ package plugin
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -24,6 +25,10 @@ const (
|
|||||||
|
|
||||||
//nolint:revive
|
//nolint:revive
|
||||||
func (p *Plugin) run(ctx context.Context) error {
|
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 {
|
if err := p.Validate(); err != nil {
|
||||||
return fmt.Errorf("validation failed: %w", err)
|
return fmt.Errorf("validation failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -35,6 +40,28 @@ func (p *Plugin) run(ctx context.Context) error {
|
|||||||
return nil
|
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.
|
// Validate handles the settings validation of the plugin.
|
||||||
func (p *Plugin) Validate() error {
|
func (p *Plugin) Validate() error {
|
||||||
p.Settings.DataDir = ".terraform"
|
p.Settings.DataDir = ".terraform"
|
||||||
|
Loading…
Reference in New Issue
Block a user