add -config edit editor-

This commit is contained in:
lucaspalomodevelop 2023-11-19 16:36:50 +01:00
parent cb577cfdf5
commit 8c7edfc55e
3 changed files with 38 additions and 7 deletions

View File

@ -123,6 +123,34 @@ void config(int argc, char *argv[])
std::cout << settings.getSettingsAsString() << std::endl;
}
else if (std::string(argv[1]) == "edit")
{
if (argc > 2)
{
if (std::string(argv[2]) == "editor")
{
std::string editor;
if (argc > 3)
editor = argv[3];
else
{
std::cout << "Enter editor: ";
std::cin >> editor;
}
settings.value["editor"] = editor;
settings.writeSettings();
return;
}
return;
}
else
{
system((std::string(settings.value["editor"]) + " " + settings.filepath).c_str());
}
}
// if (argv[2] == "editor")
// {
// std::cout << "Enter editor: ";

View File

@ -7,6 +7,7 @@ Setup setup;
Settings::Settings(void)
{
setup = Setup();
filepath = setup.home + "/.automconfig.json";
readSettings();
}
@ -16,7 +17,7 @@ Settings::~Settings(void)
void Settings::readSettings()
{
std::ifstream file(setup.home + "/.automconfig.json");
std::ifstream file(filepath);
if (!file.is_open())
{
std::cout << "Error:" + setup.home + "/.automconfig.json not found" << std::endl;
@ -31,12 +32,12 @@ std::string Settings::getSettingsAsString()
return this->value.dump(4);
}
// void Settings::writeSettings()
// {
// std::ofstream file(setup.home + "/.automconfig.json");
// file << this->value.dump(4);
// file.close();
// }
void Settings::writeSettings()
{
std::ofstream file(setup.home + "/.automconfig.json");
file << this->value.dump(4);
file.close();
}
// void Settings::set(std::string key, std::string value)
// {

View File

@ -26,9 +26,11 @@ private:
public:
json value;
std::string filepath;
Settings(void);
~Settings(void);
void readSettings();
void writeSettings();
std::string getSettingsAsString();
Settings &operator=(const Settings &) = default;
};