Skip to content

Commit

Permalink
leftovers
Browse files Browse the repository at this point in the history
  • Loading branch information
Reuven committed Jun 18, 2024
1 parent 60e2132 commit 1d44bb2
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 19 deletions.
2 changes: 0 additions & 2 deletions internal/breaking_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (

"github.com/spf13/cobra"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/formatters"
)

func getBreakingChangesCmd() *cobra.Command {
Expand All @@ -22,7 +21,6 @@ func getBreakingChangesCmd() *cobra.Command {

addCommonDiffFlags(&cmd, &flags)
addCommonBreakingFlags(&cmd, &flags)
enumWithOptions(&cmd, newEnumValue(formatters.SupportedFormatsByContentType(formatters.OutputChangelog), string(formatters.FormatText), &flags.format), "format", "f", "output format")
enumWithOptions(&cmd, newEnumValue([]string{LevelErr, LevelWarn}, "", &flags.failOn), "fail-on", "o", "exit with return code 1 when output includes errors with this level or higher")

return &cmd
Expand Down
1 change: 0 additions & 1 deletion internal/changelog.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func getChangelogCmd() *cobra.Command {

addCommonDiffFlags(&cmd, &flags)
addCommonBreakingFlags(&cmd, &flags)
enumWithOptions(&cmd, newEnumValue(formatters.SupportedFormatsByContentType(formatters.OutputChangelog), string(formatters.FormatText), &flags.format), "format", "f", "output format")
enumWithOptions(&cmd, newEnumValue([]string{LevelErr, LevelWarn, LevelInfo}, "", &flags.failOn), "fail-on", "o", "exit with return code 1 when output includes errors with this level or higher")
enumWithOptions(&cmd, newEnumValue([]string{LevelErr, LevelWarn, LevelInfo}, LevelInfo, &flags.level), "level", "", "output errors with this level or higher")

Expand Down
16 changes: 10 additions & 6 deletions internal/changelog_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type ChangelogFlags struct {
lang string
errIgnoreFile string
warnIgnoreFile string
deprecationDaysBeta int
deprecationDaysStable int
deprecationDaysBeta uint
deprecationDaysStable uint
color string
}

Expand Down Expand Up @@ -78,11 +78,11 @@ func (flags *ChangelogFlags) getIncludeChecks() []string {
return flags.includeChecks
}

func (flags *ChangelogFlags) getDeprecationDaysBeta() int {
func (flags *ChangelogFlags) getDeprecationDaysBeta() uint {
return flags.deprecationDaysBeta
}

func (flags *ChangelogFlags) getDeprecationDaysStable() int {
func (flags *ChangelogFlags) getDeprecationDaysStable() uint {
return flags.deprecationDaysStable
}

Expand Down Expand Up @@ -190,6 +190,10 @@ func (flags *ChangelogFlags) refLang() *string {
return &flags.lang
}

func (flags *ChangelogFlags) refFormat() *string {
return &flags.format
}

func (flags *ChangelogFlags) refErrIgnoreFile() *string {
return &flags.errIgnoreFile
}
Expand All @@ -202,11 +206,11 @@ func (flags *ChangelogFlags) refIncludeChecks() *[]string {
return &flags.includeChecks
}

func (flags *ChangelogFlags) refDeprecationDaysBeta() *int {
func (flags *ChangelogFlags) refDeprecationDaysBeta() *uint {
return &flags.deprecationDaysBeta
}

func (flags *ChangelogFlags) refDeprecationDaysStable() *int {
func (flags *ChangelogFlags) refDeprecationDaysStable() *uint {
return &flags.deprecationDaysStable
}

Expand Down
6 changes: 4 additions & 2 deletions internal/cmd_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/spf13/cobra"
"github.com/tufin/oasdiff/checker"
"github.com/tufin/oasdiff/checker/localizations"
"github.com/tufin/oasdiff/formatters"
)

func addCommonDiffFlags(cmd *cobra.Command, flags Flags) {
Expand Down Expand Up @@ -42,7 +43,8 @@ func addCommonBreakingFlags(cmd *cobra.Command, flags Flags) {
cmd.PersistentFlags().StringVarP(flags.refErrIgnoreFile(), "err-ignore", "", "", "configuration file for ignoring errors")
cmd.PersistentFlags().StringVarP(flags.refWarnIgnoreFile(), "warn-ignore", "", "", "configuration file for ignoring warnings")
cmd.PersistentFlags().VarP(newEnumSliceValue(checker.GetOptionalRuleIds(), nil, flags.refIncludeChecks()), "include-checks", "i", "comma-separated list of optional checks (run 'oasdiff checks --required false' to see options)")
cmd.PersistentFlags().IntVarP(flags.refDeprecationDaysBeta(), "deprecation-days-beta", "", checker.BetaDeprecationDays, "min days required between deprecating a beta resource and removing it")
cmd.PersistentFlags().IntVarP(flags.refDeprecationDaysStable(), "deprecation-days-stable", "", checker.StableDeprecationDays, "min days required between deprecating a stable resource and removing it")
cmd.PersistentFlags().UintVarP(flags.refDeprecationDaysBeta(), "deprecation-days-beta", "", checker.DefaultBetaDeprecationDays, "min days required between deprecating a beta resource and removing it")
cmd.PersistentFlags().UintVarP(flags.refDeprecationDaysStable(), "deprecation-days-stable", "", checker.DefaultStableDeprecationDays, "min days required between deprecating a stable resource and removing it")
enumWithOptions(cmd, newEnumValue([]string{"auto", "always", "never"}, "auto", flags.refColor()), "color", "", "when to colorize textual output")
enumWithOptions(cmd, newEnumValue(formatters.SupportedFormatsByContentType(formatters.OutputChangelog), string(formatters.FormatText), flags.refFormat()), "format", "f", "output format")
}
12 changes: 8 additions & 4 deletions internal/diff_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ func (flags *DiffFlags) getIncludeChecks() []string {
return nil
}

func (flags *DiffFlags) getDeprecationDaysBeta() int {
func (flags *DiffFlags) getDeprecationDaysBeta() uint {

Check warning on line 73 in internal/diff_flags.go

View check run for this annotation

Codecov / codecov/patch

internal/diff_flags.go#L73

Added line #L73 was not covered by tests
return 0
}

func (flags *DiffFlags) getDeprecationDaysStable() int {
func (flags *DiffFlags) getDeprecationDaysStable() uint {

Check warning on line 77 in internal/diff_flags.go

View check run for this annotation

Codecov / codecov/patch

internal/diff_flags.go#L77

Added line #L77 was not covered by tests
return 0
}

Expand Down Expand Up @@ -182,6 +182,10 @@ func (flags *DiffFlags) refLang() *string {
return nil
}

func (flags *DiffFlags) refFormat() *string {
return nil

Check warning on line 186 in internal/diff_flags.go

View check run for this annotation

Codecov / codecov/patch

internal/diff_flags.go#L185-L186

Added lines #L185 - L186 were not covered by tests
}

func (flags *DiffFlags) refErrIgnoreFile() *string {
return nil
}
Expand All @@ -194,11 +198,11 @@ func (flags *DiffFlags) refIncludeChecks() *[]string {
return nil
}

func (flags *DiffFlags) refDeprecationDaysBeta() *int {
func (flags *DiffFlags) refDeprecationDaysBeta() *uint {

Check warning on line 201 in internal/diff_flags.go

View check run for this annotation

Codecov / codecov/patch

internal/diff_flags.go#L201

Added line #L201 was not covered by tests
return nil
}

func (flags *DiffFlags) refDeprecationDaysStable() *int {
func (flags *DiffFlags) refDeprecationDaysStable() *uint {

Check warning on line 205 in internal/diff_flags.go

View check run for this annotation

Codecov / codecov/patch

internal/diff_flags.go#L205

Added line #L205 was not covered by tests
return nil
}

Expand Down
9 changes: 5 additions & 4 deletions internal/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type Flags interface {
getInsensitiveHeaders() bool
getCircularReferenceCounter() int
getIncludeChecks() []string
getDeprecationDaysBeta() int
getDeprecationDaysStable() int
getDeprecationDaysBeta() uint
getDeprecationDaysStable() uint
getLang() string
getColor() string
getWarnIgnoreFile() string
Expand Down Expand Up @@ -47,10 +47,11 @@ type Flags interface {
refFlattenParams() *bool
refInsensitiveHeaders() *bool
refLang() *string
refFormat() *string
refErrIgnoreFile() *string
refWarnIgnoreFile() *string
refIncludeChecks() *[]string
refDeprecationDaysBeta() *int
refDeprecationDaysStable() *int
refDeprecationDaysBeta() *uint
refDeprecationDaysStable() *uint
refColor() *string
}
6 changes: 6 additions & 0 deletions internal/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ func Test_BreakingChangesFlattenAllOf(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff breaking ../data/allof/simple.yaml ../data/allof/revision.yaml --flatten-allof --fail-on ERR"), io.Discard, io.Discard))
}

func Test_BreakingChangesInvalidDeprecationDays(t *testing.T) {
var stderr bytes.Buffer
require.Equal(t, 100, internal.Run(cmdToArgs("oasdiff breaking ../data/deprecation/base.yaml ../data/deprecation/deprecated-with-sunset.yaml --deprecation-days-stable=-1"), io.Discard, &stderr))
require.Equal(t, "Error: invalid argument \"-1\" for \"--deprecation-days-stable\" flag: strconv.ParseUint: parsing \"-1\": invalid syntax\n", stderr.String())
}

func Test_BreakingChangesFlattenCommonParams(t *testing.T) {
require.Zero(t, internal.Run(cmdToArgs("oasdiff breaking ../data/common-params/params_in_path.yaml ../data/common-params/params_in_op.yaml --flatten-params --fail-on ERR"), io.Discard, io.Discard))
}
Expand Down

0 comments on commit 1d44bb2

Please sign in to comment.