()
| 69 | ) |
| 70 | |
| 71 | func install() (path string) { |
| 72 | verbose := os.Getenv("COPILOT_CLI_INSTALL_VERBOSE") == "1" |
| 73 | logError := func(msg string, err error) { |
| 74 | if verbose { |
| 75 | fmt.Printf("embedded CLI installation error: %s: %v\n", msg, err) |
| 76 | } |
| 77 | } |
| 78 | if verbose { |
| 79 | start := time.Now() |
| 80 | defer func() { |
| 81 | duration := time.Since(start) |
| 82 | fmt.Printf("installing embedded CLI at %s installation took %s\n", path, duration) |
| 83 | }() |
| 84 | } |
| 85 | installDir := config.Dir |
| 86 | if installDir == "" { |
| 87 | if copilotHome := os.Getenv("COPILOT_HOME"); copilotHome != "" { |
| 88 | installDir = filepath.Join(copilotHome, "cache", "copilot-sdk") |
| 89 | } else { |
| 90 | var err error |
| 91 | if installDir, err = os.UserCacheDir(); err != nil { |
| 92 | // Fall back to temp dir if UserCacheDir is unavailable |
| 93 | installDir = os.TempDir() |
| 94 | } |
| 95 | installDir = filepath.Join(installDir, "copilot-sdk") |
| 96 | } |
| 97 | } |
| 98 | path, err := installAt(installDir) |
| 99 | if err != nil { |
| 100 | logError("installing in configured directory", err) |
| 101 | return "" |
| 102 | } |
| 103 | return path |
| 104 | } |
| 105 | |
| 106 | func installAt(installDir string) (string, error) { |
| 107 | if err := os.MkdirAll(installDir, 0755); err != nil { |
no test coverage detected
searching dependent graphs…