Skip to content

Commit 3e250c6

Browse files
authored
chore: clidocgen: generate consistent docs (coder#7047)
* chore: clidocgen: ensure same generated docs * fix
1 parent 0347231 commit 3e250c6

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

cli/config/file.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,9 @@ func read(path string) ([]byte, error) {
125125
}
126126

127127
func DefaultDir() string {
128-
return configdir.LocalConfig("coderv2")
128+
configDir := configdir.LocalConfig("coderv2")
129+
if dir := os.Getenv("CLIDOCGEN_CONFIG_DIRECTORY"); dir != "" {
130+
configDir = dir
131+
}
132+
return configDir
129133
}

codersdk/deployment.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,9 @@ func DefaultCacheDir() string {
348348
// For compatibility with systemd.
349349
defaultCacheDir = dir
350350
}
351-
351+
if dir := os.Getenv("CLIDOCGEN_CACHE_DIRECTORY"); dir != "" {
352+
defaultCacheDir = dir
353+
}
352354
return filepath.Join(defaultCacheDir, "coder")
353355
}
354356

scripts/clidocgen/main.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ type manifest struct {
2828
Routes []route `json:"routes,omitempty"`
2929
}
3030

31-
func unsetCoderEnv() {
31+
func prepareEnv() {
32+
// Unset CODER_ environment variables
3233
for _, env := range os.Environ() {
3334
if strings.HasPrefix(env, "CODER_") {
3435
split := strings.SplitN(env, "=", 2)
@@ -37,6 +38,16 @@ func unsetCoderEnv() {
3738
}
3839
}
3940
}
41+
42+
// Override default OS values to ensure the same generated results.
43+
err := os.Setenv("CLIDOCGEN_CACHE_DIRECTORY", "~/.cache")
44+
if err != nil {
45+
panic(err)
46+
}
47+
err = os.Setenv("CLIDOCGEN_CONFIG_DIRECTORY", "~/.config/coderv2")
48+
if err != nil {
49+
panic(err)
50+
}
4051
}
4152

4253
func deleteEmptyDirs(dir string) error {
@@ -63,7 +74,7 @@ func deleteEmptyDirs(dir string) error {
6374
}
6475

6576
func main() {
66-
unsetCoderEnv()
77+
prepareEnv()
6778

6879
workdir, err := os.Getwd()
6980
if err != nil {

0 commit comments

Comments
 (0)