Skip to content

Commit 258f460

Browse files
committed
Remove deprecated '--sort-by-XXX' flags
In v0.13.0 flags `--sort-by-required` and `--sort-by-type` have been deprecated in favor of `--sort-by required` and `--sort-by type` respectively. And they are completely being removed now (two releases after original announcement) Signed-off-by: Khosrow Moossavi <khos2ow@gmail.com>
1 parent b4ebd5b commit 258f460

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

cmd/root.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ func NewCommand() *cobra.Command {
7474
cmd.PersistentFlags().BoolVar(new(bool), "hide-all", false, "hide all sections (default false)")
7575
cmd.PersistentFlags().MarkDeprecated("show-all", "more information: https://terraform-docs.io/user-guide/how-to/#visibility-of-sections\n\n") //nolint:errcheck,gosec
7676
cmd.PersistentFlags().MarkDeprecated("hide-all", "more information: https://terraform-docs.io/user-guide/how-to/#visibility-of-sections\n\n") //nolint:errcheck,gosec
77-
78-
cmd.PersistentFlags().BoolVar(&config.Sort.Criteria.Required, "sort-by-required", false, "sort items by name and print required ones first (default false)")
79-
cmd.PersistentFlags().BoolVar(&config.Sort.Criteria.Type, "sort-by-type", false, "sort items by type of them (default false)")
80-
cmd.PersistentFlags().MarkDeprecated("sort-by-required", "use '--sort-by required' instead\n\n") //nolint:errcheck,gosec
81-
cmd.PersistentFlags().MarkDeprecated("sort-by-type", "use '--sort-by type' instead\n\n") //nolint:errcheck,gosec
8277
// <==
8378

8479
cmd.PersistentFlags().StringVar(&config.HeaderFrom, "header-from", "main.tf", "relative path of a file to read header from")

internal/cli/config.go

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -342,36 +342,22 @@ var allSorts = []string{
342342
// SortTypes list.
343343
var SortTypes = strings.Join(allSorts, ", ")
344344

345-
type sortby struct {
346-
Name bool `name:"name"`
347-
Required bool `name:"required"`
348-
Type bool `name:"type"`
349-
}
350345
type sort struct {
351-
Enabled bool `mapstructure:"enabled"`
352-
By string `mapstructure:"by"`
353-
Criteria sortby `mapstructure:"-"`
346+
Enabled bool `mapstructure:"enabled"`
347+
By string `mapstructure:"by"`
354348
}
355349

356350
func defaultSort() sort {
357351
return sort{
358352
Enabled: true,
359353
By: sortName,
360-
Criteria: sortby{
361-
Name: true,
362-
Required: false,
363-
Type: false,
364-
},
365354
}
366355
}
367356

368357
func (s *sort) validate() error {
369358
if !contains(allSorts, s.By) {
370359
return fmt.Errorf("'%s' is not a valid sort type", s.By)
371360
}
372-
if s.Criteria.Required && s.Criteria.Type {
373-
return fmt.Errorf("'--sort-by-required' and '--sort-by-type' can't be used together")
374-
}
375361
return nil
376362
}
377363

@@ -461,11 +447,6 @@ func (c *Config) process() error { //nolint:gocyclo
461447
}
462448
}
463449

464-
// Enable specified sort criteria
465-
c.Sort.Criteria.Name = c.Sort.Enabled && c.Sort.By == sortName
466-
c.Sort.Criteria.Required = c.Sort.Enabled && c.Sort.By == sortRequired
467-
c.Sort.Criteria.Type = c.Sort.Enabled && c.Sort.By == sortType
468-
469450
return nil
470451
}
471452

@@ -499,9 +480,9 @@ func (c *Config) extract() (*print.Settings, *terraform.Options) {
499480
options.OutputValuesPath = c.OutputValues.From
500481

501482
// sort
502-
options.SortBy.Name = c.Sort.Enabled && c.Sort.Criteria.Name
503-
options.SortBy.Required = c.Sort.Enabled && c.Sort.Criteria.Required
504-
options.SortBy.Type = c.Sort.Enabled && c.Sort.Criteria.Type
483+
options.SortBy.Name = c.Sort.Enabled && c.Sort.By == sortName
484+
options.SortBy.Required = c.Sort.Enabled && c.Sort.By == sortRequired
485+
options.SortBy.Type = c.Sort.Enabled && c.Sort.By == sortType
505486

506487
// settings
507488
settings.EscapeCharacters = c.Settings.Escape

0 commit comments

Comments
 (0)