mirror of
https://github.com/lucaspalomodevelop/autom.git
synced 2026-03-12 23:27:21 +00:00
add -config edit editor-
This commit is contained in:
parent
cb577cfdf5
commit
8c7edfc55e
28
src/main.cpp
28
src/main.cpp
@ -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: ";
|
||||
|
||||
@ -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)
|
||||
// {
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user