chore(docs): moved to folder internal/gen/docs/flags

Signed-off-by: ivan katliarchuk <ivan.katliarchuk@gmail.com>
This commit is contained in:
ivan katliarchuk 2025-01-02 16:11:27 +00:00
parent 1fdc578012
commit 02cb8a6f6b
No known key found for this signature in database
GPG Key ID: 601CDBBBB76E47BE
3 changed files with 18 additions and 16 deletions

View File

@ -1,7 +1,7 @@
# Flags
<!-- THIS FILE MUST NOT BE EDITED BY HAND -->
<!-- ON NEW FLAG ADDED PLEASE RUN 'make generate-documentation' -->
<!-- ON NEW FLAG ADDED PLEASE RUN 'make generate-flags-documentation' -->
| Flag | Description |
| :------ | :----------- |

View File

@ -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
<!-- THIS FILE MUST NOT BE EDITED BY HAND -->
<!-- ON NEW FLAG ADDED PLEASE RUN 'make generate-documentation' -->
<!-- ON NEW FLAG ADDED PLEASE RUN 'make generate-flags-documentation' -->
| 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
}

View File

@ -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)