diff --git a/FlowPluginsTs/CommunityFlowPlugins/tools/runCli/1.0.0/index.ts b/FlowPluginsTs/CommunityFlowPlugins/tools/runCli/1.0.0/index.ts index db10b0a..1d3455f 100644 --- a/FlowPluginsTs/CommunityFlowPlugins/tools/runCli/1.0.0/index.ts +++ b/FlowPluginsTs/CommunityFlowPlugins/tools/runCli/1.0.0/index.ts @@ -1,5 +1,5 @@ import { CLI } from '../../../../FlowHelpers/1.0.0/cliUtils'; -import { getContainer, getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils'; +import { getFileName, getPluginWorkDir } from '../../../../FlowHelpers/1.0.0/fileUtils'; import { IpluginDetails, IpluginInputArgs, @@ -34,7 +34,80 @@ const details = (): IpluginDetails => ({ }, tooltip: 'CLI to run', }, + { + label: 'Does Command Create Output File?', + name: 'doesCommandCreateOutputFile', + type: 'boolean', + defaultValue: 'true', + inputUI: { + type: 'switch', + }, + tooltip: + 'Toggle this on if the command creates an output file.', + }, + { + label: 'Output File Path', + name: 'userOutputFilePath', + type: 'string', + // eslint-disable-next-line no-template-curly-in-string + defaultValue: '${cacheDir}/${fileName}.{{{args.inputFileObj.container}}}', + inputUI: { + type: 'text', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'doesCommandCreateOutputFile', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: ` + This path can be accessed using \${outputFilePath} in the "CLI Arguments" input below. + + \\n + \${cacheDir} is a special variable that points to the Tdarr worker cache directory. + \\n + \${fileName} is a special variable for the filename without extension. + + \\nExample\\n + \${cacheDir}/\${fileName}.{{{args.inputFileObj.container}}} + `, + }, + { + label: 'Output File Becomes Working File?', + name: 'outputFileBecomesWorkingFile', + type: 'boolean', + defaultValue: 'true', + inputUI: { + type: 'switch', + displayConditions: { + logic: 'AND', + sets: [ + { + logic: 'AND', + inputs: [ + { + name: 'doesCommandCreateOutputFile', + value: 'true', + condition: '===', + }, + ], + }, + ], + }, + }, + tooltip: + 'Toggle this on to make the output file become the working file for the next plugin.', + }, { label: 'CLI Arguments', name: 'cliArguments', @@ -46,7 +119,7 @@ const details = (): IpluginDetails => ({ }, tooltip: `Specify arguments to pass to the CLI. Normal variable templating with {{{}}} applies but \${outputFilePath} is a special - variable for an output file in the Tdarr cache directory. + variable from the "Output File Path" input above. \\nExample\\n -o "\${outputFilePath}" "{{{args.inputFileObj._id}}}" @@ -68,12 +141,28 @@ const plugin = async (args: IpluginInputArgs): Promise => { args.inputs = lib.loadDefaultValues(args.inputs, details); let selectedCli = String(args.inputs.cli); + const { + outputFileBecomesWorkingFile, + } = args.inputs; + let userOutputFilePath = String(args.inputs.userOutputFilePath); let cliArguments = String(args.inputs.cliArguments); - const outputFilePath = `${getPluginWorkDir(args)}/${getFileName(args.inputFileObj._id)}` - + `.${getContainer(args.inputFileObj._id)}`; + // eslint-disable-next-line no-template-curly-in-string + if (cliArguments.includes('${outputFilePath}')) { + // eslint-disable-next-line no-template-curly-in-string + if (userOutputFilePath.includes('${cacheDir}')) { + const cacheDir = getPluginWorkDir(args); + userOutputFilePath = userOutputFilePath.replace(/\${cacheDir}/g, cacheDir); + } - cliArguments = cliArguments.replace(/\${outputFilePath}/g, outputFilePath); + // eslint-disable-next-line no-template-curly-in-string + if (userOutputFilePath.includes('${fileName}')) { + const fileName = getFileName(args.inputFileObj._id); + userOutputFilePath = userOutputFilePath.replace(/\${fileName}/g, fileName); + } + + cliArguments = cliArguments.replace(/\${outputFilePath}/g, userOutputFilePath); + } const cliArgs = [ ...args.deps.parseArgsStringToArgv(cliArguments, '', ''), @@ -99,7 +188,7 @@ const plugin = async (args: IpluginInputArgs): Promise => { spawnArgs: cliArgs, spawnOpts: {}, jobLog: args.jobLog, - outputFilePath, + outputFilePath: userOutputFilePath, inputFileObj: args.inputFileObj, logFullCliOutput: args.logFullCliOutput, updateWorker: args.updateWorker, @@ -114,9 +203,10 @@ const plugin = async (args: IpluginInputArgs): Promise => { } return { - outputFileObj: { - _id: outputFilePath, - }, + outputFileObj: outputFileBecomesWorkingFile ? { + _id: userOutputFilePath, + } + : args.inputFileObj, outputNumber: 1, variables: args.variables, };