Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last Utility #65

Merged
merged 29 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4f1d377
Add the initial implementation of the last utility
Puffy1215 Jul 3, 2024
0443684
tests: Added tests for last util
Puffy1215 Jul 6, 2024
6349faf
last: Reformatted unix.rs
Puffy1215 Jul 10, 2024
79564b6
last: Fixed time formatting issues
Puffy1215 Jul 11, 2024
33d831e
last: Fixed missing "- crash" message
Puffy1215 Jul 15, 2024
3dac6f0
last: Removed wtmp check in test
Puffy1215 Jul 15, 2024
da300ea
last: Fixed documentation and help output
Puffy1215 Jul 15, 2024
47be2f7
last: Removed unused imports
Puffy1215 Jul 15, 2024
332ddd6
last: Added licensing to files
Puffy1215 Jul 15, 2024
2336aec
last: Remove unneeded comment from Cargo.toml
Puffy1215 Jul 16, 2024
9dca98a
last: Replace unwrap with unwrap_or_default
Puffy1215 Jul 16, 2024
f0c2dd9
last: Remove unneeded comment from test
Puffy1215 Jul 17, 2024
0f36ea9
last: Remove unused variable and is_quoted function
Puffy1215 Jul 17, 2024
5639ac2
last: Fix clippy warnings
Puffy1215 Jul 17, 2024
8ca0cf2
last: Simplified last test case
Puffy1215 Jul 17, 2024
aa71ca0
last: Fix Cargo formatting errors
Puffy1215 Jul 17, 2024
e0bb411
last: Limit Unix module to just Unix
Puffy1215 Jul 17, 2024
2687722
last: Generalized regex test
Puffy1215 Jul 17, 2024
dfa118b
last: Account for unsupported Windows module
Puffy1215 Jul 17, 2024
d5b0fc6
last: Remove macOS from -x test
Puffy1215 Jul 17, 2024
e73a608
Added earliest timestamp message in output
Puffy1215 Jul 29, 2024
fd64c73
Added test_short_invalid_utmp_file
Puffy1215 Jul 29, 2024
1abe14e
Linted code (unix.rs and test_last.rs) to standard
Puffy1215 Jul 29, 2024
9edae58
Fixed file start time to use correct formatting. Optimized
Puffy1215 Jul 30, 2024
4e5c481
Fixed regex in test. Added str constants for time formatting
Puffy1215 Jul 30, 2024
d84a6ac
last: fix invalid cfg in test
cakebaker Sep 19, 2024
58e7b69
last: ignore failing test
cakebaker Sep 19, 2024
95d83aa
last: fix clippy warnings
cakebaker Sep 19, 2024
633aea3
last: use MetaDataExt for unix instead of linux
cakebaker Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
289 changes: 212 additions & 77 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ feat_common_core = [
"lsmem",
"ctrlaltdel",
"rev",
"last"
]

[workspace.dependencies]
Expand All @@ -50,6 +51,7 @@ rand = { version = "0.8", features = ["small_rng"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.122"
tabled = "0.16.0"
dns-lookup = "2.0.4"

[dependencies]
clap = { workspace = true }
Expand All @@ -58,13 +60,15 @@ clap_mangen = { workspace = true }
uucore = { workspace = true }
phf = { workspace = true }
textwrap = { workspace = true }
dns-lookup = { workspace = true }

#
lscpu = { optional = true, version = "0.0.1", package = "uu_lscpu", path = "src/uu/lscpu" }
lsmem = { optional = true, version = "0.0.1", package = "uu_lsmem", path = "src/uu/lsmem" }
mountpoint = { optional = true, version = "0.0.1", package = "uu_mountpoint", path = "src/uu/mountpoint" }
ctrlaltdel = { optional = true, version = "0.0.1", package = "uu_ctrlaltdel", path = "src/uu/ctrlaltdel" }
rev = { optional = true, version = "0.0.1", package = "uu_rev", path = "src/uu/rev" }
last = { optional = true, version = "0.0.1", package = "uu_last", path = "src/uu/last" }

[dev-dependencies]
pretty_assertions = "1"
Expand Down
12 changes: 12 additions & 0 deletions src/uu/last/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[package]
name = "uu_last"
version = "0.0.1"
edition = "2021"

[lib]
path = "src/last.rs"

[dependencies]
uucore = { workspace = true, features = ["utmpx"] }
clap = { workspace = true}
dns-lookup = { workspace = true }
8 changes: 8 additions & 0 deletions src/uu/last/last.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# last

```
Usage:
[options] [<username>...] [<tty>...]
```

Show a listing of last logged in users.
94 changes: 94 additions & 0 deletions src/uu/last/src/last.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
// This file is part of the uutils util-linux package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use clap::{crate_version, Arg, ArgAction, Command};
use uucore::{format_usage, help_about, help_usage};

mod platform;

mod options {
pub const SYSTEM: &str = "system";
pub const HOSTLAST: &str = "hostlast";
pub const NO_HOST: &str = "nohostname";
pub const LIMIT: &str = "limit";
pub const DNS: &str = "dns";
pub const TIME_FORMAT: &str = "time-format";
pub const USER_TTY: &str = "username";
pub const FILE: &str = "file";
}

const ABOUT: &str = help_about!("last.md");
const USAGE: &str = help_usage!("last.md");

#[uucore::main]
use platform::uumain;

pub fn uu_app() -> Command {
Command::new(uucore::util_name())
.version(crate_version!())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.infer_long_args(true)
.arg(
Arg::new(options::FILE)
.short('f')
.long("file")
.action(ArgAction::Set)
.default_value("/var/log/wtmp")
.help("use a specific file instead of /var/log/wtmp")
.required(false),
)
.arg(
Arg::new(options::SYSTEM)
.short('x')
.long(options::SYSTEM)
.action(ArgAction::SetTrue)
.required(false)
.help("display system shutdown entries and run level changes"),
)
.arg(
Arg::new(options::DNS)
.short('d')
.long(options::DNS)
.action(ArgAction::SetTrue)
.required(false)
.help("translate the IP number back into a hostname"),
)
.arg(
Arg::new(options::HOSTLAST)
.short('a')
.long(options::HOSTLAST)
.action(ArgAction::SetTrue)
.required(false)
.help("display hostnames in the last column"),
)
.arg(
Arg::new(options::NO_HOST)
.short('R')
.long(options::NO_HOST)
.action(ArgAction::SetTrue)
.required(false)
.help("don't display the hostname field"),
)
.arg(
Arg::new(options::LIMIT)
.short('n')
.long(options::LIMIT)
.action(ArgAction::Set)
.required(false)
.help("how many lines to show")
.value_parser(clap::value_parser!(i32))
.allow_negative_numbers(true),
)
.arg(
Arg::new(options::TIME_FORMAT)
.long(options::TIME_FORMAT)
.action(ArgAction::Set)
.required(false)
.help("show timestamps in the specified <format>: notime|short|full|iso")
.default_value("short"),
)
.arg(Arg::new(options::USER_TTY).action(ArgAction::Append))
}
1 change: 1 addition & 0 deletions src/uu/last/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uucore::bin!(uu_last);
19 changes: 19 additions & 0 deletions src/uu/last/src/platform/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// This file is part of the uutils util-linux package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

#[cfg(unix)]
mod unix;
#[cfg(unix)]
pub use self::unix::*;

#[cfg(target_os = "openbsd")]
mod openbsd;
#[cfg(target_os = "openbsd")]
pub use self::openbsd::*;

#[cfg(windows)]
mod windows;
#[cfg(windows)]
pub use self::windows::*;
17 changes: 17 additions & 0 deletions src/uu/last/src/platform/openbsd.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// This file is part of the uutils util-linux package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

// Specific implementation for OpenBSD: tool unsupported (utmpx not supported)

use crate::uu_app;

use uucore::error::UResult;

pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let _matches = uu_app().try_get_matches_from(args)?;

println!("unsupported command on OpenBSD");
Ok(())
}
Loading