mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 09:04:12 +02:00
add exec root option
This commit is contained in:
parent
242cf54a74
commit
6a3058888f
2 changed files with 41 additions and 13 deletions
26
src/args.rs
26
src/args.rs
|
|
@ -25,6 +25,7 @@ pub enum HazeArgs {
|
||||||
filter: Option<String>,
|
filter: Option<String>,
|
||||||
service: Option<ExecService>,
|
service: Option<ExecService>,
|
||||||
command: Vec<String>,
|
command: Vec<String>,
|
||||||
|
root: bool,
|
||||||
},
|
},
|
||||||
Occ {
|
Occ {
|
||||||
filter: Option<String>,
|
filter: Option<String>,
|
||||||
|
|
@ -180,11 +181,20 @@ impl HazeArgs {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let root = match args.peek() {
|
||||||
|
Some(arg) if arg.as_ref() == "root" => {
|
||||||
|
args.next();
|
||||||
|
true
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
let command = args.map(S::into).collect();
|
let command = args.map(S::into).collect();
|
||||||
Ok(HazeArgs::Exec {
|
Ok(HazeArgs::Exec {
|
||||||
filter,
|
filter,
|
||||||
service,
|
service,
|
||||||
command,
|
command,
|
||||||
|
root,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
HazeCommand::Occ => Ok(HazeArgs::Occ {
|
HazeCommand::Occ => Ok(HazeArgs::Occ {
|
||||||
|
|
@ -508,6 +518,20 @@ fn test_arg_parse() {
|
||||||
filter: None,
|
filter: None,
|
||||||
service: None,
|
service: None,
|
||||||
command: vec!["foo".to_string(), "bar".to_string()],
|
command: vec!["foo".to_string(), "bar".to_string()],
|
||||||
|
root: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
assert_eq!(
|
||||||
|
HazeArgs::parse(
|
||||||
|
&config,
|
||||||
|
vec!["haze", "exec", "root", "foo", "bar"].into_iter()
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
HazeArgs::Exec {
|
||||||
|
filter: None,
|
||||||
|
service: None,
|
||||||
|
command: vec!["foo".to_string(), "bar".to_string()],
|
||||||
|
root: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -520,6 +544,7 @@ fn test_arg_parse() {
|
||||||
filter: Some("asdasd".to_string()),
|
filter: Some("asdasd".to_string()),
|
||||||
service: None,
|
service: None,
|
||||||
command: vec!["foo".to_string(), "bar".to_string()],
|
command: vec!["foo".to_string(), "bar".to_string()],
|
||||||
|
root: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -532,6 +557,7 @@ fn test_arg_parse() {
|
||||||
filter: Some("asdasd".to_string()),
|
filter: Some("asdasd".to_string()),
|
||||||
service: Some(ExecService::Db),
|
service: Some(ExecService::Db),
|
||||||
command: vec!["foo".to_string(), "bar".to_string()],
|
command: vec!["foo".to_string(), "bar".to_string()],
|
||||||
|
root: false,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
|
||||||
28
src/main.rs
28
src/main.rs
|
|
@ -4,7 +4,7 @@ use crate::args::{ExecService, HazeArgs};
|
||||||
use crate::cloud::{Cloud, CloudOptions};
|
use crate::cloud::{Cloud, CloudOptions};
|
||||||
use crate::config::HazeConfig;
|
use crate::config::HazeConfig;
|
||||||
use crate::database::DatabaseFamily;
|
use crate::database::DatabaseFamily;
|
||||||
use crate::exec::container_logs;
|
use crate::exec::{container_logs, exec, exec_tty};
|
||||||
use crate::git::checkout_all;
|
use crate::git::checkout_all;
|
||||||
use crate::help::help;
|
use crate::help::help;
|
||||||
use crate::image::update_image;
|
use crate::image::update_image;
|
||||||
|
|
@ -117,22 +117,24 @@ async fn main() -> Result<ExitCode> {
|
||||||
filter,
|
filter,
|
||||||
service,
|
service,
|
||||||
command,
|
command,
|
||||||
|
root,
|
||||||
} => {
|
} => {
|
||||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||||
match service {
|
match service {
|
||||||
None => {
|
None => {
|
||||||
cloud
|
let command = if command.is_empty() {
|
||||||
.exec(
|
vec!["bash".to_string()]
|
||||||
&docker,
|
} else {
|
||||||
if command.is_empty() {
|
command
|
||||||
vec!["bash".to_string()]
|
};
|
||||||
} else {
|
let env = get_forward_env();
|
||||||
command
|
let tty = atty::is(atty::Stream::Stdout);
|
||||||
},
|
let user = if root { "root" } else { "haze" };
|
||||||
atty::is(atty::Stream::Stdout),
|
if tty {
|
||||||
get_forward_env(),
|
exec_tty(&docker, &cloud.id, user, command, env).await?;
|
||||||
)
|
} else {
|
||||||
.await?;
|
exec(&docker, &cloud.id, user, command, env, Some(stdout())).await?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(ExecService::Db) => {
|
Some(ExecService::Db) => {
|
||||||
cloud
|
cloud
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue