Skip to content

Commit 8cbdea7

Browse files
committed
Update true and false commands to use cli
1 parent 7200a43 commit 8cbdea7

File tree

2 files changed

+16
-48
lines changed

2 files changed

+16
-48
lines changed

src/bin/false.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,18 @@
11
#![feature(exitcode_exit_method)]
22

3-
use std::{
4-
io::{Write, stdout},
5-
os::unix::ffi::OsStrExt,
6-
process::ExitCode,
7-
};
3+
use std::{io::stdout, process::ExitCode};
84

9-
use coreutils::{Result, help_text, version_text};
10-
11-
const VERSION: &str = version_text!("false");
12-
const HELP: &str = help_text!("false");
5+
use coreutils::{Result, cli_with_args};
6+
use sap::Parser;
137

148
fn main() -> Result {
15-
let mut args = std::env::args_os();
9+
let args = std::env::args_os();
1610

1711
if args.len() == 2 {
18-
args.next();
19-
if let Some(arg) = args.next() {
20-
match arg.as_bytes() {
21-
b"--version" => {
22-
stdout().write_all(VERSION.as_bytes())?;
23-
return Ok(());
24-
}
25-
b"--help" => {
26-
stdout().write_all(HELP.as_bytes())?;
27-
return Ok(());
28-
}
29-
_ => {}
30-
}
31-
}
12+
let mut stdout = stdout();
13+
let mut args_parser = Parser::from_arbitrary(args)?;
14+
15+
cli_with_args!(args_parser, "false", stdout, #ignore);
3216
}
3317

3418
ExitCode::FAILURE.exit_process()

src/bin/true.rs

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,15 @@
1-
use std::{
2-
io::{Write, stdout},
3-
os::unix::ffi::OsStrExt,
4-
};
5-
6-
use coreutils::{Result, help_text, version_text};
7-
8-
const VERSION: &str = version_text!("true");
9-
const HELP: &str = help_text!("true");
1+
use coreutils::{Result, cli_with_args};
2+
use sap::Parser;
3+
use std::io::stdout;
104

115
fn main() -> Result {
12-
let mut args = std::env::args_os();
6+
let args = std::env::args_os();
137

148
if args.len() == 2 {
15-
args.next();
16-
if let Some(arg) = args.next() {
17-
match arg.as_bytes() {
18-
b"--version" => {
19-
stdout().write_all(VERSION.as_bytes())?;
20-
return Ok(());
21-
}
22-
b"--help" => {
23-
stdout().write_all(HELP.as_bytes())?;
24-
return Ok(());
25-
}
26-
_ => {}
27-
}
28-
}
9+
let mut stdout = stdout();
10+
let mut args_parser = Parser::from_arbitrary(args)?;
11+
12+
cli_with_args!(args_parser, "true", stdout, #ignore);
2913
}
3014

3115
Ok(())

0 commit comments

Comments
 (0)