diff --git a/docs/flags.md b/docs/flags.md index 22046b2ea..bf98d3f51 100644 --- a/docs/flags.md +++ b/docs/flags.md @@ -1,7 +1,7 @@ # Flags - + | Flag | Description | | :------ | :----------- | diff --git a/internal/gen/main.go b/internal/gen/docs/flags/main.go similarity index 93% rename from internal/gen/main.go rename to internal/gen/docs/flags/main.go index 8c0ca8e24..17f6ba162 100644 --- a/internal/gen/main.go +++ b/internal/gen/docs/flags/main.go @@ -33,14 +33,14 @@ type Flag struct { type Flags []Flag // AddFlag adds a new flag to the Flags struct -func (f *Flags) AddFlag(name, description string) { +func (f *Flags) addFlag(name, description string) { *f = append(*f, Flag{Name: name, Description: description}) } const markdownTemplate = `# Flags - + | Flag | Description | | :------ | :----------- | @@ -85,7 +85,7 @@ func computeFlags() Flags { if !flag.IsBoolFlag() { flagString += fmt.Sprintf("=%s", flag.FormatPlaceHolder()) } - flags.AddFlag(fmt.Sprintf("`%s`", flagString), flag.HelpWithEnvar()) + flags.addFlag(fmt.Sprintf("`%s`", flagString), flag.HelpWithEnvar()) } return flags } diff --git a/internal/gen/main_test.go b/internal/gen/docs/flags/main_test.go similarity index 76% rename from internal/gen/main_test.go rename to internal/gen/docs/flags/main_test.go index 7f6abab8c..a3a72e819 100644 --- a/internal/gen/main_test.go +++ b/internal/gen/docs/flags/main_test.go @@ -26,6 +26,8 @@ import ( "github.com/stretchr/testify/assert" ) +const pathToDocs = "%s/../../../../docs" + func TestComputeFlags(t *testing.T) { flags := computeFlags() @@ -54,35 +56,35 @@ func TestGenerateMarkdownTableRenderer(t *testing.T) { func TestFlagsMdExists(t *testing.T) { testPath, _ := os.Getwd() - fsys := os.DirFS(fmt.Sprintf("%s/../../docs", testPath)) - filePath := "flags.md" - _, err := fs.Stat(fsys, filePath) - assert.NoError(t, err, "expected file %s to exist", filePath) + fsys := os.DirFS(fmt.Sprintf(pathToDocs, testPath)) + fileName := "flags.md" + st, err := fs.Stat(fsys, fileName) + assert.NoError(t, err, "expected file %s to exist", fileName) + assert.Equal(t, fileName, st.Name()) } func TestFlagsMdUpToDate(t *testing.T) { testPath, _ := os.Getwd() - fsys := os.DirFS(fmt.Sprintf("%s/../../docs", testPath)) - filePath := "flags.md" - expected, err := fs.ReadFile(fsys, filePath) - assert.NoError(t, err, "expected file %s to exist", filePath) + fsys := os.DirFS(fmt.Sprintf(pathToDocs, testPath)) + fileName := "flags.md" + expected, err := fs.ReadFile(fsys, fileName) + assert.NoError(t, err, "expected file %s to exist", fileName) flags := computeFlags() actual, err := flags.generateMarkdownTable() assert.NoError(t, err) - - assert.True(t, len(expected) == len(actual), "expected file '%s' to be up to date. execute 'make generate-documentation", filePath) + assert.True(t, len(expected) == len(actual), "expected file '%s' to be up to date. execute 'make generate-flags-documentation", fileName) } func TestFlagsMdExtraFlagAdded(t *testing.T) { testPath, _ := os.Getwd() - fsys := os.DirFS(fmt.Sprintf("%s/../../docs", testPath)) + fsys := os.DirFS(fmt.Sprintf(pathToDocs, testPath)) filePath := "flags.md" expected, err := fs.ReadFile(fsys, filePath) assert.NoError(t, err, "expected file %s to exist", filePath) flags := computeFlags() - flags.AddFlag("new-flag", "description2") + flags.addFlag("new-flag", "description2") actual, err := flags.generateMarkdownTable() assert.NoError(t, err)