mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
comm: return UResult from uumain() function
This commit is contained in:
parent
eb87ddbaf7
commit
2aebfc9f8d
2 changed files with 17 additions and 6 deletions
|
@ -11,6 +11,8 @@ use std::cmp::Ordering;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{self, stdin, BufRead, BufReader, Stdin};
|
use std::io::{self, stdin, BufRead, BufReader, Stdin};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
use uucore::error::FromIo;
|
||||||
|
use uucore::error::UResult;
|
||||||
use uucore::InvalidEncodingHandling;
|
use uucore::InvalidEncodingHandling;
|
||||||
|
|
||||||
use clap::{crate_version, App, Arg, ArgMatches};
|
use clap::{crate_version, App, Arg, ArgMatches};
|
||||||
|
@ -128,20 +130,21 @@ fn open_file(name: &str) -> io::Result<LineReader> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: impl uucore::Args) -> i32 {
|
#[uucore_procs::gen_uumain]
|
||||||
|
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
|
||||||
let usage = usage();
|
let usage = usage();
|
||||||
let args = args
|
let args = args
|
||||||
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
.collect_str(InvalidEncodingHandling::ConvertLossy)
|
||||||
.accept_any();
|
.accept_any();
|
||||||
|
|
||||||
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
|
let matches = uu_app().usage(&usage[..]).get_matches_from(args);
|
||||||
|
let filename1 = matches.value_of(options::FILE_1).unwrap();
|
||||||
let mut f1 = open_file(matches.value_of(options::FILE_1).unwrap()).unwrap();
|
let filename2 = matches.value_of(options::FILE_2).unwrap();
|
||||||
let mut f2 = open_file(matches.value_of(options::FILE_2).unwrap()).unwrap();
|
let mut f1 = open_file(filename1).map_err_context(|| filename1.to_string())?;
|
||||||
|
let mut f2 = open_file(filename2).map_err_context(|| filename2.to_string())?;
|
||||||
|
|
||||||
comm(&mut f1, &mut f2, &matches);
|
comm(&mut f1, &mut f2, &matches);
|
||||||
|
Ok(())
|
||||||
0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uu_app() -> App<'static, 'static> {
|
pub fn uu_app() -> App<'static, 'static> {
|
||||||
|
|
|
@ -170,3 +170,11 @@ fn no_arguments() {
|
||||||
fn one_argument() {
|
fn one_argument() {
|
||||||
new_ucmd!().arg("a").fails().no_stdout().no_stderr();
|
new_ucmd!().arg("a").fails().no_stdout().no_stderr();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_no_such_file() {
|
||||||
|
new_ucmd!()
|
||||||
|
.args(&["bogus_file_1", "bogus_file_2"])
|
||||||
|
.fails()
|
||||||
|
.stderr_only("comm: bogus_file_1: No such file or directory");
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue