Skip to content

Commit 48a2c01

Browse files
committed
datetime: Use compile-time macro env!
1 parent bceb39c commit 48a2c01

File tree

6 files changed

+20
-27
lines changed

6 files changed

+20
-27
lines changed

datetime/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ edition.workspace = true
88
rust-version.workspace = true
99

1010
[dependencies]
11-
plib = { path = "../plib" }
1211
clap.workspace = true
1312
gettext-rs.workspace = true
1413
chrono.workspace = true
1514
libc.workspace = true
1615

16+
[dev-dependencies]
17+
plib = { path = "../plib" }
18+
1719
[lints]
1820
workspace = true
1921

datetime/cal.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use chrono::Datelike;
1515
use clap::Parser;
1616
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
17-
use plib::PROJECT_NAME;
1817

1918
#[derive(Parser)]
2019
#[command(version, about = gettext("cal - print a calendar"))]
@@ -94,12 +93,11 @@ fn print_year(year: u32) {
9493
}
9594

9695
fn main() -> Result<(), Box<dyn std::error::Error>> {
97-
// parse command line arguments
98-
let mut args = Args::parse();
99-
10096
setlocale(LocaleCategory::LcAll, "");
101-
textdomain(PROJECT_NAME)?;
102-
bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?;
97+
textdomain(env!("PROJECT_NAME"))?;
98+
bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?;
99+
100+
let mut args = Args::parse();
103101

104102
// If no arguments are provided, display the current month
105103
if args.month.is_none() && args.year.is_none() {

datetime/date.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use chrono::{DateTime, Datelike, Local, LocalResult, TimeZone, Utc};
1515
use clap::Parser;
1616
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
17-
use plib::PROJECT_NAME;
1817

1918
const DEF_TIMESTR: &str = "%a %b %e %H:%M:%S %Z %Y";
2019

@@ -146,12 +145,11 @@ fn set_time(utc: bool, timestr: &str) -> Result<(), &'static str> {
146145
}
147146

148147
fn main() -> Result<(), Box<dyn std::error::Error>> {
149-
// parse command line arguments
150-
let args = Args::parse();
151-
152148
setlocale(LocaleCategory::LcAll, "");
153-
textdomain(PROJECT_NAME)?;
154-
bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?;
149+
textdomain(env!("PROJECT_NAME"))?;
150+
bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?;
151+
152+
let args = Args::parse();
155153

156154
match &args.timestr {
157155
None => show_time(args.utc, DEF_TIMESTR),

datetime/sleep.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
use clap::Parser;
1111
use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleCategory};
12-
use libc::{signal, SIGALRM, SIG_IGN};
13-
use plib::PROJECT_NAME;
1412
use std::{thread, time};
1513

1614
#[derive(Parser)]
@@ -24,16 +22,15 @@ struct Args {
2422
}
2523

2624
fn main() -> Result<(), Box<dyn std::error::Error>> {
27-
// parse command line arguments
28-
let args = Args::parse();
29-
3025
setlocale(LocaleCategory::LcAll, "");
31-
textdomain(PROJECT_NAME)?;
32-
bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?;
26+
textdomain(env!("PROJECT_NAME"))?;
27+
bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?;
28+
29+
let args = Args::parse();
3330

3431
unsafe {
3532
// Ignore the SIGALRM signal
36-
signal(SIGALRM, SIG_IGN);
33+
libc::signal(libc::SIGALRM, libc::SIG_IGN);
3734
}
3835

3936
thread::sleep(time::Duration::from_secs(args.seconds));

datetime/tests/time/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::{
1212
process::{Command, Output, Stdio},
1313
};
1414

15-
use plib::TestPlan;
15+
use plib::testing::TestPlan;
1616

1717
fn run_test_base(cmd: &str, args: &Vec<String>, stdin_data: &[u8]) -> Output {
1818
let relpath = if cfg!(debug_assertions) {

datetime/time.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,9 @@ use std::process::{Command, Stdio};
1212
use std::time::Instant;
1313

1414
use clap::Parser;
15-
1615
use gettextrs::{
1716
bind_textdomain_codeset, bindtextdomain, gettext, setlocale, textdomain, LocaleCategory,
1817
};
19-
use plib::PROJECT_NAME;
2018

2119
#[derive(Parser)]
2220
#[command(
@@ -134,9 +132,9 @@ impl Status {
134132

135133
fn main() -> Result<(), Box<dyn std::error::Error>> {
136134
setlocale(LocaleCategory::LcAll, "");
137-
textdomain(PROJECT_NAME)?;
138-
bindtextdomain(PROJECT_NAME, "locale")?;
139-
bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?;
135+
textdomain(env!("PROJECT_NAME"))?;
136+
bindtextdomain(env!("PROJECT_NAME"), "locale")?;
137+
bind_textdomain_codeset(env!("PROJECT_NAME"), "UTF-8")?;
140138

141139
let args = Args::parse();
142140

0 commit comments

Comments
 (0)