Skip to content

Commit

Permalink
Add last Utility (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
Puffy1215 committed Sep 19, 2024
1 parent 201b2fe commit 49fc7ff
Show file tree
Hide file tree
Showing 12 changed files with 1,034 additions and 77 deletions.
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

0 comments on commit 49fc7ff

Please sign in to comment.