MCPcopy Index your code
hub / github.com/dnote/dnote / initConfigFile

Function initConfigFile

pkg/cli/infra/init.go:330–359  ·  view source on GitHub ↗

initConfigFile populates a new config file if it does not exist yet

(ctx context.DnoteCtx, apiEndpoint string)

Source from the content-addressed store, hash-verified

328
329// initConfigFile populates a new config file if it does not exist yet
330func initConfigFile(ctx context.DnoteCtx, apiEndpoint string) error {
331 path := config.GetPath(ctx)
332 ok, err := utils.FileExists(path)
333 if err != nil {
334 return errors.Wrap(err, "checking if config exists")
335 }
336 if ok {
337 return nil
338 }
339
340 editor := getEditorCommand()
341
342 // Use default API endpoint if none provided
343 endpoint := apiEndpoint
344 if endpoint == "" {
345 endpoint = DefaultAPIEndpoint
346 }
347
348 cf := config.Config{
349 Editor: editor,
350 APIEndpoint: endpoint,
351 EnableUpgradeCheck: true,
352 }
353
354 if err := config.Write(ctx, cf); err != nil {
355 return errors.Wrap(err, "writing config")
356 }
357
358 return nil
359}
360
361// initFiles creates, if necessary, the dnote directory and files inside
362func initFiles(ctx context.DnoteCtx, apiEndpoint string) error {

Callers 1

initFilesFunction · 0.85

Calls 4

GetPathFunction · 0.92
FileExistsFunction · 0.92
WriteFunction · 0.92
getEditorCommandFunction · 0.70

Tested by

no test coverage detected