Skip to content

Commit d870966

Browse files
authored
chore: Add deprecated flag for unused metadata (google#4367)
1 parent 73fcc12 commit d870966

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

tools/metadata/main.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"fmt"
1515
"os"
1616
"path/filepath"
17+
"slices"
1718

1819
"github.com/alecthomas/kong"
1920
"github.com/google/go-github/v88/github"
@@ -44,7 +45,8 @@ consistent with the SHA listed in "openapi_commit". This is run in CI as a conve
4445
changes to openapi_operations.yaml.
4546
`,
4647

47-
"output_json_help": `Output JSON.`,
48+
"unused_deprecated_help": `Only list deprecated operations in openapi_operations.yaml that aren't used by any service methods.`,
49+
"output_json_help": `Output JSON.`,
4850
}
4951

5052
type rootCmd struct {
@@ -142,7 +144,8 @@ func (c *updateGoCmd) Run(root *rootCmd) error {
142144
}
143145

144146
type unusedCmd struct {
145-
JSON bool `kong:"help=${output_json_help}"`
147+
Deprecated bool `kong:"help=${unused_deprecated_help}"`
148+
JSON bool `kong:"help=${output_json_help}"`
146149
}
147150

148151
func (c *unusedCmd) Run(root *rootCmd, k *kong.Context) error {
@@ -154,6 +157,11 @@ func (c *unusedCmd) Run(root *rootCmd, k *kong.Context) error {
154157
if err != nil {
155158
return err
156159
}
160+
if c.Deprecated {
161+
unused = slices.DeleteFunc(unused, func(op *operation) bool {
162+
return !op.Deprecated
163+
})
164+
}
157165
if c.JSON {
158166
enc := json.NewEncoder(k.Stdout)
159167
enc.SetIndent("", " ")

0 commit comments

Comments
 (0)