parseFlags handles the parsing of legacy and persistent config flags.
(ctx context.Context, args []string)
| 474 | |
| 475 | // parseFlags handles the parsing of legacy and persistent config flags. |
| 476 | func parseFlags(ctx context.Context, args []string) (flagStartupConfig *StartupConfig, fs *flag.FlagSet, disablePersistentConfig *bool, err error) { |
| 477 | fs = flag.NewFlagSet(args[0], flag.ContinueOnError) |
| 478 | |
| 479 | // used by service scripts as a way to specify a per-distro defaultLogFilePath |
| 480 | defaultLogFilePathFlag := fs.String("defaultLogFilePath", "", "Path to log files, if not overridden by --logFilePath, or the config") |
| 481 | |
| 482 | disablePersistentConfig = fs.Bool("disable_persistent_config", false, "Can be set to false to disable persistent config handling, and read all configuration from a legacy config file.") |
| 483 | |
| 484 | // register config property flags |
| 485 | startupConfig := NewEmptyStartupConfig() |
| 486 | legacyStartupConfig := NewEmptyStartupConfig() |
| 487 | |
| 488 | configFlags := registerConfigFlags(&startupConfig, fs) |
| 489 | legacyConfigFlags := registerLegacyFlags(&legacyStartupConfig, fs) |
| 490 | |
| 491 | if err = fs.Parse(args[1:]); err != nil { |
| 492 | return nil, nil, nil, err |
| 493 | } |
| 494 | |
| 495 | err = fillConfigWithFlags(fs, configFlags) |
| 496 | if err != nil { |
| 497 | return nil, nil, nil, fmt.Errorf("error merging flags on to config: %w", err) |
| 498 | } |
| 499 | |
| 500 | err = fillConfigWithLegacyFlags(ctx, legacyConfigFlags, fs, startupConfig.Logging.Console.LogLevel != nil) |
| 501 | if err != nil { |
| 502 | return nil, nil, nil, fmt.Errorf("error merging legacy flags on to config: %w", err) |
| 503 | } |
| 504 | // Merge persistent config on to legacy startup config to give priority to persistent config flags |
| 505 | err = legacyStartupConfig.Merge(&startupConfig) |
| 506 | if err != nil { |
| 507 | return nil, nil, nil, err |
| 508 | } |
| 509 | |
| 510 | defaultLogFilePath = *defaultLogFilePathFlag |
| 511 | |
| 512 | return &legacyStartupConfig, fs, disablePersistentConfig, nil |
| 513 | } |