@@ -6,6 +6,7 @@ package cmd
66import (
77 "fmt"
88 "os"
9+ "sort"
910
1011 "github.com/spf13/cobra"
1112)
2021 Use : "openapi-changes" ,
2122 Short : "Detect and explore changes between OpenAPI / Swagger specifications." ,
2223 Long : `openapi-changes can detect every change found in an OpenAPI specification.
23- it can compare between two files, or a single file, over time.
24+ it can compare between two files, or a single file, over time.
2425
25- All commands use the current doctor-based engine.` ,
26+ The comparison and reporting commands use the current doctor-based engine.` ,
2627 RunE : func (cmd * cobra.Command , args []string ) error {
2728 opts , _ , err := readCommonFlags (cmd )
2829 if err != nil {
@@ -32,7 +33,7 @@ All commands use the current doctor-based engine.`,
3233
3334 fmt .Println ("Current commands" )
3435 fmt .Println ()
35- for _ , name := range [] string { "console" , "summary" , "report" , "markdown-report" , "html-report" } {
36+ for _ , name := range visibleRootCommandNames ( cmd ) {
3637 fmt .Printf (" > %s\n " , name )
3738 }
3839 fmt .Println ()
@@ -53,13 +54,26 @@ func Execute(version, commit, date string) {
5354 }
5455}
5556
57+ func visibleRootCommandNames (root * cobra.Command ) []string {
58+ var names []string
59+ for _ , command := range root .Commands () {
60+ if command == nil || command .Hidden || command .Name () == "help" {
61+ continue
62+ }
63+ names = append (names , command .Name ())
64+ }
65+ sort .Strings (names )
66+ return names
67+ }
68+
5669func init () {
5770 cobra .OnInitialize (initConfig )
5871 rootCmd .AddCommand (GetConsoleCommand ())
5972 rootCmd .AddCommand (GetHTMLReportCommand ())
6073 rootCmd .AddCommand (GetMarkdownReportCommand ())
6174 rootCmd .AddCommand (GetReportCommand ())
6275 rootCmd .AddCommand (GetSummaryCommand ())
76+ rootCmd .AddCommand (GetVersionCommand ())
6377 rootCmd .PersistentFlags ().BoolP ("top" , "t" , false , "Only show latest changes (last git revision against HEAD)" )
6478 rootCmd .PersistentFlags ().IntP ("limit" , "l" , 5 , "Limit history to number of revisions (default is 5)" )
6579 rootCmd .PersistentFlags ().BoolP ("global-revisions" , "R" , false , "Consider all revisions in limit, not just the ones for the file" )
0 commit comments