Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generate: Introduce provider-dir flag #259

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changes/unreleased/ENHANCEMENTS-20230606-141357.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: ENHANCEMENTS
body: 'generate: Added `provider-dir` flag, which enables the command to be run from
any directory'
time: 2023-06-06T14:13:57.482032-04:00
custom:
Issue: "259"
21 changes: 11 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Usage: tfplugindocs [--version] [--help] <command> [<args>]

Available commands are:
the generate command is run by default
generate generates a plugin website from code, templates, and examples for the current directory
generate generates a plugin website from code, templates, and examples
validate validates a plugin website for the current directory

```
Expand All @@ -39,14 +39,15 @@ $ tfplugindocs generate --help

Usage: tfplugindocs generate [<args>]

--examples-dir <ARG> examples directory (default: "examples")
--ignore-deprecated <ARG> don't generate documentation for deprecated resources and data-sources (default: "false")
--provider-name <ARG> provider name, as used in Terraform configurations
--rendered-provider-name <ARG> provider name, as generated in documentation (ex. page titles, ...)
--rendered-website-dir <ARG> output directory (default: "docs")
--tf-version <ARG> terraform binary version to download
--website-source-dir <ARG> templates directory (default: "templates")
--website-temp-dir <ARG> temporary directory (used during generation)
--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
--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")
--tf-version <ARG> terraform binary version to download
--website-source-dir <ARG> templates directory based on provider-dir (default: "templates")
--website-temp-dir <ARG> temporary directory (used during generation)
```

`validate` command:
Expand All @@ -59,7 +60,7 @@ Usage: tfplugindocs validate [<args>]

### How it Works

When you run `tfplugindocs` from root directory of the provider the tool takes the following actions:
When you run `tfplugindocs`, by default from the root directory of a provider codebase, the tool takes the following actions:

* Copy all the templates and static files to a temporary directory
* Build (`go build`) a temporary binary of the provider source code
Expand Down
11 changes: 7 additions & 4 deletions internal/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type generateCmd struct {
flagProviderName string
flagRenderedProviderName string

flagProviderDir string
flagRenderedWebsiteDir string
flagExamplesDir string
flagWebsiteTmpDir string
Expand All @@ -27,7 +28,7 @@ type generateCmd struct {
}

func (cmd *generateCmd) Synopsis() string {
return "generates a plugin website from code, templates, and examples for the current directory"
return "generates a plugin website from code, templates, and examples"
}

func (cmd *generateCmd) Help() string {
Expand Down Expand Up @@ -71,11 +72,12 @@ 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.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.flagRenderedProviderName, "rendered-provider-name", "", "provider name, as generated in documentation (ex. page titles, ...)")
fs.StringVar(&cmd.flagRenderedWebsiteDir, "rendered-website-dir", "docs", "output directory")
fs.StringVar(&cmd.flagExamplesDir, "examples-dir", "examples", "examples directory")
fs.StringVar(&cmd.flagRenderedWebsiteDir, "rendered-website-dir", "docs", "output directory based on provider-dir")
fs.StringVar(&cmd.flagExamplesDir, "examples-dir", "examples", "examples directory based on provider-dir")
fs.StringVar(&cmd.flagWebsiteTmpDir, "website-temp-dir", "", "temporary directory (used during generation)")
fs.StringVar(&cmd.flagWebsiteSourceDir, "website-source-dir", "templates", "templates directory")
fs.StringVar(&cmd.flagWebsiteSourceDir, "website-source-dir", "templates", "templates directory based on provider-dir")
fs.StringVar(&cmd.tfVersion, "tf-version", "", "terraform binary version to download")
fs.BoolVar(&cmd.flagIgnoreDeprecated, "ignore-deprecated", false, "don't generate documentation for deprecated resources and data-sources")
return fs
Expand All @@ -95,6 +97,7 @@ func (cmd *generateCmd) Run(args []string) int {
func (cmd *generateCmd) runInternal() error {
err := provider.Generate(
cmd.ui,
cmd.flagProviderDir,
cmd.flagProviderName,
cmd.flagRenderedProviderName,
cmd.flagRenderedWebsiteDir,
Expand Down
Loading
Loading