MCPcopy
hub / github.com/perkeep/perkeep / writeConfig

Method writeConfig

cmd/pk-put/init.go:181–200  ·  view source on GitHub ↗
(cc *clientconfig.Config)

Source from the content-addressed store, hash-verified

179}
180
181func (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
202func (c *initCmd) RunCommand(args []string) error {
203 if len(args) > 0 {

Callers 1

RunCommandMethod · 0.95

Calls 5

UserClientConfigPathFunction · 0.92
PrintfMethod · 0.80
StatMethod · 0.65
MkdirAllMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected