Skip to content

Commit

Permalink
validate: Default provider name to base directory when running `valid…
Browse files Browse the repository at this point in the history
…ate` (#377)

* fix

* addd changelog

* add comment to --provider-name argument
  • Loading branch information
austinvalle authored May 24, 2024
1 parent 56ab54b commit 7f32d68
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changes/unreleased/BUG FIXES-20240524-122908.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: BUG FIXES
body: 'validate: Fixed issue with provider name not defaulting to directory'
time: 2024-05-24T12:29:08.506286-04:00
custom:
Issue: "376"
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Usage: tfplugindocs generate [<args>]
--examples-dir <ARG> examples directory based on provider-dir (default: "examples")
--ignore-deprecated <ARG> don't generate documentation for deprecated resources and data-sources (default: "false")
--provider-dir <ARG> relative or absolute path to the root provider code directory when running the command outside the root provider code directory
--provider-name <ARG> provider name, as used in Terraform configurations
--provider-name <ARG> provider name, as used in Terraform configurations; defaults to the --provider-dir short name (after removing `terraform-provider-` prefix)
--providers-schema <ARG> path to the providers schema JSON file, which contains the output of the terraform providers schema -json command. Setting this flag will skip building the provider and calling Terraform CLI
--rendered-provider-name <ARG> provider name, as generated in documentation (ex. page titles, ...)
--rendered-website-dir <ARG> output directory based on provider-dir (default: "docs")
Expand All @@ -83,7 +83,7 @@ $ tfplugindocs validate --help
Usage: tfplugindocs validate [<args>]
--provider-dir <ARG> relative or absolute path to the root provider code directory; this will default to the current working directory if not set
--provider-name <ARG> provider name, as used in Terraform configurations
--provider-name <ARG> provider name, as used in Terraform configurations; defaults to the --provider-dir short name (after removing `terraform-provider-` prefix)
--providers-schema <ARG> path to the providers schema JSON file, which contains the output of the terraform providers schema -json command. Setting this flag will skip building the provider and calling Terraform CLI
--tf-version <ARG> terraform binary version to download. If not provided, will look for a terraform binary in the local environment. If not found in the environment, will download the latest version of Terraform
```
Expand All @@ -98,7 +98,7 @@ Usage: tfplugindocs migrate [<args>]
--examples-dir <ARG> examples directory based on provider-dir (default: "examples")
--provider-dir <ARG> relative or absolute path to the root provider code directory when running the command outside the root provider code directory
--templates-dir <ARG> new website templates directory based on provider-dir; files will be migrated to this directory (default: "templates")
--provider-name <ARG> provider name, as used in Terraform configurations; this will default to provider-dir basename if not set
--provider-name <ARG> provider name, as used in Terraform configurations; defaults to the --provider-dir short name (after removing `terraform-provider-` prefix)
```
### How it Works
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (cmd *generateCmd) Help() string {

func (cmd *generateCmd) Flags() *flag.FlagSet {
fs := flag.NewFlagSet("generate", flag.ExitOnError)
fs.StringVar(&cmd.flagProviderName, "provider-name", "", "provider name, as used in Terraform configurations")
fs.StringVar(&cmd.flagProviderName, "provider-name", "", "provider name, as used in Terraform configurations; defaults to the --provider-dir short name (after removing `terraform-provider-` prefix)")
fs.StringVar(&cmd.flagProviderDir, "provider-dir", "", "relative or absolute path to the root provider code directory when running the command outside the root provider code directory")
fs.StringVar(&cmd.flagProvidersSchema, "providers-schema", "", "path to the providers schema JSON file, which contains the output of the terraform providers schema -json command. Setting this flag will skip building the provider and calling Terraform CLI")
fs.StringVar(&cmd.flagRenderedProviderName, "rendered-provider-name", "", "provider name, as generated in documentation (ex. page titles, ...)")
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (cmd *migrateCmd) Flags() *flag.FlagSet {
fs.StringVar(&cmd.flagProviderDir, "provider-dir", "", "relative or absolute path to the root provider code directory; this will default to the current working directory if not set")
fs.StringVar(&cmd.flagTemplatesDir, "templates-dir", "templates", "new website templates directory based on provider-dir; files will be migrated to this directory")
fs.StringVar(&cmd.flagExamplesDir, "examples-dir", "examples", "examples directory based on provider-dir; extracted code examples will be migrated to this directory")
fs.StringVar(&cmd.flagProviderName, "provider-name", "", "provider name, as used in Terraform configurations; this will default to provider-dir basename if not set")
fs.StringVar(&cmd.flagProviderName, "provider-name", "", "provider name, as used in Terraform configurations; defaults to the --provider-dir short name (after removing `terraform-provider-` prefix)")

return fs
}
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (cmd *validateCmd) Help() string {

func (cmd *validateCmd) Flags() *flag.FlagSet {
fs := flag.NewFlagSet("validate", flag.ExitOnError)
fs.StringVar(&cmd.flagProviderName, "provider-name", "", "provider name, as used in Terraform configurations")
fs.StringVar(&cmd.flagProviderName, "provider-name", "", "provider name, as used in Terraform configurations; defaults to the --provider-dir short name (after removing `terraform-provider-` prefix)")
fs.StringVar(&cmd.flagProviderDir, "provider-dir", "", "relative or absolute path to the root provider code directory; this will default to the current working directory if not set")
fs.StringVar(&cmd.flagProvidersSchema, "providers-schema", "", "path to the providers schema JSON file, which contains the output of the terraform providers schema -json command. Setting this flag will skip building the provider and calling Terraform CLI")
fs.StringVar(&cmd.tfVersion, "tf-version", "", "terraform binary version to download. If not provided, will look for a terraform binary in the local environment. If not found in the environment, will download the latest version of Terraform")
Expand Down
4 changes: 4 additions & 0 deletions internal/provider/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ func (v *validator) validate(ctx context.Context) error {

var err error

if v.providerName == "" {
v.providerName = filepath.Base(v.providerDir)
}

if v.providersSchemaPath == "" {
v.logger.infof("exporting schema from Terraform")
v.providerSchema, err = TerraformProviderSchemaFromTerraform(ctx, v.providerName, v.providerDir, v.tfVersion, v.logger)
Expand Down

0 comments on commit 7f32d68

Please sign in to comment.