diff --git a/README.md b/README.md index c73c109..61247f7 100644 --- a/README.md +++ b/README.md @@ -10,13 +10,14 @@ Today is a lightweight tool for tracking daily code commits, allowing developers By default **today** shows your commits today. It reads your git commit info and list the commits which is committed by the `${user.name}` in *global config* . -```bash +```sh Use today to review what you accomplished today! Usage: today [OPTION...] -o, --offset arg Offset from today (default: 0) -d, --directory arg The working directory to be check (default: .) + -a, --author arg Who's commits that will be checked -h, --help Print usage ``` diff --git a/src/main.cpp b/src/main.cpp index cb473cc..87ebc12 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,12 +33,20 @@ date::sys_days today() return date::floor(now); } -std::vector collect_info(std::string_view directory, date::sys_days d) +std::vector collect_info(std::string_view directory, date::sys_days d, std::optional opt_author) { std::vector result; auto repo = repository::open(directory); auto cfg_snapshot = repo.repo_config_snapshot(); - auto author = cfg_snapshot.get_string("user.name"); + std::string author; + if (opt_author) + { + author = *opt_author; + } + else + { + author = cfg_snapshot.get_string("user.name"); + } spdlog::debug("setting author: {}", author); auto walker = revwalk(repo); walker.push_head(); @@ -63,8 +71,9 @@ int main(int argc, char **argv) #ifdef DEBUG spdlog::set_level(spdlog::level::debug); #endif - cxxopts::Options options("today", "Use today to review what you've accomplished today!"); - options.add_options()("o,offset", "Offset from today", cxxopts::value()->default_value("0"))("d,directory", "The working directory to be check", cxxopts::value()->default_value("."))("h,help", "Print usage"); + cxxopts::Options options("today", "Use today to review what you accomplished today!"); + options.add_options()("o,offset", "Offset from today", cxxopts::value()->default_value("0"))("d,directory", "The working directory to be check", cxxopts::value()->default_value("."))("a,author", "Who's commits that will be checked", cxxopts::value())("h,help", "Print usage"); + auto result = options.parse(argc, argv); if (result.count("help")) { @@ -73,8 +82,13 @@ int main(int argc, char **argv) } auto offset = result["offset"].as(); auto dir = result["directory"].as(); + std::optional opt_author; + if (result.count("author")) + { + opt_author = result["author"].as(); + } spdlog::debug("offset: {}", offset); - auto cs = collect_info(dir, today() + date::days(offset)); + auto cs = collect_info(dir, today() + date::days(offset), opt_author); print_commits_info(cs); } \ No newline at end of file