initConfigFile populates a new config file if it does not exist yet
(ctx context.DnoteCtx, apiEndpoint string)
| 328 | |
| 329 | // initConfigFile populates a new config file if it does not exist yet |
| 330 | func 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 |
| 362 | func initFiles(ctx context.DnoteCtx, apiEndpoint string) error { |
no test coverage detected