Skip to content

Commit

Permalink
feat: add --author option
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamska1008 committed Sep 13, 2024
1 parent 9191d76 commit 5a7fcb3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down
24 changes: 19 additions & 5 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ date::sys_days today()
return date::floor<date::days>(now);
}

std::vector<t_commit_info> collect_info(std::string_view directory, date::sys_days d)
std::vector<t_commit_info> collect_info(std::string_view directory, date::sys_days d, std::optional<std::string> opt_author)
{
std::vector<t_commit_info> 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();
Expand All @@ -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<int>()->default_value("0"))("d,directory", "The working directory to be check", cxxopts::value<std::string>()->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<int>()->default_value("0"))("d,directory", "The working directory to be check", cxxopts::value<std::string>()->default_value("."))("a,author", "Who's commits that will be checked", cxxopts::value<std::string>())("h,help", "Print usage");

auto result = options.parse(argc, argv);
if (result.count("help"))
{
Expand All @@ -73,8 +82,13 @@ int main(int argc, char **argv)
}
auto offset = result["offset"].as<int>();
auto dir = result["directory"].as<std::string>();
std::optional<std::string> opt_author;
if (result.count("author"))
{
opt_author = result["author"].as<std::string>();
}
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);
}

0 comments on commit 5a7fcb3

Please sign in to comment.