create-config option
Some checks failed
Build-Test-Publish / build (linux/amd64) (push) Successful in 36s
Build-Test-Publish / build (linux/arm64) (push) Has been cancelled

This commit is contained in:
j
2025-12-28 12:45:51 +13:00
parent 55f55631aa
commit 82c30f1daa
3 changed files with 47 additions and 21 deletions

View File

@@ -18,7 +18,7 @@ namespace dropshell {
int edit_handler(const CommandContext& ctx);
static std::vector<std::string> edit_name_list={"edit"};
static std::vector<std::string> edit_name_list={"edit","create-config"};
// Static registration
struct EditCommandRegister {
@@ -87,13 +87,27 @@ bool edit_file(const std::string &file_path, bool has_bb64)
}
}
int create_config()
{
if (!gConfig().is_config_set())
{
bool ok = gConfig().save_config(); // save defaults.
info << "Default dropshell.json created." << std::endl;
return (ok ? 0 : 1);
}
else
info << "Existing dropshell.json unchanged." << std::endl;
return 0;
}
// ------------------------------------------------------------------------------------------------
// edit config
// ------------------------------------------------------------------------------------------------
int edit_config()
{
if (!gConfig().is_config_set())
gConfig().save_config(false); // save defaults.
create_config();
std::string config_file = localfile::dropshell_json();
if (!edit_file(config_file, false) || !std::filesystem::exists(config_file))
@@ -105,8 +119,9 @@ int edit_config()
// Don't save_config after loading - it would rewrite the file the user just edited!
// The config is already saved by the editor, we just validated it by loading it.
gConfig().create_aux_directories();
std::cout << "Successfully edited config file at " << config_file << std::endl;
info << "Successfully edited config file at " << config_file << std::endl;
return 0;
}
@@ -232,7 +247,16 @@ int edit_service_config(const std::string &server, const std::string &service)
int edit_handler(const CommandContext& ctx) {
// edit dropshell config
if (ctx.args.size() < 1)
return edit_config();
{
if (ctx.command=="create-config")
{
int rval = create_config();
gConfig().create_aux_directories();
return rval;
}
else
return edit_config();
}
// edit server config
if (ctx.args.size() < 2) {