Skip to content

Commit

Permalink
feat: edit/view configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
easbarba committed Aug 9, 2024
1 parent ab26aa1 commit c81b5af
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 26 deletions.
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: edit/view configurations

## 0.2.0

- feat: refactor, more tests and improve cli ui
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Easily manage multiple FLOSS repositories.
```shell
onur grab
onur backup nuxt awesomewm gitignore
onur edit c.misc cli11 https://github.com/cliutils/cli11 main
onur --help
```

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
6 changes: 3 additions & 3 deletions src/database/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ auto
Parse::single (path filepath) -> Konfig
{
Konfig result;
map<string, list<Project> > subtopiks;
map<string, list<Project>> subtopiks;

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

for (auto &[subtopic, subtopics] : configParsed.items ())
{
Expand All @@ -74,7 +74,7 @@ Parse::single (path filepath) -> Konfig
subtopiks[subtopic] = { projects };
}

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

Expand Down
46 changes: 36 additions & 10 deletions src/handlers/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@
*/

#include <filesystem>
#include <format>
#include <iostream>
#include <ostream>

#include "../include/commands.hpp"
#include "../include/globals.hpp"
#include "helpers.hpp"
#include "misc.hpp"

using std::cout;
using std::endl;
Expand All @@ -33,23 +35,22 @@ Commands::grab (void) -> void
{
for (auto single : parse.multi ())
{
cout << "\n " << single.topic << ":" << endl;
cout << "\n " << single.name << ":" << endl;

for (auto subtopic : single.subtopics)
for (auto topic : single.topics)
{
cout << " + " << subtopic.first << endl;
for (auto project : subtopic.second)
cout << " + " << topic.first << endl;
for (auto project : topic.second)
{
auto placeholder{ path (globals.projectsDir / single.topic
/ subtopic.first / project.name) };
auto dirpath{ placeholder };
auto finalpath{ path (globals.projectsDir / single.name
/ topic.first / project.name) };

printProjectInfo (project);

if (exists (dirpath / ".git" / "config"))
actions.pull (dirpath);
if (exists (finalpath / ".git" / "config"))
actions.pull (finalpath);
else
actions.klone (project, dirpath);
actions.klone (project, finalpath);
}

cout << endl;
Expand All @@ -62,3 +63,28 @@ Commands::backup (void) -> void
{
cout << "Backing up" << endl;
}

auto
Commands::edit (std::string config, Edit edit) -> void
{
for (auto single : parse.multi ())
{
if (config == single.name)
{
cout << "\n " << single.name << ":" << endl;
for (auto topic : single.topics)
{
cout << " + " << topic.first << endl;
for (auto project : topic.second)
{
printProjectInfo (project);
}
}
}

std::string m{ std::format ("{} {} {} {}", config,
edit.name.has_value (),
edit.url.has_value (), edit.branch) };
// cout << config << single.name << endl;
}
}
3 changes: 2 additions & 1 deletion src/include/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

#include "actions.hpp"
#include "globals.hpp"
#include "misc.hpp"
#include "parse.hpp"
#include "project.hpp"

class Commands
{
Expand All @@ -31,4 +31,5 @@ class Commands

auto grab (void) -> void;
auto backup (void) -> void;
auto edit (std::string config, Edit edit) -> void;
};
4 changes: 2 additions & 2 deletions src/include/konfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ class Konfig
public:
Konfig ();

std::string topic;
std::map<std::string, std::list<Project> > subtopics;
std::string name;
std::map<std::string, std::list<Project>> topics;
};
26 changes: 26 additions & 0 deletions src/include/misc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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/>.
*/

#pragma once

#include <optional>
#include <string>

struct Edit
{
std::optional<std::string> name;
std::optional<std::string> url;
std::string branch{ "master" };
};
25 changes: 17 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,37 +19,46 @@
#include <CLI/CLI.hpp>

#include "include/commands.hpp"
#include "include/misc.hpp"

using std::string;

auto
main (int argc, char *argv[]) -> int
{
CLI::App app{ "Easily manage multiple FLOSS repositories." };
app.require_subcommand (1);
argv = { app.ensure_utf8 (argv) };

string filename{ "default" };
app.add_option ("-f,--file", filename, "A help string");
app.set_version_flag ("--version", string ("0.0.1"));
app.set_version_flag ("--version", string ("0.2.0"));

CLI::App *grab_cmd{ app.add_subcommand ("grab", "grab all projects") };
CLI::App *backup_cmd{ app.add_subcommand (
"backup", "compress all selected projects") };
app.require_subcommand ();

CLI::App *edit_cmd{ app.add_subcommand ("edit", "manage configurations") };
std::string edit_config;
Edit edit;
edit_cmd->add_option ("config", edit_config, "Configuration name and topic")
->required (true);
edit_cmd->add_option ("name", edit.name, "Project name");
edit_cmd->add_option ("url", edit.url, "Project url");
edit_cmd->add_option ("branch", edit.branch, "Project branch");

CLI11_PARSE (app, argc, argv);

Commands commands;

if (*grab_cmd)
{
commands.grab ();
}
commands.grab ();

if (*backup_cmd)
{
commands.backup ();
}
commands.backup ();

if (*edit_cmd)
commands.edit (edit_config, edit);

return 0;
}

0 comments on commit c81b5af

Please sign in to comment.