startgit

Static page generator for git repositories
git clone git://git.dimitrijedobrota.com/startgit.git
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |

commit4cb0eaa5d1d3125c7156ad04483b80c8d6ff0a7d
parent0146a48f47bd4023c43bb5d026adfabdb8cc7a6e
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateWed, 8 Jan 2025 15:32:11 +0100

Read and parse command line arguments

Diffstat:
MCMakeLists.txt|++++--
Msource/main.cpp|++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------

2 files changed, 83 insertions(+), 20 deletions(-)


diff --git a/CMakeLists.txt b/CMakeLists.txt

@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)

project(
startgit
VERSION 0.1.1
VERSION 0.1.2
DESCRIPTION "Static page generator for git repositories"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/stargit.git"
LANGUAGES CXX

@@ -16,6 +16,8 @@ include(cmake/variables.cmake)

# ---- Declare dependencies ----
find_package(git2wrap CONFIG REQUIRED)
find_package(hemplate 0.1 CONFIG REQUIRED)
find_package(poafloc 1 CONFIG REQUIRED)
# ---- Declare library ----

@@ -24,7 +26,7 @@ add_library(

source/lib.cpp
)
target_link_libraries(startgit_lib PUBLIC git2wrap::git2wrap)
target_link_libraries(startgit_lib PUBLIC git2wrap::git2wrap hemplate::hemplate poafloc::poafloc)
target_include_directories(
startgit_lib ${warning_guard}

diff --git a/source/main.cpp b/source/main.cpp

@@ -1,5 +1,7 @@

#include <filesystem>
#include <format>
#include <iostream>
#include <string>
#include <git2.h>
#include <git2wrap/error.hpp>

@@ -8,36 +10,95 @@

#include <git2wrap/repository.hpp>
#include <git2wrap/revwalk.hpp>
#include <git2wrap/signature.hpp>
#include <poafloc/poafloc.hpp>
int main()
std::string long_to_string(int64_t date)
{
std::stringstream strs;
strs << std::put_time(std::gmtime(&date), "%Y-%m-%d %I:%M:%S %p"); // NOLINT
return strs.str();
}
struct arguments_t
{
std::filesystem::path output_dir = ".";
std::vector<std::filesystem::path> repos;
std::string url;
};
int parse_opt(int key, const char* arg, poafloc::Parser* parser)
{
auto* args = static_cast<arguments_t*>(parser->input());
switch (key) {
case 'o':
args->output_dir = arg;
break;
case 'u':
args->url = arg;
break;
case poafloc::ARG:
args->repos.emplace_back(arg);
break;
default:
break;
}
return 0;
}
// NOLINTBEGIN
// clang-format off
static const poafloc::option_t options[] = {
// {0, 0, 0, 0, "Output mode", 1},
{"output", 'o', "DIR", 0, "Output directory"},
{"url", 'u', "baseurl", 0, "Base URL to make links in the Atom feeds absolute"},
{0},
};
// clang-format on
static const poafloc::arg_t arg {
options,
parse_opt,
"config_file",
"",
};
// NOLINTEND
int main(int argc, char* argv[])
{
arguments_t args;
if (poafloc::parse(&arg, argc, argv, 0, &args) != 0) {
std::cerr << "There was an error while parsing arguments";
return 1;
}
try {
using namespace git2wrap; // NOLINT
const libgit2 libgit;
repository repo = repository::open(
"../maintain/stellar", GIT_REPOSITORY_OPEN_NO_SEARCH, nullptr);
for (const auto& repo_name : args.repos) {
repository repo = repository::open(
repo_name.c_str(), GIT_REPOSITORY_OPEN_NO_SEARCH, nullptr);
for (auto it = repo.branch_begin(GIT_BRANCH_LOCAL); it != repo.branch_end();
++it)
{
const object obj = repo.revparse(it->get_name().c_str());
std::cout << it->get_name() << " " << obj.get_id() << '\n';
for (auto it = repo.branch_begin(GIT_BRANCH_LOCAL);
it != repo.branch_end();
++it)
{
const object obj = repo.revparse(it->get_name().c_str());
std::cout << it->get_name() << " " << obj.get_id() << '\n';
revwalk rwalk(repo);
rwalk.push(obj.get_id());
revwalk rwalk(repo);
rwalk.push(obj.get_id());
while (const auto commit = rwalk.next()) {
std::cout << std::format("{}: {} ({})\n",
commit.get_time(),
commit.get_summary(),
commit.get_author().get_name());
while (const auto commit = rwalk.next()) {
std::cout << std::format("\t{}: {} ({})\n",
long_to_string(commit.get_time()),
commit.get_summary(),
commit.get_author().get_name());
}
}
break;
}
} catch (const git2wrap::error& err) {
std::cerr << std::format("({}:{}) Error {}/{}: {}\n",
err.get_file(),