atento_core/
interpreter.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Clone, Deserialize, Serialize)]
5pub struct Interpreter {
6 pub command: String,
8 #[serde(default)]
10 pub args: Vec<String>,
11 pub extension: String,
13}
14
15#[must_use]
17pub fn default_interpreters() -> Vec<(String, Interpreter)> {
18 vec![
19 (
20 "bash".to_string(),
21 Interpreter {
22 command: "bash".to_string(),
23 args: vec![],
24 extension: ".sh".to_string(),
25 },
26 ),
27 (
28 "batch".to_string(),
29 Interpreter {
30 command: "cmd".to_string(),
31 args: vec!["/c".to_string()],
32 extension: ".bat".to_string(),
33 },
34 ),
35 (
36 "powershell".to_string(),
37 Interpreter {
38 command: "powershell".to_string(),
39 args: vec![
40 "-NoLogo".to_string(),
41 "-NoProfile".to_string(),
42 "-NonInteractive".to_string(),
43 "-ExecutionPolicy".to_string(),
44 "Bypass".to_string(),
45 "-File".to_string(),
46 ],
47 extension: ".ps1".to_string(),
48 },
49 ),
50 (
51 "pwsh".to_string(),
52 Interpreter {
53 command: "pwsh".to_string(),
54 args: vec![
55 "-NoLogo".to_string(),
56 "-NoProfile".to_string(),
57 "-NonInteractive".to_string(),
58 "-ExecutionPolicy".to_string(),
59 "Bypass".to_string(),
60 "-File".to_string(),
61 ],
62 extension: ".ps1".to_string(),
63 },
64 ),
65 (
66 "python".to_string(),
67 Interpreter {
68 command: "python3".to_string(),
69 args: vec![],
70 extension: ".py".to_string(),
71 },
72 ),
73 (
74 "python3".to_string(),
75 Interpreter {
76 command: "python3".to_string(),
77 args: vec![],
78 extension: ".py".to_string(),
79 },
80 ),
81 ]
82}
83
84impl Interpreter {
85 #[must_use]
87 pub fn extension(&self) -> &str {
88 &self.extension
89 }
90
91 #[must_use]
93 pub fn is_valid(&self) -> bool {
94 !self.command.is_empty() && !self.extension.is_empty()
95 }
96}