MCPcopy Create free account
hub / github.com/devops-rob/target-cli / TargetHomeCreate

Function TargetHomeCreate

pkg/targetdir/targetdir.go:28–49  ·  view source on GitHub ↗

TargetHomeCreate checks for the target directory and profiles.json file and creates if they don't exist

()

Source from the content-addressed store, hash-verified

26// TargetHomeCreate checks for the target directory
27// and profiles.json file and creates if they don't exist
28func TargetHomeCreate() {
29 var defaultConfig = "{\n\t\"vault\": {},\n\t\"consul\": {},\n\t\"nomad\": {}\n\t\"terraform\": {}\n}"
30 targetHome := TargetHome()
31 if _, err := os.Stat(targetHome); os.IsNotExist(err) {
32 os.Mkdir(targetHome, 0755)
33 }
34
35 f := fmt.Sprintf("%s/profiles.json", targetHome)
36
37 if _, err := os.Stat(f); os.IsNotExist(err) {
38 // Create and write the default configuration to the file
39 err := os.WriteFile(f, []byte(defaultConfig), 0644)
40 if err != nil {
41 fmt.Printf("Error creating and writing to profiles.json: %v\n", err)
42 }
43 }
44
45 defaultsDir := targetHome + "/defaults"
46 if _, err := os.Stat(defaultsDir); os.IsNotExist(err) {
47 os.Mkdir(defaultsDir, 0755)
48 }
49}

Callers 2

ExecuteFunction · 0.92
initFunction · 0.92

Calls 1

TargetHomeFunction · 0.85

Tested by

no test coverage detected