(cc *clientconfig.Config)
| 179 | } |
| 180 | |
| 181 | func (c *initCmd) writeConfig(cc *clientconfig.Config) error { |
| 182 | configFilePath := osutil.UserClientConfigPath() |
| 183 | if _, err := os.Stat(configFilePath); err == nil { |
| 184 | return fmt.Errorf("config file %q already exists; quitting without touching it", configFilePath) |
| 185 | } |
| 186 | if err := os.MkdirAll(filepath.Dir(configFilePath), 0700); err != nil { |
| 187 | return err |
| 188 | } |
| 189 | |
| 190 | jsonBytes, err := json.MarshalIndent(cc, "", " ") |
| 191 | if err != nil { |
| 192 | log.Fatalf("JSON serialization error: %v", err) |
| 193 | } |
| 194 | if err := os.WriteFile(configFilePath, jsonBytes, 0600); err != nil { |
| 195 | return fmt.Errorf("could not write client config file %v: %v", configFilePath, err) |
| 196 | } |
| 197 | log.Printf("Wrote %q; modify as necessary.", configFilePath) |
| 198 | return nil |
| 199 | |
| 200 | } |
| 201 | |
| 202 | func (c *initCmd) RunCommand(args []string) error { |
| 203 | if len(args) > 0 { |
no test coverage detected