diff --git a/doc/json_schema.json b/doc/json_schema.json index fda68c2ab..db9e587b5 100644 --- a/doc/json_schema.json +++ b/doc/json_schema.json @@ -1236,6 +1236,10 @@ "description": "Set the shell program to execute the command text\nDefault: cmd for Windows, /bin/sh for *nix", "type": "string" }, + "param": { + "description": "Set the parameter used when starting the shell\nDefault: /c for Windows, -c for *nix", + "type": "string" + }, "text": { "description": "Set the command text to be executed", "type": "string" diff --git a/src/data/help.json b/src/data/help.json index a55402156..f6c1ffc2f 100644 --- a/src/data/help.json +++ b/src/data/help.json @@ -1376,6 +1376,15 @@ "default": "\"cmd\" for Windows; \"/bin/sh\" for *nix" } }, + { + "long": "command-param", + "desc": "Set the parameter used when starting the shell", + "remark": "Due to the difference of how OSes handle command line parameters, Windows will parse whitespaces as param separators, while *nix will not", + "arg": { + "type": "str", + "default": "\"/c\" for Windows; \"-c\" for *nix" + } + }, { "long": "command-key", "desc": "Set the module key to display", diff --git a/src/modules/command/command.c b/src/modules/command/command.c index fec6e721b..0db07b4bd 100644 --- a/src/modules/command/command.c +++ b/src/modules/command/command.c @@ -9,13 +9,13 @@ void ffPrintCommand(FFCommandOptions* options) { FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); - const char* error = ffProcessAppendStdOut(&result, (char* const[]){ + const char* error = ffProcessAppendStdOut(&result, options->param.length ? (char* const[]){ + options->shell.chars, + options->param.chars, + options->text.chars, + NULL + } : (char* const[]){ options->shell.chars, - #ifdef _WIN32 - "/c", - #else - "-c", - #endif options->text.chars, NULL }); @@ -58,6 +58,12 @@ bool ffParseCommandCommandOptions(FFCommandOptions* options, const char* key, co return true; } + if(ffStrEqualsIgnCase(subKey, "param")) + { + ffOptionParseString(key, value, &options->param); + return true; + } + if(ffStrEqualsIgnCase(subKey, "text")) { ffOptionParseString(key, value, &options->text); @@ -86,6 +92,12 @@ void ffParseCommandJsonObject(FFCommandOptions* options, yyjson_val* module) continue; } + if (ffStrEqualsIgnCase(key, "param")) + { + ffStrbufSetS(&options->param, yyjson_get_str(val)); + continue; + } + if (ffStrEqualsIgnCase(key, "text")) { ffStrbufSetS(&options->text, yyjson_get_str(val)); @@ -106,6 +118,9 @@ void ffGenerateCommandJsonConfig(FFCommandOptions* options, yyjson_mut_doc* doc, if (!ffStrbufEqual(&defaultOptions.shell, &options->shell)) yyjson_mut_obj_add_strbuf(doc, module, "shell", &options->shell); + if (!ffStrbufEqual(&defaultOptions.param, &options->param)) + yyjson_mut_obj_add_strbuf(doc, module, "param", &options->param); + if (!ffStrbufEqual(&defaultOptions.text, &options->text)) yyjson_mut_obj_add_strbuf(doc, module, "text", &options->text); } @@ -113,13 +128,13 @@ void ffGenerateCommandJsonConfig(FFCommandOptions* options, yyjson_mut_doc* doc, void ffGenerateCommandJsonResult(FF_MAYBE_UNUSED FFCommandOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) { FF_STRBUF_AUTO_DESTROY result = ffStrbufCreate(); - const char* error = ffProcessAppendStdOut(&result, (char* const[]){ + const char* error = ffProcessAppendStdOut(&result, options->param.length ? (char* const[]){ + options->shell.chars, + options->param.chars, + options->text.chars, + NULL + } : (char* const[]){ options->shell.chars, - #ifdef _WIN32 - "/c", - #else - "-c", - #endif options->text.chars, NULL }); @@ -168,7 +183,13 @@ void ffInitCommandOptions(FFCommandOptions* options) "/bin/sh" #endif ); - + ffStrbufInitStatic(&options->param, + #ifdef _WIN32 + "/c" + #else + "-c" + #endif + ); ffStrbufInit(&options->text); } @@ -176,5 +197,6 @@ void ffDestroyCommandOptions(FFCommandOptions* options) { ffOptionDestroyModuleArg(&options->moduleArgs); ffStrbufDestroy(&options->shell); + ffStrbufDestroy(&options->param); ffStrbufDestroy(&options->text); } diff --git a/src/modules/command/option.h b/src/modules/command/option.h index 6aab8a3c2..d30c51ea8 100644 --- a/src/modules/command/option.h +++ b/src/modules/command/option.h @@ -10,5 +10,6 @@ typedef struct FFCommandOptions FFModuleArgs moduleArgs; FFstrbuf shell; + FFstrbuf param; FFstrbuf text; } FFCommandOptions;