add config show command

This commit is contained in:
lucaspalomodevelop 2023-11-19 13:33:34 +01:00
parent dc471a91a6
commit cb577cfdf5
4 changed files with 82 additions and 1 deletions

View File

@ -31,6 +31,7 @@ void input(int argc, char *argv[])
command.addCommandAlias("remove", "r"); command.addCommandAlias("remove", "r");
command.addCommand("show", "[script] - Shows a script", showScript); command.addCommand("show", "[script] - Shows a script", showScript);
command.addCommandAlias("show", "s"); command.addCommandAlias("show", "s");
command.addCommand("config", "<command> - Configures autom", config);
command.addDefaultCommand(runScript); command.addDefaultCommand(runScript);
command.runCommand(argv[1], argc, argv); command.runCommand(argv[1], argc, argv);
@ -107,6 +108,54 @@ void runScript(int argc, char *argv[])
// } // }
} }
void config(int argc, char *argv[])
{
if (argc < 1)
{
std::cout << "Usage: autom config <command>" << std::endl;
return;
}
if (std::string(argv[1]) == "show")
{
std::cout << "Settings:" << std::endl;
std::cout << settings.getSettingsAsString() << std::endl;
}
// if (argv[2] == "editor")
// {
// std::cout << "Enter editor: ";
// std::string editor;
// std::cin >> editor;
// settings.value["editor"] = editor;
// settings.save();
// return;
// }
// if (argv[2] == "search_dirs")
// {
// std::cout << "Enter search dirs: ";
// std::string search_dirs;
// std::cin >> search_dirs;
// settings.value["search_dirs"] = search_dirs;
// settings.save();
// return;
// }
// if (argv[2] == "scripts")
// {
// std::cout << "Enter scripts: ";
// std::string scripts;
// std::cin >> scripts;
// settings.value["scripts"] = scripts;
// settings.save();
// return;
// }
// std::cout << "Command " << argv[2] << " does not exist" << std::endl;
}
void showScript(int argc, char *argv[]) void showScript(int argc, char *argv[])
{ {

View File

@ -22,6 +22,8 @@ Command command;
void input(int argc, char *argv[]); void input(int argc, char *argv[]);
// run a script with is in the autom directory // run a script with is in the autom directory
void runScript(int argc, char *argv[]); void runScript(int argc, char *argv[]);
// config function for configuring autom
void config(int argc, char *argv[]);
// list all scripts in the autom directory // list all scripts in the autom directory
void listScripts(int argc, char *argv[]); void listScripts(int argc, char *argv[]);
// add a script in the autom directory // add a script in the autom directory

View File

@ -24,4 +24,33 @@ void Settings::readSettings()
readSettings(); readSettings();
} }
this->value = json::parse(file); this->value = json::parse(file);
} }
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::set(std::string key, std::string value)
// {
// this->value[key] = value;
// writeSettings();
// }
// std::string Settings::get(std::string key)
// {
// return this->value[key];
// }
// void Settings::set(std::string key, int value)
// {
// this->value[key] = value;
// writeSettings();
// }

View File

@ -29,6 +29,7 @@ public:
Settings(void); Settings(void);
~Settings(void); ~Settings(void);
void readSettings(); void readSettings();
std::string getSettingsAsString();
Settings &operator=(const Settings &) = default; Settings &operator=(const Settings &) = default;
}; };