forked from denoland/deno_task_shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset.rs
More file actions
62 lines (54 loc) · 1.54 KB
/
set.rs
File metadata and controls
62 lines (54 loc) · 1.54 KB
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
// Copyright 2018-2025 the Deno authors. MIT license.
use futures::future::LocalBoxFuture;
use crate::shell::types::EnvChange;
use crate::shell::types::ExecuteResult;
use super::ShellCommand;
use super::ShellCommandContext;
pub struct SetCommand;
impl ShellCommand for SetCommand {
fn execute(
&self,
mut context: ShellCommandContext,
) -> LocalBoxFuture<'static, ExecuteResult> {
let result = execute_set(&mut context);
Box::pin(futures::future::ready(result))
}
}
fn execute_set(context: &mut ShellCommandContext) -> ExecuteResult {
let mut changes = Vec::new();
let args: Vec<String> = context
.args
.iter()
.filter_map(|a| a.to_str().map(|s| s.to_string()))
.collect();
let mut i = 0;
while i < args.len() {
let arg = &args[i];
if arg == "-o" || arg == "+o" {
let enable = arg == "-o";
if i + 1 < args.len() {
let option_name = &args[i + 1];
match option_name.as_str() {
"pipefail" => {
changes.push(EnvChange::SetOption("pipefail".to_string(), enable));
}
_ => {
let _ = context
.stderr
.write_line(&format!("set: unknown option: {}", option_name));
return ExecuteResult::from_exit_code(1);
}
}
i += 2;
} else {
// No option name provided - in bash this would list options
// For now, just return success
i += 1;
}
} else {
// Unknown argument
i += 1;
}
}
ExecuteResult::Continue(0, changes, Vec::new())
}