You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am creating a CLI app that have input arguments based on this example (I am learning Rust).
When I run nx run my_app:run --args="file1 file2", which is the typical Nx ways of forwarding arguments to the ran command. However, the buildCommand function push them as-is in-between other args destined for cargo run.
The resulting command built is cargo run --target-dir dist/target/my_app --args file1 file2 -p my_app, but cargo run --target-dir dist/target/my_app -p my_app -- file1 file2 should be the one expected.
Actual command with Nx VS expected cargo command
actual
nx run my_app:run --args="file1 file2"> nx run my_app:run --args=file1 file2
> cargo run --target-dir dist/target/my_app --args file1 file2 -p my_app
error: unexpected argument '--args' found
tip: a similar argument exists: '--target'
tip: to pass '--args' as a value, use '-- --args'
Usage: cargo run --target-dir <DIRECTORY> --target [<TRIPLE>] [ARGS]...
For more information, try '--help'.
NX [object Object]
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
NX Ran target run for project my_app (631ms)
With additional flags:
--args=file1 file2
✖ 1/1 failed
✔ 0/1 succeeded [0 read from cache]
I think a test case could be written as below. Maybe the last entry "file1 file2", should be two elements, but I think Nx pass the whole thing as a string to the executor.
I'll see if I can submit a proper PR later on.
it('user arguments (--args) should be put at the end after --',()=>{constcommand=buildCommand('run',{args: "file1 file2"},context);expect(command).toMatchInlineSnapshot(` Array [ "run", "-p", "project", "--", "file1 file2", ] `);
And the buildCommand could be modified as such.
export function buildCommand(
baseCommand: string,
options: BaseOptions,
context: ExecutorContext
): string[] {
const args = [];
if (options.toolchain && options.toolchain !== 'stable') {
args.push(`+${options.toolchain}`);
}
args.push(baseCommand);
for (const [key, value] of Object.entries(options)) {
if (key === 'toolchain') {
continue;
}
+ if (key === 'args') {+ continue;+ }
if (typeof value === 'boolean') {
// false flags should not be added to the cargo args
if (value) {
args.push(`--${key}`);
}
} else if (Array.isArray(value)) {
for (const item of value) {
args.push(`--${key}`, item);
}
} else {
args.push(`--${key}`, value);
}
}
if (!args.includes("--package")) {
args.push("-p", context.projectName);
}
+ if (options.args) {+ args.push("--", options.args);+ }
return args;
}
The text was updated successfully, but these errors were encountered:
It appears there is already PR #42 for that! But I am not sure if it's the right approach using -- with the Nx run command, as their way of forwarding arguments is using --args as shown in their docs.
sharky98
added a commit
to sharky98/monodon
that referenced
this issue
Dec 20, 2024
I am creating a CLI app that have input arguments based on this example (I am learning Rust).
When I run
nx run my_app:run --args="file1 file2"
, which is the typical Nx ways of forwarding arguments to the ran command. However, thebuildCommand
function push them as-is in-between other args destined forcargo run
.The resulting command built is
cargo run --target-dir dist/target/my_app --args file1 file2 -p my_app
, butcargo run --target-dir dist/target/my_app -p my_app -- file1 file2
should be the one expected.Actual command with Nx VS expected cargo command
actual
expected
I think a test case could be written as below. Maybe the last entry
"file1 file2",
should be two elements, but I think Nx pass the whole thing as a string to the executor.I'll see if I can submit a proper PR later on.
And the
buildCommand
could be modified as such.The text was updated successfully, but these errors were encountered: