Skip to content

Commit 461f693

Browse files
committed
Update to sap v5
1 parent 7578d87 commit 461f693

File tree

8 files changed

+21
-22
lines changed

8 files changed

+21
-22
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ rustix = { version = "1.0.7", features = [
2626
"fs",
2727
"stdio",
2828
] }
29-
sap = "0.0.4"
29+
sap = "0.0.5"

src/bin/cat.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub fn main() -> Result {
1212
cli! {
1313
"cat", stdout, #error
1414
Value(value) => {
15-
files.push(value.to_owned());
15+
files.push(value.into_owned());
1616
}
1717
};
1818

@@ -30,7 +30,7 @@ pub fn main() -> Result {
3030
let mut stdin = BufReader::new(stdin());
3131
io::copy(&mut stdin, &mut stdout)?;
3232
} else {
33-
let mut reader = BufReader::new(File::open(&file_path)?); // Is it fine to error here? or should we keep going
33+
let mut reader = BufReader::new(File::open(file_path)?); // Is it fine to error here? or should we keep going
3434
io::copy(&mut reader, &mut stdout)?;
3535
}
3636
}

src/bin/false.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustix::process::EXIT_FAILURE;
55
use sap::Parser;
66

77
pub fn main() -> Result {
8-
let args = std::env::args_os();
8+
let args = std::env::args();
99

1010
if args.len() == 2 {
1111
let mut stdout = stdout();

src/bin/mkdir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub fn main() -> Result {
1111
cli! {
1212
"mkdir", stdout, #error
1313
Value(value) => {
14-
dirs.push(value.to_owned()); // FIXME: I am not a fan of all this allocation but we can't easily move out of the argument parser
14+
dirs.push(value.into_owned()); // FIXME: I am not a fan of all this allocation but we can't easily move out of the argument parser
1515
}
1616
};
1717

src/bin/true.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use sap::Parser;
33
use std::io::stdout;
44

55
pub fn main() -> Result {
6-
let args = std::env::args_os();
6+
let args = std::env::args();
77

88
if args.len() == 2 {
99
let mut stdout = stdout();

src/bin/wc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub fn main() -> Result {
5151
Short('m') | Long("chars") => flags |= Flags::CHARS
5252
Short('c') | Long("bytes") => flags |= Flags::BYTES
5353
Value(value) => {
54-
files.push(value.to_owned());
54+
files.push(value.into_owned());
5555
}
5656
};
5757

@@ -63,7 +63,7 @@ pub fn main() -> Result {
6363

6464
// If no files, read from stdin
6565
if files.is_empty() {
66-
files.push("-".to_string());
66+
files.push("-".into());
6767
}
6868

6969
for path in files {

src/bin/yes.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::{
22
borrow::Cow,
33
io::{BufWriter, Write, stdout},
4-
os::unix::ffi::OsStringExt,
54
};
65

76
use puppyutils::{Result, cli};
@@ -10,40 +9,40 @@ pub fn main() -> Result {
109
// No point in locking stdout since we only use it once in this program
1110
let mut stdout = stdout();
1211

13-
let mut buffer: Option<Vec<u8>> = None;
12+
let mut buffer = None;
1413

1514
let arg_parser = cli! {
1615
"yes", stdout, #error
1716
Value(value) => {
18-
extend_buffer(&mut buffer, value.as_bytes().to_vec());
17+
extend_buffer(&mut buffer, value);
1918
}
2019
};
2120

2221
arg_parser
2322
.into_inner()
24-
.for_each(|arg| extend_buffer(&mut buffer, arg.into_vec()));
23+
.for_each(|arg| extend_buffer(&mut buffer, arg.into()));
2524

26-
let output: Cow<'_, [u8]> = if let Some(mut buffer) = buffer {
27-
buffer.push(b'\n');
25+
let output = if let Some(mut buffer) = buffer {
26+
buffer.push('\n');
2827
Cow::Owned(buffer)
2928
} else {
30-
Cow::Borrowed(b"y\n")
29+
Cow::Borrowed("y\n")
3130
};
3231

3332
// Write everything to stdout, BufWriter will handle the buffering
3433
let mut stdout = BufWriter::new(stdout);
3534

3635
loop {
37-
stdout.write_all(&output)?;
36+
stdout.write_all(output.as_bytes())?;
3837
}
3938
}
4039

4140
#[inline]
42-
fn extend_buffer(buffer: &mut Option<Vec<u8>>, mut arg: Vec<u8>) {
41+
fn extend_buffer(buffer: &mut Option<String>, arg: Cow<'_, str>) {
4342
if let Some(buffer) = buffer {
44-
buffer.push(b' '); // Manually put the space
45-
buffer.append(&mut arg);
43+
buffer.push(' '); // Manually put the space
44+
buffer.push_str(arg.as_ref());
4645
} else {
47-
*buffer = Some(arg)
46+
*buffer = Some(arg.into_owned())
4847
}
4948
}

0 commit comments

Comments
 (0)