-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (41 loc) · 1.18 KB
/
main.cpp
File metadata and controls
48 lines (41 loc) · 1.18 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
#include <CLI/CLI.hpp>
#include <git2.h> // For version number only
#include <iostream>
#include "src/utils/git_exception.hpp"
#include "version.hpp"
#include "subcommand/init_subcommand.hpp"
#include "subcommand/status_subcommand.hpp"
int main(int argc, char** argv)
{
int exitCode = 0;
try
{
const libgit2_object lg2_obj;
CLI::App app{"Git using C++ wrapper of libgit2"};
// Top-level command options.
auto version = app.add_flag("-v,--version", "Show version");
// Sub commands
init_subcommand init(lg2_obj, app);
status_subcommand status(lg2_obj, app);
app.parse(argc, argv);
if (version->count())
{
std::cout << "git2cpp version " << GIT2CPP_VERSION_STRING << " (libgit2 " << LIBGIT2_VERSION << ")" << std::endl;
}
}
catch (const CLI::Error& e)
{
std::cerr << e.what() << std::endl;
exitCode = 1;
}
catch (const GitException& e)
{
std::cerr << e.what() << std::endl;
exitCode = e.errorCode();
}
catch (std::exception& e) {
std::cerr << e.what() << std::endl;
exitCode = 1;
}
return exitCode;
}