1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-26 00:59:24 -05:00

feat: support short flags for permissions (#24883)

This commit adds short CLI flags for following permission flags:
- "-R" for "--allow-read"
- "-W" for "--allow-write"
- "-E" for "--allow-env"
- "-N" for "--allow-net"
- "-S" for "--allow-sys"

---------

Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Ryan Dahl 2024-08-08 09:46:10 -04:00 committed by GitHub
parent ab8802f49b
commit 1d5927aaf2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3137,6 +3137,7 @@ fn permission_args(app: Command) -> Command {
.arg(
Arg::new("allow-read")
.long("allow-read")
.short('R')
.num_args(0..)
.use_value_delimiter(true)
.require_equals(true)
@ -3159,6 +3160,7 @@ fn permission_args(app: Command) -> Command {
.arg(
Arg::new("allow-write")
.long("allow-write")
.short('W')
.num_args(0..)
.use_value_delimiter(true)
.require_equals(true)
@ -3181,6 +3183,7 @@ fn permission_args(app: Command) -> Command {
.arg(
Arg::new("allow-net")
.long("allow-net")
.short('N')
.num_args(0..)
.use_value_delimiter(true)
.require_equals(true)
@ -3202,6 +3205,7 @@ fn permission_args(app: Command) -> Command {
.arg(
Arg::new("allow-env")
.long("allow-env")
.short('E')
.num_args(0..)
.use_value_delimiter(true)
.require_equals(true)
@ -3242,6 +3246,7 @@ fn permission_args(app: Command) -> Command {
.arg(
Arg::new("allow-sys")
.long("allow-sys")
.short('S')
.num_args(0..)
.use_value_delimiter(true)
.require_equals(true)
@ -5696,6 +5701,26 @@ mod tests {
);
}
#[test]
fn short_permission_flags() {
let r = flags_from_vec(svec!["deno", "run", "-RW", "gist.ts"]);
assert_eq!(
r.unwrap(),
Flags {
subcommand: DenoSubcommand::Run(RunFlags::new_default(
"gist.ts".to_string()
)),
permissions: PermissionFlags {
allow_read: Some(vec![]),
allow_write: Some(vec![]),
..Default::default()
},
code_cache_enabled: true,
..Flags::default()
}
);
}
#[test]
fn deny_read() {
let r = flags_from_vec(svec!["deno", "run", "--deny-read", "gist.ts"]);