Skip to content

Commit dc410cd

Browse files
committed
make cmd and sidecar exclusive
1 parent 4e89ec7 commit dc410cd

File tree

1 file changed

+82
-61
lines changed

1 file changed

+82
-61
lines changed

plugins/shell/build.rs

Lines changed: 82 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,38 @@ impl Default for ShellScopeEntryAllowedArgs {
6565

6666
/// Shell scope entry.
6767
#[derive(JsonSchema)]
68+
#[serde(untagged, deny_unknown_fields)]
6869
#[allow(unused)]
69-
pub(crate) struct ShellScopeEntry {
70-
/// The name for this allowed shell command configuration.
71-
///
72-
/// This name will be used inside of the webview API to call this command along with
73-
/// any specified arguments.
74-
name: String,
75-
/// The command name.
76-
/// It can start with a variable that resolves to a system base directory.
77-
/// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
78-
/// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
79-
/// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$LOG`, `$TEMP`, `$APPCONFIG`, `$APPDATA`,
80-
/// `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.
81-
// use default just so the schema doesn't flag it as required
82-
#[serde(rename = "cmd")]
83-
command: Option<PathBuf>,
84-
/// The allowed arguments for the command execution.
85-
#[serde(default)]
86-
args: ShellScopeEntryAllowedArgs,
87-
/// If this command is a sidecar command.
88-
#[serde(default)]
89-
sidecar: bool,
70+
pub(crate) enum ShellScopeEntry {
71+
Command {
72+
/// The name for this allowed shell command configuration.
73+
///
74+
/// This name will be used inside of the webview API to call this command along with
75+
/// any specified arguments.
76+
name: String,
77+
/// The command name.
78+
/// It can start with a variable that resolves to a system base directory.
79+
/// The variables are: `$AUDIO`, `$CACHE`, `$CONFIG`, `$DATA`, `$LOCALDATA`, `$DESKTOP`,
80+
/// `$DOCUMENT`, `$DOWNLOAD`, `$EXE`, `$FONT`, `$HOME`, `$PICTURE`, `$PUBLIC`, `$RUNTIME`,
81+
/// `$TEMPLATE`, `$VIDEO`, `$RESOURCE`, `$LOG`, `$TEMP`, `$APPCONFIG`, `$APPDATA`,
82+
/// `$APPLOCALDATA`, `$APPCACHE`, `$APPLOG`.
83+
// use default just so the schema doesn't flag it as required
84+
#[serde(rename = "cmd")]
85+
command: PathBuf,
86+
/// The allowed arguments for the command execution.
87+
args: ShellScopeEntryAllowedArgs,
88+
},
89+
SideCar {
90+
/// The name for this allowed shell command configuration.
91+
///
92+
/// This name will be used inside of the webview API to call this command along with
93+
/// any specified arguments.
94+
name: String,
95+
/// The allowed arguments for the command execution.
96+
args: ShellScopeEntryAllowedArgs,
97+
/// If this command is a sidecar command.
98+
sidecar: bool,
99+
},
90100
}
91101

92102
// Ensure `ShellScopeEntry` and `scope_entry::EntryRaw`
@@ -95,48 +105,59 @@ pub(crate) struct ShellScopeEntry {
95105
// are kept in sync
96106
#[allow(clippy::unnecessary_operation)]
97107
fn _f() {
98-
let v = scope_entry::EntryRaw {
108+
match (ShellScopeEntry::SideCar {
99109
name: String::new(),
100-
command: None,
101-
args: scope_entry::ShellAllowedArgs::default(),
102-
sidecar: false,
103-
};
104-
105-
ShellScopeEntry {
106-
name: v.name,
107-
command: v.command,
108-
args: match v.args {
109-
scope_entry::ShellAllowedArgs::Flag(flag) => ShellScopeEntryAllowedArgs::Flag(flag),
110-
scope_entry::ShellAllowedArgs::List(vec) => ShellScopeEntryAllowedArgs::List(
111-
vec.into_iter()
112-
.map(|s| match s {
113-
scope_entry::ShellAllowedArg::Fixed(fixed) => {
114-
ShellScopeEntryAllowedArg::Fixed(fixed)
115-
}
116-
scope_entry::ShellAllowedArg::Var { validator, raw } => {
117-
ShellScopeEntryAllowedArg::Var { validator, raw }
118-
}
119-
})
120-
.collect(),
121-
),
110+
args: ShellScopeEntryAllowedArgs::Flag(false),
111+
sidecar: true,
112+
}) {
113+
ShellScopeEntry::Command {
114+
name,
115+
command,
116+
args,
117+
} => scope_entry::EntryRaw {
118+
name,
119+
command: Some(command),
120+
args: match args {
121+
ShellScopeEntryAllowedArgs::Flag(flag) => scope_entry::ShellAllowedArgs::Flag(flag),
122+
ShellScopeEntryAllowedArgs::List(vec) => scope_entry::ShellAllowedArgs::List(
123+
vec.into_iter()
124+
.map(|s| match s {
125+
ShellScopeEntryAllowedArg::Fixed(fixed) => {
126+
scope_entry::ShellAllowedArg::Fixed(fixed)
127+
}
128+
ShellScopeEntryAllowedArg::Var { validator, raw } => {
129+
scope_entry::ShellAllowedArg::Var { validator, raw }
130+
}
131+
})
132+
.collect(),
133+
),
134+
},
135+
sidecar: false,
136+
},
137+
ShellScopeEntry::SideCar {
138+
name,
139+
args,
140+
sidecar,
141+
} => scope_entry::EntryRaw {
142+
name,
143+
command: None,
144+
args: match args {
145+
ShellScopeEntryAllowedArgs::Flag(flag) => scope_entry::ShellAllowedArgs::Flag(flag),
146+
ShellScopeEntryAllowedArgs::List(vec) => scope_entry::ShellAllowedArgs::List(
147+
vec.into_iter()
148+
.map(|s| match s {
149+
ShellScopeEntryAllowedArg::Fixed(fixed) => {
150+
scope_entry::ShellAllowedArg::Fixed(fixed)
151+
}
152+
ShellScopeEntryAllowedArg::Var { validator, raw } => {
153+
scope_entry::ShellAllowedArg::Var { validator, raw }
154+
}
155+
})
156+
.collect(),
157+
),
158+
},
159+
sidecar,
122160
},
123-
sidecar: v.sidecar,
124-
};
125-
126-
match ShellScopeEntryAllowedArgs::Flag(false) {
127-
ShellScopeEntryAllowedArgs::Flag(flag) => scope_entry::ShellAllowedArgs::Flag(flag),
128-
ShellScopeEntryAllowedArgs::List(vec) => scope_entry::ShellAllowedArgs::List(
129-
vec.into_iter()
130-
.map(|s| match s {
131-
ShellScopeEntryAllowedArg::Fixed(fixed) => {
132-
scope_entry::ShellAllowedArg::Fixed(fixed)
133-
}
134-
ShellScopeEntryAllowedArg::Var { validator, raw } => {
135-
scope_entry::ShellAllowedArg::Var { validator, raw }
136-
}
137-
})
138-
.collect(),
139-
),
140161
};
141162
}
142163

0 commit comments

Comments
 (0)