Command: add new option --command-param

Fix #1255
This commit is contained in:
李通洲
2024-09-10 21:59:30 +08:00
parent a052033dc6
commit e8f711830e
4 changed files with 49 additions and 13 deletions
+4
View File
@@ -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"
+9
View File
@@ -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",
+35 -13
View File
@@ -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);
}
+1
View File
@@ -10,5 +10,6 @@ typedef struct FFCommandOptions
FFModuleArgs moduleArgs;
FFstrbuf shell;
FFstrbuf param;
FFstrbuf text;
} FFCommandOptions;