Open andykais opened 2 months ago
update: I do seem to have found a way to get this working with the following code:
function forager_cli(strings: TemplateStringsArray, ...params: any[]) {
const cli_entrypoint = path.join(path.resolve(import.meta.dirname!, '..'), 'src/cli.ts')
const forager_bin = `deno run --check -A --unstable-ffi ${$.escapeArg(cli_entrypoint)}`
let command_string = ''
for (let index = 0; index < strings.length - 1; index++) {
const string_part = strings[index]
const param = params[index]
command_string += string_part + $.escapeArg(param)
}
command_string += strings.at(-1)
return $.raw`${forager_bin} ${command_string}`.stdout('piped')
}
// usage
await forager_cli`create ${test_resources.somefile} --tag=wallpaper`
const output = forager_cli`--log-level=json search --tag wallpaper`.json()
Ill leave this open for a day or two for a maintainer to peak at, but my use case is handled!
Hi there, I am getting used to using dax for testing a cli tool I am building in deno. Usage of that cli might look like
forager search --tag foobar
. Generally this means I want to have test scripts run something like so:This is a little verbose though, so I have trying to come up with a way to shorthand the first bit of boilerplate in that command into something like so:
this doesnt seem to be a viable option however, and I get errors like this from dax:
I have had success using
$.raw
like so:however I do like the auto-escape behavior dax provides, since this is another common command I want to run inside tests:
and that feels a tag verbose. Generally I am hoping there is a way to tell dax to not escape that first part of the command, or use some kind of builder pattern for dax that makes this more practical. This may not be possible but I figured its worth asking!