From ddde4d726e6d8f73eec8dc32206b8e58f0c24744 Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Mon, 1 Jan 2024 18:07:31 +0100 Subject: [PATCH] fix: dont add none-plugin flags to docs (#46) --- docs/docs.go | 9 ++++++--- docs/docs_test.go | 5 +++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 38c6980..6c4f41f 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -78,6 +78,7 @@ func prepareArgsWithValues(flags []cli.Flag) []*PluginArg { func parseFlags(flags []cli.Flag) []*PluginArg { args := make([]*PluginArg, 0) + namePrefix := "plugin_" for _, f := range flags { flag, ok := f.(cli.DocGenerationFlag) @@ -87,10 +88,12 @@ func parseFlags(flags []cli.Flag) []*PluginArg { modArg := &PluginArg{} - name := flag.GetEnvVars()[0] - name = strings.TrimPrefix(name, "PLUGIN_") - modArg.Name = strings.ToLower(strings.TrimSpace(name)) + name := strings.ToLower(strings.TrimSpace(flag.GetEnvVars()[0])) + if !strings.HasPrefix(name, namePrefix) { + continue + } + modArg.Name = strings.TrimPrefix(name, namePrefix) modArg.Description = flag.GetUsage() modArg.Default = flag.GetDefaultText() diff --git a/docs/docs_test.go b/docs/docs_test.go index 0133de4..0bbb505 100644 --- a/docs/docs_test.go +++ b/docs/docs_test.go @@ -42,6 +42,11 @@ func testApp() *cli.App { Usage: "slice flag", EnvVars: []string{"PLUGIN_SLICE_FLAG"}, }, + &cli.StringFlag{ + Name: "hidden.flag", + Usage: "hidden flag", + EnvVars: []string{"HIDDEN_FLAG", "PLUGIN_HIDDEN_FLAG"}, + }, }, }