Skip to content

Commit

Permalink
feat: add action edit/view configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
easbarba committed Aug 14, 2024
1 parent ab26aa1 commit 3c7bbe8
Show file tree
Hide file tree
Showing 26 changed files with 605 additions and 120 deletions.
64 changes: 60 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
build_debug/
build_release/

# MESON

/build
/subprojects/*
!/subprojects/*.wrap
/.cache

# CMAKE

# Generated and user files
**/CMakeCache.txt
**/CMakeUserPresets.json
Expand All @@ -11,8 +20,55 @@ build_release/
**/install_manifest.txt
**/compile_commands.json

# Build directories
build/
out/
cmake-build-*/

/build
/subprojects/*
!/subprojects/*.wrap
/.cache
# CMake files
CMakeCache.txt
CMakeFiles/
CMakeScripts/
Testing/
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# IDE-specific files (example for Visual Studio Code)
.vscode/

# OS-specific files
.DS_Store
Thumbs.db
19 changes: 17 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
image: registry.gitlab.com/easbarba/onur-cpp:0.2.0

stages:
- build
- test

workflow:
Expand All @@ -9,7 +10,21 @@ workflow:
when: never
- if: $CI_COMMIT_BRANCH == 'main'

Integration Tests:
.build_template: &build_definition
stage: build
script:
- cmake -B build -S .
- cmake --build build

build:linux:
<<: *build_definition
artifacts:
paths:
- build/

test:
stage: test
script:
- meson test -C /home/easbarba/app/build
- ./build/tests/onur_tests
dependencies:
- build:linux
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ along with Onur. If not, see <https://www.gnu.org/licenses/>.

# CHANGELOG

## 0.3.0

- feat: add action edit/view configurations

## 0.2.0

- feat: refactor, more tests and improve cli ui
Expand Down
24 changes: 22 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# Onur is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Onur is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Onur. If not, see <https://www.gnu.org/licenses/>.

cmake_minimum_required(VERSION 3.20.0)
project(Onur)
add_executable(onur src/main.cpp)
project(onur)

# Set C++ standard
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED True)

# Add subdirectories
add_subdirectory(src)
add_subdirectory(tests)
22 changes: 17 additions & 5 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,29 @@ CONTAINER_IMAGE := registry.gitlab.com/${USER}/${NAME}:${VERSION}
# ------------------------------------ TASKS

.PHONY: all
all:
all: cmake.all

.PHONY: dev
dev: cmake.dev

.PHONY: meson.all
meson.all:
CC=g++ meson setup $(BUILDDIR) --wipe
CC=g++ meson compile -C $(BUILDDIR)

.PHONY: dev
dev:

.PHONY: meson.dev
meson.dev:
CC=g++ meson setup $(BUILDDIR)
CC=g++ meson compile -C $(BUILDDIR)

.PHONY: cmake
cmake:
.PHONY: cmake.all
cmake.all: clean
cmake -B ${BUILDDIR} -S .
cmake --build ${BUILDDIR}

.PHONY: cmake.dev
cmake.dev:
cmake -B ${BUILDDIR} -S .
cmake --build ${BUILDDIR}

Expand Down
26 changes: 22 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,30 @@ Easily manage multiple FLOSS repositories.
| [ruby](https://gitlab.com/easbarba/onur-ruby)



## Usage

```shell
onur grab
onur backup nuxt awesomewm gitignore
# grab all projects
onur grab

# grab only the c projects
onur grab c

# list the cpp configuration file
onur config cpp

# list topics of haskell
onur config haskell.

# list only the projects on misc topic of lisp
onur config lisp.misc

# add a new configuration with theses entries in the topic misc of c
onur config c.misc cli11 https://github.com/cliutils/cli11 main

# back up these projects as tar.gz
onur backup ecmascript.nuxt lua.awesomewm misc.gitignore

onur --help
```

Expand Down Expand Up @@ -90,7 +108,7 @@ depth = 1

## Installation

`onur` requires a c++ 20 compiler and `meson` to install, locally at `$HOME/.local/bin`, easily with : `make all install`.
`onur` requires a c++ 23 compiler and `meson` or `cmake`: `make all`.

## Development

Expand Down
7 changes: 5 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@ along with Onur. If not, see <https://www.gnu.org/licenses/>.

### High

- verbose
- flag: --verbose
- validation of repository links
- actions: --filter rust
- actions: --filter rust:misc
- actions: --only rust,haskel,commonlisp
- actions: --exclude rust,haskel,commonlisp

### Mid
- actions: onur config c.misc foo https://git@gmasd main

### Low

- config: move on these to a syntax check class
Expand Down
2 changes: 1 addition & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ project(
'cpp',
license: 'GNU GPL version 3',
version: '0.2.0',
default_options: [ 'cpp_std=c++20', 'warning_level=3' ],
default_options: [ 'cpp_std=c++23', 'warning_level=3' ],
meson_version: '>=1.4.0',
)

Expand Down
39 changes: 39 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Onur is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Onur is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Onur. If not, see <https://www.gnu.org/licenses/>.

include(FetchContent)

FetchContent_Declare(
cli11
GIT_REPOSITORY https://github.com/CLIUtils/CLI11.git
GIT_TAG v2.4.1
)
FetchContent_MakeAvailable(cli11)

FetchContent_Declare(
json
GIT_REPOSITORY https://github.com/nlohmann/json.git
GIT_TAG v3.11.2
)
FetchContent_MakeAvailable(json)

add_executable(onur main.cpp
common/globals.cpp
database/parse.cpp
database/repository.cpp
domain/konfig.cpp
handlers/actions.cpp
handlers/commands.cpp
handlers/helpers.cpp)
target_link_libraries(onur PRIVATE CLI11::CLI11 nlohmann_json::nlohmann_json)
target_include_directories(onur PRIVATE ${PROJECT_SOURCE_DIR}/src/include)
68 changes: 57 additions & 11 deletions src/database/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
#include <filesystem>
#include <fstream>
#include <list>
#include <string>

#include <nlohmann/json.hpp>
#include <print>
#include <string>

#include "../include/cli.hpp"
#include "../include/konfig.hpp"
#include "../include/parse.hpp"
#include "../include/project.hpp"
Expand Down Expand Up @@ -52,29 +53,29 @@ auto
Parse::single (path filepath) -> Konfig
{
Konfig result;
map<string, list<Project> > subtopiks;
map<string, list<Project>> _topics;

auto configParsed = parse_file (contents_of (filepath));
result.topic = { filepath.stem () };
result.name = { filepath.stem () };

for (auto &[subtopic, subtopics] : configParsed.items ())
for (auto &[topic, topics] : configParsed.items ())
{
list<Project> projects;
for (auto projekt : subtopics)
for (auto project : topics)
{
string branch{ "master" };
if (!projekt["branch"].is_null ())
branch = projekt["branch"];
if (!project["branch"].is_null ())
branch = project["branch"];

auto pkt{ Project (projekt["name"], projekt["url"], branch) };
auto pkt{ Project (project["name"], project["url"], branch) };

projects.push_back (pkt);
}

subtopiks[subtopic] = { projects };
_topics[topic] = { projects };
}

result.subtopics = { subtopiks };
result.topics = { _topics };
return result;
}

Expand All @@ -90,3 +91,48 @@ Parse::contents_of (string path_to_file) -> string
ifstream file (path_to_file);
return { istreambuf_iterator<char> (file), istreambuf_iterator<char>{} };
}

auto
Parse::exist (std::string name) -> bool
{
for (auto config : multi ())
if (config.name == name)
return true;

// std::for_each (multi ().begin (), multi ().end (),
// [name, &result] (Konfig config) {
// std::println ("MEH");
// result = { config.name == name };
// std::println ("FOOL");
// });

return false;
}

// Overload the to_json function for automatic conversion
void
to_json (nlohmann::json &j, const Konfig &k)
{
j = k.to_json ();
}

auto
Parse::save (std::string name, std::string topic,
ConfigEntries entries) -> void
{
// if (entries.name || entries.url.has_value () || !entries.branch.empty ())
// {
// std::println ("Either name or url of project are missing. Exiting!");
// return;
// }

Project project{ entries };

std::map<std::string, std::list<Project>> topics;
topics[topic] = { entries };

Konfig konfig{ name, topics };
nlohmann::json j = konfig;

std::println ("Saving config with name {} as \n{}", konfig.name, j.dump ());
}
Loading

0 comments on commit 3c7bbe8

Please sign in to comment.