MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / initialize

Method initialize

src/Context.cpp:507–758  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

505
506////////////////////////////////////////////////////////////////////////////////
507int Context::initialize(int argc, const char** argv) {
508 timer_total.start();
509 int rc = 0;
510 home_dir = getenv("HOME");
511
512 std::vector<std::string> searchPaths{TASK_RCDIR};
513
514 try {
515 ////////////////////////////////////////////////////////////////////////////
516 //
517 // [1] Load the correct config file.
518 // - Default to ~/.taskrc (ctor).
519 // - If no ~/.taskrc, use $XDG_CONFIG_HOME/task/taskrc if exists, or
520 // ~/.config/task/taskrc if $XDG_CONFIG_HOME is unset
521 // - Allow $TASKRC override.
522 // - Allow command line override rc:<file>
523 // - Load resultant file.
524 // - Apply command line overrides to the config.
525 //
526 ////////////////////////////////////////////////////////////////////////////
527
528 bool taskrc_overridden = false;
529
530 // XDG_CONFIG_HOME doesn't count as an override (no warning header)
531 if (!rc_file.exists()) {
532 // Use XDG_CONFIG_HOME if defined, otherwise default to ~/.config
533 std::string xdg_config_home;
534 const char* env_xdg_config_home = getenv("XDG_CONFIG_HOME");
535
536 if (env_xdg_config_home)
537 xdg_config_home = format("{1}", env_xdg_config_home);
538 else
539 xdg_config_home = format("{1}/.config", home_dir);
540
541 // Ensure the path does not end with '/'
542 if (xdg_config_home.back() == '/') xdg_config_home.pop_back();
543
544 // https://github.com/GothenburgBitFactory/libshared/issues/32
545 std::string rcfile_path = format("{1}/task/taskrc", xdg_config_home);
546
547 File maybe_rc_file = File(rcfile_path);
548 if (maybe_rc_file.exists()) rc_file = maybe_rc_file;
549 }
550
551 char* override = getenv("TASKRC");
552 if (override) {
553 rc_file = File(override);
554 taskrc_overridden = true;
555 }
556
557 taskrc_overridden = CLI2::getOverride(argc, argv, rc_file) || taskrc_overridden;
558
559 // Artificial scope for timing purposes.
560 {
561 Timer timer;
562 config.parse(configurationDefaults, 1, searchPaths);
563 config.load(rc_file._data, 1, searchPaths);
564 debugTiming(format("Config::load ({1})", rc_file._data), timer);

Callers

nothing calls this directly

Calls 15

initializeColorRulesFunction · 0.85
colorFunction · 0.85
colorizeDebugFunction · 0.85
colorizeHeaderFunction · 0.85
colorizeFootnoteFunction · 0.85
existsMethod · 0.80
parseMethod · 0.80
setMethod · 0.80
entityMethod · 0.80
analyzeMethod · 0.80
attributeMethod · 0.80
getCommandMethod · 0.80

Tested by

no test coverage detected