-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
68 lines (57 loc) · 2.81 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <string>
#include <filesystem>
#include "includes/git_manager.h"
#include "includes/options_manager.hpp"
auto main(const int argc, char **argv) -> int
{
auto manager = new cclip::options_manager("Scheduled Git Commit");
manager->add_option("h", "help", "Displays this help message.", false, false);
manager->add_option("t", "time", "The time to schedule the commit, time is specified by a ms,s,m,h or d for milliseconds, seconds, minutes, hours or days. If no time specifier is used, the default is ms. (Default: 1h)", false, true);
manager->add_option("m", "message", "The commit message template, check the docs for more information about message formatting. (Default: Scheduled commit at %t)", false, true);
manager->add_option("d", "directory", "The directory to commit, if not specified, the current directory is used. (Default: .)", false, true);
manager->add_option("ct", "tag", "If included, the commit will also create a tag using message template.", false, false);
manager->add_option("p", "push", "If included, the commit will also push to the remote repository.", false, false);
unsigned long long time = 3600000; // 1 hour
std::string message = "Scheduled commit at %t";
std::string directory = ".";
manager->parse(argc, argv);
if (manager->is_present("h"))
{
manager->print_help();
return 0;
}
if (manager->is_present("t"))
{
if (const std::string time_str = manager->get_option("t")->argument; time_str.back() == 's')
{
time = std::stoull(time_str.substr(0, time_str.size() - 1)) * 1000; // Convert seconds to milliseconds
} else if (time_str.back() == 'm')
{
time = std::stoull(time_str.substr(0, time_str.size() - 1)) * 60000; // Convert minutes to milliseconds
} else if (time_str.back() == 'h')
{
time = std::stoull(time_str.substr(0, time_str.size() - 1)) * 3600000; // Convert hours to milliseconds
} else if (time_str.back() == 'd')
{
time = std::stoull(time_str.substr(0, time_str.size() - 1)) * 86400000; // Convert days to milliseconds
} else
{
time = std::stoull(time_str); // Default to milliseconds
}
}
if (manager->is_present("m"))
{
message = manager->get_option("m")->argument;
}
if (manager->is_present("d"))
{
directory = manager->get_option("d")->argument;
}
const bool create_tag = manager->is_present("ct");
const bool push = manager->is_present("p");
delete manager; // Free memory for the options manager
directory = std::filesystem::absolute(directory).string(); // Converts directory to absolute path
const ScheduledGitCommit::GitManager git(time, message, directory, create_tag, push);
git.run();
}