Skip to content

Commit 0f122bd

Browse files
committed
uptime: Add -p, --pretty argument
1 parent 45b0c39 commit 0f122bd

File tree

19 files changed

+274
-118
lines changed

19 files changed

+274
-118
lines changed

Cargo.lock

Lines changed: 29 additions & 14 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
@@ -349,7 +349,7 @@ walkdir = "2.5"
349349
winapi-util = "0.1.8"
350350
windows-sys = { version = "0.59.0", default-features = false }
351351
xattr = "1.3.1"
352-
zip = { version = "2.2.2", default-features = false, features = ["deflate"] }
352+
zip = { version = "3.0.0", default-features = false, features = ["deflate"] }
353353

354354
hex = "0.4.3"
355355
md-5 = "0.10.6"

docs/src/extensions.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ also provides a `-v`/`--verbose` flag.
9292

9393
## `uptime`
9494

95-
Similar to the proc-ps implementation and unlike GNU/Coreutils, `uptime` provides `-s`/`--since` to show since when the system is up.
95+
Similar to the proc-ps implementation and unlike GNU/Coreutils, `uptime` provides:
96+
* `-s`/`--since` to show since when the system is up
97+
* `-p`/`--pretty` to display uptime in a pretty-printed format
9698

9799
## `base32/base64/basenc`
98100

fuzz/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.

src/uu/id/src/id.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
138138
selinux_supported: {
139139
#[cfg(feature = "selinux")]
140140
{
141-
selinux::kernel_support() != selinux::KernelSupport::Unsupported
141+
uucore::selinux::is_selinux_enabled()
142142
}
143143
#[cfg(not(feature = "selinux"))]
144144
{
@@ -174,13 +174,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
174174
));
175175
}
176176

177-
let delimiter = {
178-
if state.zflag {
179-
"\0".to_string()
180-
} else {
181-
" ".to_string()
182-
}
183-
};
177+
let delimiter = if state.zflag { "\0" } else { " " };
184178
let line_ending = LineEnding::from_zero_flag(state.zflag);
185179

186180
if state.cflag {
@@ -307,7 +301,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
307301
}
308302
})
309303
.collect::<Vec<_>>()
310-
.join(&delimiter),
304+
.join(delimiter),
311305
// NOTE: this is necessary to pass GNU's "tests/id/zero.sh":
312306
if state.zflag && state.user_specified && users.len() > 1 {
313307
"\0"

src/uu/ls/src/ls.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,7 @@ impl Config {
11571157
selinux_supported: {
11581158
#[cfg(feature = "selinux")]
11591159
{
1160-
selinux::kernel_support() != selinux::KernelSupport::Unsupported
1160+
uucore::selinux::is_selinux_enabled()
11611161
}
11621162
#[cfg(not(feature = "selinux"))]
11631163
{
@@ -2576,26 +2576,21 @@ fn display_items(
25762576

25772577
for item in items {
25782578
#[cfg(unix)]
2579-
if config.inode || config.alloc_size {
2580-
let more_info = display_additional_leading_info(
2581-
item,
2582-
&padding_collection,
2583-
config,
2584-
&mut state.out,
2585-
)?;
2586-
2587-
write!(state.out, "{more_info}")?;
2588-
}
2579+
let should_display_leading_info = config.inode || config.alloc_size;
25892580
#[cfg(not(unix))]
2590-
if config.alloc_size {
2581+
let should_display_leading_info = config.alloc_size;
2582+
2583+
if should_display_leading_info {
25912584
let more_info = display_additional_leading_info(
25922585
item,
25932586
&padding_collection,
25942587
config,
25952588
&mut state.out,
25962589
)?;
2590+
25972591
write!(state.out, "{more_info}")?;
25982592
}
2593+
25992594
display_item_long(item, &padding_collection, config, state, dired, quoted)?;
26002595
}
26012596
} else {

src/uu/mktemp/src/mktemp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,8 @@ fn make_temp_dir(dir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult
468468

469469
match builder.tempdir_in(dir) {
470470
Ok(d) => {
471-
// `into_path` consumes the TempDir without removing it
472-
let path = d.into_path();
471+
// `keep` consumes the TempDir without removing it
472+
let path = d.keep();
473473
Ok(path)
474474
}
475475
Err(e) if e.kind() == ErrorKind::NotFound => {

src/uu/pr/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ path = "src/pr.rs"
2020
[dependencies]
2121
clap = { workspace = true }
2222
uucore = { workspace = true, features = ["entries"] }
23-
quick-error = { workspace = true }
2423
itertools = { workspace = true }
2524
regex = { workspace = true }
2625
chrono = { workspace = true }
26+
thiserror = { workspace = true }
2727

2828
[[bin]]
2929
name = "pr"

src/uu/pr/src/pr.rs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
use chrono::{DateTime, Local};
1010
use clap::{Arg, ArgAction, ArgMatches, Command};
1111
use itertools::Itertools;
12-
use quick_error::ResultExt;
1312
use regex::Regex;
1413
use std::fs::{File, metadata};
1514
use std::io::{BufRead, BufReader, Lines, Read, Write, stdin, stdout};
1615
#[cfg(unix)]
1716
use std::os::unix::fs::FileTypeExt;
17+
use thiserror::Error;
1818

19-
use quick_error::quick_error;
2019
use uucore::display::Quotable;
2120
use uucore::error::UResult;
2221
use uucore::{format_usage, help_about, help_section, help_usage};
@@ -134,35 +133,21 @@ impl From<std::io::Error> for PrError {
134133
}
135134
}
136135

137-
quick_error! {
138-
#[derive(Debug)]
139-
enum PrError {
140-
Input(err: std::io::Error, path: String) {
141-
context(path: &'a str, err: std::io::Error) -> (err, path.to_owned())
142-
display("pr: Reading from input {path} gave error")
143-
source(err)
144-
}
145-
146-
UnknownFiletype(path: String) {
147-
display("pr: {path}: unknown filetype")
148-
}
149-
150-
EncounteredErrors(msg: String) {
151-
display("pr: {msg}")
152-
}
153-
154-
IsDirectory(path: String) {
155-
display("pr: {path}: Is a directory")
156-
}
157-
158-
IsSocket(path: String) {
159-
display("pr: cannot open {path}, Operation not supported on socket")
160-
}
161-
162-
NotExists(path: String) {
163-
display("pr: cannot open {path}, No such file or directory")
164-
}
165-
}
136+
#[derive(Debug, Error)]
137+
enum PrError {
138+
#[error("pr: Reading from input {1} gave error")]
139+
Input(std::io::Error, String),
140+
#[error("pr: {0}: unknown filetype")]
141+
UnknownFiletype(String),
142+
#[error("pr: {0}")]
143+
EncounteredErrors(String),
144+
#[error("pr: {0}: Is a directory")]
145+
IsDirectory(String),
146+
#[cfg(not(windows))]
147+
#[error("pr: cannot open {0}, Operation not supported on socket")]
148+
IsSocket(String),
149+
#[error("pr: cannot open {0}, No such file or directory")]
150+
NotExists(String),
166151
}
167152

168153
pub fn uu_app() -> Command {
@@ -795,9 +780,9 @@ fn open(path: &str) -> Result<Box<dyn Read>, PrError> {
795780
#[cfg(unix)]
796781
ft if ft.is_socket() => Err(PrError::IsSocket(path_string)),
797782
ft if ft.is_dir() => Err(PrError::IsDirectory(path_string)),
798-
ft if ft.is_file() || ft.is_symlink() => {
799-
Ok(Box::new(File::open(path).context(path)?) as Box<dyn Read>)
800-
}
783+
ft if ft.is_file() || ft.is_symlink() => Ok(Box::new(
784+
File::open(path).map_err(|e| PrError::Input(e, path.to_string()))?,
785+
) as Box<dyn Read>),
801786
_ => Err(PrError::UnknownFiletype(path_string)),
802787
}
803788
})

src/uu/runcon/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ path = "src/runcon.rs"
1919

2020
[dependencies]
2121
clap = { workspace = true }
22-
uucore = { workspace = true, features = ["entries", "fs", "perms"] }
22+
uucore = { workspace = true, features = ["entries", "fs", "perms", "selinux"] }
2323
selinux = { workspace = true }
2424
thiserror = { workspace = true }
2525
libc = { workspace = true }

0 commit comments

Comments
 (0)