1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
use serde::{Deserialize, Serialize};
/// Interpreter configuration with command, arguments, and file extension
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct Interpreter {
/// The command to execute (e.g., "bash", "node", "/usr/bin/python3")
pub command: String,
/// Additional arguments to pass before the script file (not including the command)
#[serde(default)]
pub args: Vec<String>,
/// File extension for the script (e.g., ".sh", ".js")
pub extension: String,
}
/// Returns the default interpreter configurations as (key, Interpreter) pairs
#[must_use]
pub fn default_interpreters() -> Vec<(String, Interpreter)> {
vec![
(
"bash".to_string(),
Interpreter {
command: "bash".to_string(),
args: vec![],
extension: ".sh".to_string(),
},
),
(
"batch".to_string(),
Interpreter {
command: "cmd".to_string(),
args: vec!["/c".to_string()],
extension: ".bat".to_string(),
},
),
(
"powershell".to_string(),
Interpreter {
command: "powershell".to_string(),
args: vec![
"-NoLogo".to_string(),
"-NoProfile".to_string(),
"-NonInteractive".to_string(),
"-ExecutionPolicy".to_string(),
"Bypass".to_string(),
"-File".to_string(),
],
extension: ".ps1".to_string(),
},
),
(
"pwsh".to_string(),
Interpreter {
command: "pwsh".to_string(),
args: vec![
"-NoLogo".to_string(),
"-NoProfile".to_string(),
"-NonInteractive".to_string(),
"-ExecutionPolicy".to_string(),
"Bypass".to_string(),
"-File".to_string(),
],
extension: ".ps1".to_string(),
},
),
(
"python".to_string(),
Interpreter {
command: "python3".to_string(),
args: vec![],
extension: ".py".to_string(),
},
),
(
"python3".to_string(),
Interpreter {
command: "python3".to_string(),
args: vec![],
extension: ".py".to_string(),
},
),
]
}
impl Interpreter {
/// Returns the file extension associated with the interpreter
#[must_use]
pub fn extension(&self) -> &str {
&self.extension
}
/// Returns the full command and arguments as a vector of strings
#[must_use]
pub fn is_valid(&self) -> bool {
!self.command.is_empty() && !self.extension.is_empty()
}
}