chore: clidocgen: generate consistent docs (#7047)

* chore: clidocgen: ensure same generated docs

* fix
This commit is contained in:
Marcin Tojek 2023-04-07 18:32:06 +02:00 committed by GitHub
parent 0347231bb8
commit 3e250c6609
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -125,5 +125,9 @@ func read(path string) ([]byte, error) {
}
func DefaultDir() string {
return configdir.LocalConfig("coderv2")
configDir := configdir.LocalConfig("coderv2")
if dir := os.Getenv("CLIDOCGEN_CONFIG_DIRECTORY"); dir != "" {
configDir = dir
}
return configDir
}

View File

@ -348,7 +348,9 @@ func DefaultCacheDir() string {
// For compatibility with systemd.
defaultCacheDir = dir
}
if dir := os.Getenv("CLIDOCGEN_CACHE_DIRECTORY"); dir != "" {
defaultCacheDir = dir
}
return filepath.Join(defaultCacheDir, "coder")
}

View File

@ -28,7 +28,8 @@ type manifest struct {
Routes []route `json:"routes,omitempty"`
}
func unsetCoderEnv() {
func prepareEnv() {
// Unset CODER_ environment variables
for _, env := range os.Environ() {
if strings.HasPrefix(env, "CODER_") {
split := strings.SplitN(env, "=", 2)
@ -37,6 +38,16 @@ func unsetCoderEnv() {
}
}
}
// Override default OS values to ensure the same generated results.
err := os.Setenv("CLIDOCGEN_CACHE_DIRECTORY", "~/.cache")
if err != nil {
panic(err)
}
err = os.Setenv("CLIDOCGEN_CONFIG_DIRECTORY", "~/.config/coderv2")
if err != nil {
panic(err)
}
}
func deleteEmptyDirs(dir string) error {
@ -63,7 +74,7 @@ func deleteEmptyDirs(dir string) error {
}
func main() {
unsetCoderEnv()
prepareEnv()
workdir, err := os.Getwd()
if err != nil {