feat: Add new flags: --show, --show-all, --hide-all (#267)

* Add new flags: --show, --show-all, --hide-all

* add deprecated flags to Config

* update docs

* add implementation for new flags

Examples:

- hide all sections except one (or more): `terraform-docs --hide-all --show <name> ...`
- show all sections except one (or more): `terraform-docs --show-all --hide <name> ...`
This commit is contained in:
Khosrow Moossavi
2020-05-25 12:08:52 -04:00
committed by GitHub
parent 04a9ef49eb
commit e0404399a7
23 changed files with 349 additions and 163 deletions

View File

@@ -21,13 +21,13 @@ func NewCommand(config *cli.Config) *cobra.Command {
}
// flags
cmd.PersistentFlags().BoolVar(&config.Settings.Required, "required", true, "show \"Required\" column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Sensitive, "sensitive", true, "show \"Sensitive\" column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Required, "required", true, "show Required column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Sensitive, "sensitive", true, "show Sensitive column or section")
cmd.PersistentFlags().IntVar(&config.Settings.Indent, "indent", 2, "indention level of AsciiDoc sections [1, 2, 3, 4, 5]")
// deprecation
cmd.PersistentFlags().BoolVar(new(bool), "no-required", false, "do not show \"Required\" column or section")
cmd.PersistentFlags().BoolVar(new(bool), "no-sensitive", false, "do not show \"Sensitive\" column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Deprecated.NoRequired, "no-required", false, "do not show \"Required\" column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Deprecated.NoSensitive, "no-sensitive", false, "do not show \"Sensitive\" column or section")
cmd.PersistentFlags().MarkDeprecated("no-required", "use '--required=false' instead") //nolint:errcheck
cmd.PersistentFlags().MarkDeprecated("no-sensitive", "use '--sensitive=false' instead") //nolint:errcheck

View File

@@ -21,7 +21,7 @@ func NewCommand(config *cli.Config) *cobra.Command {
cmd.PersistentFlags().BoolVar(&config.Settings.Escape, "escape", true, "escape special characters")
// deprecation
cmd.PersistentFlags().BoolVar(new(bool), "no-escape", false, "do not escape special characters")
cmd.PersistentFlags().BoolVar(&config.Settings.Deprecated.NoEscape, "no-escape", false, "do not escape special characters")
cmd.PersistentFlags().MarkDeprecated("no-escape", "use '--escape=false' instead") //nolint:errcheck
return cmd

View File

@@ -21,15 +21,15 @@ func NewCommand(config *cli.Config) *cobra.Command {
}
// flags
cmd.PersistentFlags().BoolVar(&config.Settings.Required, "required", true, "show \"Required\" column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Sensitive, "sensitive", true, "show \"Sensitive\" column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Required, "required", true, "show Required column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Sensitive, "sensitive", true, "show Sensitive column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Escape, "escape", true, "escape special characters")
cmd.PersistentFlags().IntVar(&config.Settings.Indent, "indent", 2, "indention level of Markdown sections [1, 2, 3, 4, 5]")
// deprecation
cmd.PersistentFlags().BoolVar(new(bool), "no-required", false, "do not show \"Required\" column or section")
cmd.PersistentFlags().BoolVar(new(bool), "no-sensitive", false, "do not show \"Sensitive\" column or section")
cmd.PersistentFlags().BoolVar(new(bool), "no-escape", false, "do not escape special characters")
cmd.PersistentFlags().BoolVar(&config.Settings.Deprecated.NoRequired, "no-required", false, "do not show \"Required\" column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Deprecated.NoSensitive, "no-sensitive", false, "do not show \"Sensitive\" column or section")
cmd.PersistentFlags().BoolVar(&config.Settings.Deprecated.NoEscape, "no-escape", false, "do not escape special characters")
cmd.PersistentFlags().MarkDeprecated("no-required", "use '--required=false' instead") //nolint:errcheck
cmd.PersistentFlags().MarkDeprecated("no-sensitive", "use '--sensitive=false' instead") //nolint:errcheck
cmd.PersistentFlags().MarkDeprecated("no-escape", "use '--escape=false' instead") //nolint:errcheck

View File

@@ -21,7 +21,7 @@ func NewCommand(config *cli.Config) *cobra.Command {
cmd.PersistentFlags().BoolVar(&config.Settings.Color, "color", true, "colorize printed result")
// deprecation
cmd.PersistentFlags().BoolVar(new(bool), "no-color", false, "do not colorize printed result")
cmd.PersistentFlags().BoolVar(&config.Settings.Deprecated.NoColor, "no-color", false, "do not colorize printed result")
cmd.PersistentFlags().MarkDeprecated("no-color", "use '--color=false' instead") //nolint:errcheck
return cmd

View File

@@ -42,7 +42,10 @@ func NewCommand() *cobra.Command {
}
// flags
cmd.PersistentFlags().StringSliceVar(&config.Sections.Show, "show", []string{}, "show section [header, inputs, outputs, providers, requirements]")
cmd.PersistentFlags().StringSliceVar(&config.Sections.Hide, "hide", []string{}, "hide section [header, inputs, outputs, providers, requirements]")
cmd.PersistentFlags().BoolVar(&config.Sections.ShowAll, "show-all", true, "show all sections")
cmd.PersistentFlags().BoolVar(&config.Sections.HideAll, "hide-all", false, "hide all sections (default false)")
cmd.PersistentFlags().BoolVar(&config.Sort.Enabled, "sort", true, "sort items")
cmd.PersistentFlags().BoolVar(&config.Sort.By.Required, "sort-by-required", false, "sort items by name and print required ones first (default false)")
@@ -54,12 +57,12 @@ func NewCommand() *cobra.Command {
cmd.PersistentFlags().StringVar(&config.OutputValues.From, "output-values-from", "", "inject output values from file into outputs (default \"\")")
// deprecation
cmd.PersistentFlags().BoolVar(new(bool), "no-header", false, "do not show module header")
cmd.PersistentFlags().BoolVar(new(bool), "no-inputs", false, "do not show inputs")
cmd.PersistentFlags().BoolVar(new(bool), "no-outputs", false, "do not show outputs")
cmd.PersistentFlags().BoolVar(new(bool), "no-providers", false, "do not show providers")
cmd.PersistentFlags().BoolVar(new(bool), "no-requirements", false, "do not show module requirements")
cmd.PersistentFlags().BoolVar(new(bool), "no-sort", false, "do no sort items")
cmd.PersistentFlags().BoolVar(&config.Sections.Deprecated.NoHeader, "no-header", false, "do not show module header")
cmd.PersistentFlags().BoolVar(&config.Sections.Deprecated.NoInputs, "no-inputs", false, "do not show inputs")
cmd.PersistentFlags().BoolVar(&config.Sections.Deprecated.NoOutputs, "no-outputs", false, "do not show outputs")
cmd.PersistentFlags().BoolVar(&config.Sections.Deprecated.NoProviders, "no-providers", false, "do not show providers")
cmd.PersistentFlags().BoolVar(&config.Sections.Deprecated.NoRequirements, "no-requirements", false, "do not show module requirements")
cmd.PersistentFlags().BoolVar(&config.Sort.Deprecated.NoSort, "no-sort", false, "do no sort items")
cmd.PersistentFlags().MarkDeprecated("no-header", "use '--hide header' instead") //nolint:errcheck
cmd.PersistentFlags().MarkDeprecated("no-inputs", "use '--hide inputs' instead") //nolint:errcheck