mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
chroot: refactor undocumented features (#2365)
This commit is contained in:
parent
e35cafd2f2
commit
3347dacfc8
1 changed files with 22 additions and 10 deletions
|
@ -28,6 +28,7 @@ mod options {
|
||||||
pub const GROUP: &str = "group";
|
pub const GROUP: &str = "group";
|
||||||
pub const GROUPS: &str = "groups";
|
pub const GROUPS: &str = "groups";
|
||||||
pub const USERSPEC: &str = "userspec";
|
pub const USERSPEC: &str = "userspec";
|
||||||
|
pub const COMMAND: &str = "command";
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
|
@ -39,7 +40,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
.about(ABOUT)
|
.about(ABOUT)
|
||||||
.usage(SYNTAX)
|
.usage(SYNTAX)
|
||||||
.arg(Arg::with_name(options::NEWROOT).hidden(true).required(true))
|
.arg(
|
||||||
|
Arg::with_name(options::NEWROOT)
|
||||||
|
.hidden(true)
|
||||||
|
.required(true)
|
||||||
|
.index(1),
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name(options::USER)
|
Arg::with_name(options::USER)
|
||||||
.short("u")
|
.short("u")
|
||||||
|
@ -71,6 +77,12 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
)
|
)
|
||||||
.value_name("USER:GROUP"),
|
.value_name("USER:GROUP"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name(options::COMMAND)
|
||||||
|
.hidden(true)
|
||||||
|
.multiple(true)
|
||||||
|
.index(2),
|
||||||
|
)
|
||||||
.get_matches_from(args);
|
.get_matches_from(args);
|
||||||
|
|
||||||
let default_shell: &'static str = "/bin/sh";
|
let default_shell: &'static str = "/bin/sh";
|
||||||
|
@ -94,7 +106,14 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let command: Vec<&str> = match matches.args.len() {
|
let commands = match matches.values_of(options::COMMAND) {
|
||||||
|
Some(v) => v.collect(),
|
||||||
|
None => vec![],
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: refactor the args and command matching
|
||||||
|
// See: https://github.com/uutils/coreutils/pull/2365#discussion_r647849967
|
||||||
|
let command: Vec<&str> = match commands.len() {
|
||||||
1 => {
|
1 => {
|
||||||
let shell: &str = match user_shell {
|
let shell: &str = match user_shell {
|
||||||
Err(_) => default_shell,
|
Err(_) => default_shell,
|
||||||
|
@ -102,14 +121,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
};
|
};
|
||||||
vec![shell, default_option]
|
vec![shell, default_option]
|
||||||
}
|
}
|
||||||
_ => {
|
_ => commands,
|
||||||
let mut vector: Vec<&str> = Vec::new();
|
|
||||||
for (&k, v) in matches.args.iter() {
|
|
||||||
vector.push(k);
|
|
||||||
vector.push(v.vals[0].to_str().unwrap());
|
|
||||||
}
|
|
||||||
vector
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
set_context(newroot, &matches);
|
set_context(newroot, &matches);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue