feat(cli): add warning for incorrectly ordered flags (#16734)

This code checks if permission flags are incorrectly defined after the
module name (e.g. `deno run mod.ts --allow-read` instead of the correct
`deno run --allow-read mod.ts`). If so, a simple warning is displayed.
This commit is contained in:
Asher Gomez 2022-11-24 14:00:31 +11:00 committed by GitHub
parent beaa0d8867
commit fe7e3a12ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 70 additions and 0 deletions

View file

@ -686,6 +686,17 @@ async fn run_command(
return run_from_stdin(flags).await;
}
if !flags.has_permission() && flags.has_permission_in_argv() {
log::warn!(
"{}",
crate::colors::yellow(
r#"Permission flags have likely been incorrectly set after the script argument.
To grant permissions, set them before the script argument. For example:
deno run --allow-read=. main.js"#
)
);
}
if flags.watch.is_some() {
return run_with_watch(flags, run_flags.script).await;
}