mirror of
https://codeberg.org/icewind/haze.git
synced 2026-06-03 17:14:08 +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>,
|
||||
service: Option<ExecService>,
|
||||
command: Vec<String>,
|
||||
root: bool,
|
||||
},
|
||||
Occ {
|
||||
filter: Option<String>,
|
||||
|
|
@ -180,11 +181,20 @@ impl HazeArgs {
|
|||
_ => None,
|
||||
};
|
||||
|
||||
let root = match args.peek() {
|
||||
Some(arg) if arg.as_ref() == "root" => {
|
||||
args.next();
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
};
|
||||
|
||||
let command = args.map(S::into).collect();
|
||||
Ok(HazeArgs::Exec {
|
||||
filter,
|
||||
service,
|
||||
command,
|
||||
root,
|
||||
})
|
||||
}
|
||||
HazeCommand::Occ => Ok(HazeArgs::Occ {
|
||||
|
|
@ -508,6 +518,20 @@ fn test_arg_parse() {
|
|||
filter: None,
|
||||
service: None,
|
||||
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!(
|
||||
|
|
@ -520,6 +544,7 @@ fn test_arg_parse() {
|
|||
filter: Some("asdasd".to_string()),
|
||||
service: None,
|
||||
command: vec!["foo".to_string(), "bar".to_string()],
|
||||
root: false,
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
|
|
@ -532,6 +557,7 @@ fn test_arg_parse() {
|
|||
filter: Some("asdasd".to_string()),
|
||||
service: Some(ExecService::Db),
|
||||
command: vec!["foo".to_string(), "bar".to_string()],
|
||||
root: false,
|
||||
}
|
||||
);
|
||||
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::config::HazeConfig;
|
||||
use crate::database::DatabaseFamily;
|
||||
use crate::exec::container_logs;
|
||||
use crate::exec::{container_logs, exec, exec_tty};
|
||||
use crate::git::checkout_all;
|
||||
use crate::help::help;
|
||||
use crate::image::update_image;
|
||||
|
|
@ -117,22 +117,24 @@ async fn main() -> Result<ExitCode> {
|
|||
filter,
|
||||
service,
|
||||
command,
|
||||
root,
|
||||
} => {
|
||||
let cloud = Cloud::get_by_filter(&docker, filter, &config).await?;
|
||||
match service {
|
||||
None => {
|
||||
cloud
|
||||
.exec(
|
||||
&docker,
|
||||
if command.is_empty() {
|
||||
vec!["bash".to_string()]
|
||||
} else {
|
||||
command
|
||||
},
|
||||
atty::is(atty::Stream::Stdout),
|
||||
get_forward_env(),
|
||||
)
|
||||
.await?;
|
||||
let command = if command.is_empty() {
|
||||
vec!["bash".to_string()]
|
||||
} else {
|
||||
command
|
||||
};
|
||||
let env = get_forward_env();
|
||||
let tty = atty::is(atty::Stream::Stdout);
|
||||
let user = if root { "root" } else { "haze" };
|
||||
if tty {
|
||||
exec_tty(&docker, &cloud.id, user, command, env).await?;
|
||||
} else {
|
||||
exec(&docker, &cloud.id, user, command, env, Some(stdout())).await?;
|
||||
}
|
||||
}
|
||||
Some(ExecService::Db) => {
|
||||
cloud
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue