MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / parseFlags

Function parseFlags

rest/main.go:476–513  ·  view source on GitHub ↗

parseFlags handles the parsing of legacy and persistent config flags.

(ctx context.Context, args []string)

Source from the content-addressed store, hash-verified

474
475// parseFlags handles the parsing of legacy and persistent config flags.
476func 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}

Callers 4

TestParseFlagsFunction · 0.85
TestDefaultStartupConfigFunction · 0.85
serverMainFunction · 0.85

Calls 8

NewEmptyStartupConfigFunction · 0.85
registerConfigFlagsFunction · 0.85
registerLegacyFlagsFunction · 0.85
fillConfigWithFlagsFunction · 0.85
ErrorfMethod · 0.80
StringMethod · 0.65
MergeMethod · 0.45

Tested by 3

TestParseFlagsFunction · 0.68
TestDefaultStartupConfigFunction · 0.68