Skip to content

Commit 7f32d68

Browse files
authored
validate: Default provider name to base directory when running validate (#377)
* fix * addd changelog * add comment to --provider-name argument
1 parent 56ab54b commit 7f32d68

File tree

6 files changed

+15
-6
lines changed

6 files changed

+15
-6
lines changed

Diff for: .changes/unreleased/BUG FIXES-20240524-122908.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: 'validate: Fixed issue with provider name not defaulting to directory'
3+
time: 2024-05-24T12:29:08.506286-04:00
4+
custom:
5+
Issue: "376"

Diff for: README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Usage: tfplugindocs generate [<args>]
6666
--examples-dir <ARG> examples directory based on provider-dir (default: "examples")
6767
--ignore-deprecated <ARG> don't generate documentation for deprecated resources and data-sources (default: "false")
6868
--provider-dir <ARG> relative or absolute path to the root provider code directory when running the command outside the root provider code directory
69-
--provider-name <ARG> provider name, as used in Terraform configurations
69+
--provider-name <ARG> provider name, as used in Terraform configurations; defaults to the --provider-dir short name (after removing `terraform-provider-` prefix)
7070
--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
7171
--rendered-provider-name <ARG> provider name, as generated in documentation (ex. page titles, ...)
7272
--rendered-website-dir <ARG> output directory based on provider-dir (default: "docs")
@@ -83,7 +83,7 @@ $ tfplugindocs validate --help
8383
Usage: tfplugindocs validate [<args>]
8484
8585
--provider-dir <ARG> relative or absolute path to the root provider code directory; this will default to the current working directory if not set
86-
--provider-name <ARG> provider name, as used in Terraform configurations
86+
--provider-name <ARG> provider name, as used in Terraform configurations; defaults to the --provider-dir short name (after removing `terraform-provider-` prefix)
8787
--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
8888
--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
8989
```
@@ -98,7 +98,7 @@ Usage: tfplugindocs migrate [<args>]
9898
--examples-dir <ARG> examples directory based on provider-dir (default: "examples")
9999
--provider-dir <ARG> relative or absolute path to the root provider code directory when running the command outside the root provider code directory
100100
--templates-dir <ARG> new website templates directory based on provider-dir; files will be migrated to this directory (default: "templates")
101-
--provider-name <ARG> provider name, as used in Terraform configurations; this will default to provider-dir basename if not set
101+
--provider-name <ARG> provider name, as used in Terraform configurations; defaults to the --provider-dir short name (after removing `terraform-provider-` prefix)
102102
```
103103
104104
### How it Works

Diff for: internal/cmd/generate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (cmd *generateCmd) Help() string {
7272

7373
func (cmd *generateCmd) Flags() *flag.FlagSet {
7474
fs := flag.NewFlagSet("generate", flag.ExitOnError)
75-
fs.StringVar(&cmd.flagProviderName, "provider-name", "", "provider name, as used in Terraform configurations")
75+
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)")
7676
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")
7777
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")
7878
fs.StringVar(&cmd.flagRenderedProviderName, "rendered-provider-name", "", "provider name, as generated in documentation (ex. page titles, ...)")

Diff for: internal/cmd/migrate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (cmd *migrateCmd) Flags() *flag.FlagSet {
6868
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")
6969
fs.StringVar(&cmd.flagTemplatesDir, "templates-dir", "templates", "new website templates directory based on provider-dir; files will be migrated to this directory")
7070
fs.StringVar(&cmd.flagExamplesDir, "examples-dir", "examples", "examples directory based on provider-dir; extracted code examples will be migrated to this directory")
71-
fs.StringVar(&cmd.flagProviderName, "provider-name", "", "provider name, as used in Terraform configurations; this will default to provider-dir basename if not set")
71+
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)")
7272

7373
return fs
7474
}

Diff for: internal/cmd/validate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func (cmd *validateCmd) Help() string {
6565

6666
func (cmd *validateCmd) Flags() *flag.FlagSet {
6767
fs := flag.NewFlagSet("validate", flag.ExitOnError)
68-
fs.StringVar(&cmd.flagProviderName, "provider-name", "", "provider name, as used in Terraform configurations")
68+
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)")
6969
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")
7070
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")
7171
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")

Diff for: internal/provider/validate.go

+4
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ func (v *validator) validate(ctx context.Context) error {
139139

140140
var err error
141141

142+
if v.providerName == "" {
143+
v.providerName = filepath.Base(v.providerDir)
144+
}
145+
142146
if v.providersSchemaPath == "" {
143147
v.logger.infof("exporting schema from Terraform")
144148
v.providerSchema, err = TerraformProviderSchemaFromTerraform(ctx, v.providerName, v.providerDir, v.tfVersion, v.logger)

0 commit comments

Comments
 (0)