mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
ffe056bacb
This is part of a general effort to move all of Terraform's non-library package surface under internal in order to reinforce that these are for internal use within Terraform only. If you were previously importing packages under this prefix into an external codebase, you could pin to an earlier release tag as an interim solution until you've make a plan to achieve the same functionality some other way.
60 lines
1.4 KiB
Go
60 lines
1.4 KiB
Go
package arguments
|
|
|
|
import (
|
|
"github.com/hashicorp/terraform/internal/tfdiags"
|
|
)
|
|
|
|
// Validate represents the command-line arguments for the validate command.
|
|
type Validate struct {
|
|
// Path is the directory containing the configuration to be validated. If
|
|
// unspecified, validate will use the current directory.
|
|
Path string
|
|
|
|
// ViewType specifies which output format to use: human, JSON, or "raw".
|
|
ViewType ViewType
|
|
}
|
|
|
|
// ParseValidate processes CLI arguments, returning a Validate value and errors.
|
|
// If errors are encountered, a Validate value is still returned representing
|
|
// the best effort interpretation of the arguments.
|
|
func ParseValidate(args []string) (*Validate, tfdiags.Diagnostics) {
|
|
var diags tfdiags.Diagnostics
|
|
validate := &Validate{
|
|
Path: ".",
|
|
}
|
|
|
|
var jsonOutput bool
|
|
cmdFlags := defaultFlagSet("validate")
|
|
cmdFlags.BoolVar(&jsonOutput, "json", false, "json")
|
|
|
|
if err := cmdFlags.Parse(args); err != nil {
|
|
diags = diags.Append(tfdiags.Sourceless(
|
|
tfdiags.Error,
|
|
"Failed to parse command-line flags",
|
|
err.Error(),
|
|
))
|
|
}
|
|
|
|
args = cmdFlags.Args()
|
|
if len(args) > 1 {
|
|
diags = diags.Append(tfdiags.Sourceless(
|
|
tfdiags.Error,
|
|
"Too many command line arguments",
|
|
"Expected at most one positional argument.",
|
|
))
|
|
}
|
|
|
|
if len(args) > 0 {
|
|
validate.Path = args[0]
|
|
}
|
|
|
|
switch {
|
|
case jsonOutput:
|
|
validate.ViewType = ViewJSON
|
|
default:
|
|
validate.ViewType = ViewHuman
|
|
}
|
|
|
|
return validate, diags
|
|
}
|