-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforever.cpp
More file actions
109 lines (91 loc) · 2.94 KB
/
forever.cpp
File metadata and controls
109 lines (91 loc) · 2.94 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <iostream>
#include <string>
#include <vector>
#include <filesystem>
#include <fstream>
#include <cstdlib>
#include <chrono>
#include <ctime>
namespace fs = std::filesystem;
void show_help()
{
std::cout << "[Forever. CLI] -- High-Velocity Git Automation Tool\n\n";
std::cout << "Usage:\n";
std::cout << " forever \"<commit_message>\" [branch_name]\n\n";
std::cout << "Options:\n";
std::cout << " --help Show tactical command manual\n";
std::cout << " --version Display engine development data\n";
}
void show_version()
{
std::cout << "---------------------------------------------------\n";
std::cout << "[Forever. Automation Engine]\n";
std::cout << "Version: 2.0.0-LTS \"Logging Edition\"\n";
std::cout << "Developer: hypernova-developer\n";
std::cout << "Environment: Windows (CMD Optimized)\n";
std::cout << "---------------------------------------------------\n";
}
void log_operation(const std::string& message)
{
std::ofstream log_file("forever_history.log", std::ios::app);
auto now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
char buf[26];
ctime_s(buf, sizeof(buf), &now);
std::string ts(buf);
ts.pop_back();
log_file << "[" << ts << "] " << message << std::endl;
}
int main(int argc, char* argv[])
{
if (argc < 2)
{
show_help();
return 1;
}
std::string arg1 = argv[1];
if (arg1 == "--help")
{
show_help();
return 0;
}
if (arg1 == "--version")
{
show_version();
return 0;
}
if (!fs::exists(".git"))
{
std::cerr << "[Error] Tactical Error: No .git repository found in this directory.\n";
return 1;
}
std::string commit_message = arg1;
std::string branch_name = "main";
if (argc > 2)
{
branch_name = argv[2];
}
std::cout << "[Forever.] Initiating auto-sync sequence to branch: [" << branch_name << "]\n";
std::cout << "[Stage] Staging structural changes...\n";
if (std::system("git add .") != 0)
{
std::cerr << "[Error] Operation Aborted: 'git add' failed.\n";
return 1;
}
std::cout << "[Commit] Sealing commit payload...\n";
std::string commit_cmd = "git commit -m \"" + commit_message + "\"";
if (std::system(commit_cmd.c_str()) != 0)
{
std::cerr << "[Error] Operation Aborted: 'git commit' failed.\n";
return 1;
}
std::cout << "[Push] Launching payload to origin/" << branch_name << "...\n";
std::string push_cmd = "git push origin " + branch_name;
if (std::system(push_cmd.c_str()) != 0)
{
std::cerr << "[Error] Operation Aborted: Network push rejected.\n";
return 1;
}
std::cout << "[Success] Mission Accomplished -> Repository synchronized successfully via Forever.\n";
log_operation("Successfully synchronized branch [" + branch_name + "] with message: \"" + commit_message + "\"");
return 0;
}