mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
id: add error handling (stderr/exit_code) for '-ugG'
This commit is contained in:
parent
026570ff9c
commit
00c05b8687
2 changed files with 25 additions and 14 deletions
|
@ -201,6 +201,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
};
|
};
|
||||||
|
|
||||||
let line_ending = if zflag { '\0' } else { '\n' };
|
let line_ending = if zflag { '\0' } else { '\n' };
|
||||||
|
let mut exit_code = 0;
|
||||||
|
|
||||||
if gflag {
|
if gflag {
|
||||||
let id = possible_pw
|
let id = possible_pw
|
||||||
|
@ -209,13 +210,17 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
print!(
|
print!(
|
||||||
"{}{}",
|
"{}{}",
|
||||||
if nflag {
|
if nflag {
|
||||||
entries::gid2grp(id).unwrap_or_else(|_| id.to_string())
|
entries::gid2grp(id).unwrap_or_else(|_| {
|
||||||
|
show_error!("cannot find name for group ID {}", id);
|
||||||
|
exit_code = 1;
|
||||||
|
id.to_string()
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
id.to_string()
|
id.to_string()
|
||||||
},
|
},
|
||||||
line_ending
|
line_ending
|
||||||
);
|
);
|
||||||
return 0;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if uflag {
|
if uflag {
|
||||||
|
@ -225,13 +230,17 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
print!(
|
print!(
|
||||||
"{}{}",
|
"{}{}",
|
||||||
if nflag {
|
if nflag {
|
||||||
entries::uid2usr(id).unwrap_or_else(|_| id.to_string())
|
entries::uid2usr(id).unwrap_or_else(|_| {
|
||||||
|
show_error!("cannot find name for user ID {}", id);
|
||||||
|
exit_code = 1;
|
||||||
|
id.to_string()
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
id.to_string()
|
id.to_string()
|
||||||
},
|
},
|
||||||
line_ending
|
line_ending
|
||||||
);
|
);
|
||||||
return 0;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if gsflag {
|
if gsflag {
|
||||||
|
@ -246,7 +255,11 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.unwrap_or_else(|| entries::get_groups_gnu(Some(id)).unwrap())
|
.unwrap_or_else(|| entries::get_groups_gnu(Some(id)).unwrap())
|
||||||
.iter()
|
.iter()
|
||||||
.map(|&id| if nflag {
|
.map(|&id| if nflag {
|
||||||
entries::gid2grp(id).unwrap_or_else(|_| id.to_string())
|
entries::gid2grp(id).unwrap_or_else(|_| {
|
||||||
|
show_error!("cannot find name for group ID {}", id);
|
||||||
|
exit_code = 1;
|
||||||
|
id.to_string()
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
id.to_string()
|
id.to_string()
|
||||||
})
|
})
|
||||||
|
@ -254,7 +267,7 @@ pub fn uumain(args: impl uucore::Args) -> i32 {
|
||||||
.join(delimiter),
|
.join(delimiter),
|
||||||
line_ending
|
line_ending
|
||||||
);
|
);
|
||||||
return 0;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
if matches.is_present(options::OPT_PASSWORD) {
|
if matches.is_present(options::OPT_PASSWORD) {
|
||||||
|
|
|
@ -209,10 +209,9 @@ fn test_id_default_format() {
|
||||||
// u/g/G n/r
|
// u/g/G n/r
|
||||||
let args = [opt2, opt1];
|
let args = [opt2, opt1];
|
||||||
let result = scene.ucmd().args(&args).run();
|
let result = scene.ucmd().args(&args).run();
|
||||||
|
if !result.succeeded()
|
||||||
if !result.succeeded() && is_ci()
|
&& is_ci()
|
||||||
// && (result.stderr_str().contains("cannot find name for")
|
&& result.stderr_str().contains("cannot find name for")
|
||||||
// || result.stdout_str().contains("cannot find name for"))
|
|
||||||
{
|
{
|
||||||
// '--name' does not work on CICD ubuntu-16/ubuntu-18
|
// '--name' does not work on CICD ubuntu-16/ubuntu-18
|
||||||
// id: cannot find name for user ID 1001
|
// id: cannot find name for user ID 1001
|
||||||
|
@ -255,10 +254,9 @@ fn test_id_zero() {
|
||||||
// u/g/G n/r z
|
// u/g/G n/r z
|
||||||
let args = [opt2, z_flag, opt1];
|
let args = [opt2, z_flag, opt1];
|
||||||
let result = scene.ucmd().args(&args).run();
|
let result = scene.ucmd().args(&args).run();
|
||||||
|
if !result.succeeded()
|
||||||
if !result.succeeded() && is_ci()
|
&& is_ci()
|
||||||
// && (result.stderr_str().contains("cannot find name for")
|
&& result.stderr_str().contains("cannot find name for")
|
||||||
// || result.stdout_str().contains("cannot find name for"))
|
|
||||||
{
|
{
|
||||||
// '--name' does not work on CICD ubuntu-16/ubuntu-18
|
// '--name' does not work on CICD ubuntu-16/ubuntu-18
|
||||||
// id: cannot find name for user ID 1001
|
// id: cannot find name for user ID 1001
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue