Skip to content

Commit 7247e3e

Browse files
committed
translate help msgs + globally export xlat macros
1 parent 55a733a commit 7247e3e

File tree

12 files changed

+33
-30
lines changed

12 files changed

+33
-30
lines changed

src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pub(crate) mod common;
66
pub(crate) mod cutils;
77
pub(crate) mod defaults;
88
pub(crate) mod exec;
9+
#[macro_use]
910
pub(crate) mod gettext;
1011
pub(crate) mod log;
1112
pub(crate) mod pam;
@@ -22,10 +23,3 @@ pub use visudo::main as visudo_main;
2223

2324
#[cfg(feature = "do-not-use-all-features")]
2425
compile_error!("Refusing to compile using 'cargo --all-features' --- please read the README");
25-
26-
//FIXME: this is here to ensure xlat! is used (with gettext disabled) and that
27-
// the Convert trait is exercised.
28-
#[allow(unused)]
29-
fn simulate_use() -> String {
30-
gettext::xlat!("{answer}", answer = 42)
31-
}

src/pam/converse.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::ffi::{c_int, c_void};
22
use std::time::Duration;
33

44
use crate::cutils::string_from_ptr;
5-
use crate::gettext::xlat;
65
use crate::pam::rpassword::Hidden;
76
use crate::system::signal::{self, SignalSet};
87

src/pam/error.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::path::PathBuf;
44
use std::str::Utf8Error;
55

66
use crate::cutils::string_from_ptr;
7-
use crate::gettext::xlat_write;
87

98
use super::sys::*;
109

src/pam/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{
77
time::Duration,
88
};
99

10-
use crate::gettext::xlat;
1110
use crate::system::signal::{self, SignalSet};
1211

1312
use converse::ConverserData;

src/sudo/cli/help.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
1-
pub const USAGE_MSG: &str = "\
1+
pub fn usage_msg() -> &'static str {
2+
xlat!(
3+
"\
24
usage: sudo -h | -K | -k | -V
35
usage: sudo [-BknS] [-p prompt] [-D directory] [-g group] [-u user] [-i | -s] [command [arg ...]]
46
usage: sudo -v [-BknS] [-p prompt] [-g group] [-u user]
57
usage: sudo -l [-BknS] [-p prompt] [-U user] [-g group] [-u user] [command [arg ...]]
6-
usage: sudo -e [-BknS] [-p prompt] [-D directory] [-g group] [-u user] file ...";
8+
usage: sudo -e [-BknS] [-p prompt] [-D directory] [-g group] [-u user] file ..."
9+
)
10+
}
711

8-
const DESCRIPTOR: &str = "sudo - run commands as another user";
12+
fn descriptor() -> &'static str {
13+
xlat!("sudo - run commands as another user")
14+
}
915

10-
const HELP_MSG: &str = "Options:
16+
fn help_msg() -> &'static str {
17+
xlat!("Options:
1118
-B, --bell ring bell when prompting
1219
-D, --chdir=directory change the working directory before running command
1320
-g, --group=group run command as the specified group name or ID
@@ -24,8 +31,9 @@ const HELP_MSG: &str = "Options:
2431
-u, --user=user run command (or edit file) as specified user name or ID
2532
-V, --version display version information and exit
2633
-v, --validate update user's timestamp without running a command
27-
-- stop processing command line arguments";
34+
-- stop processing command line arguments")
35+
}
2836

2937
pub fn long_help_message() -> String {
30-
format!("{DESCRIPTOR}\n{USAGE_MSG}\n{HELP_MSG}")
38+
format!("{}\n{}\n{}", descriptor(), usage_msg(), help_msg())
3139
}

src/sudo/cli/help_edit.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
pub const USAGE_MSG: &str = "\
1+
pub fn usage_msg() -> &'static str {
2+
xlat!(
3+
"\
24
usage: sudoedit -h | -V
3-
usage: sudoedit [-BknS] [-p prompt] [-g group] [-u user] file ...";
5+
usage: sudoedit [-BknS] [-p prompt] [-g group] [-u user] file ..."
6+
)
7+
}
48

5-
const DESCRIPTOR: &str = "sudo - edit files as another user";
9+
fn descriptor() -> &'static str {
10+
xlat!("sudo - edit files as another user")
11+
}
612

7-
const HELP_MSG: &str = "Options:
8-
Options:
13+
fn help_msg() -> &'static str {
14+
xlat!(
15+
"Options:
916
-B, --bell ring bell when prompting
1017
-g, --group=group run command as the specified group name or ID
1118
-h, --help display help message and exit
@@ -16,8 +23,10 @@ Options:
1623
-u, --user=user run command (or edit file) as specified user
1724
name or ID
1825
-V, --version display version information and exit
19-
-- stop processing command line arguments";
26+
-- stop processing command line arguments"
27+
)
28+
}
2029

2130
pub fn long_help_message() -> String {
22-
format!("{DESCRIPTOR}\n{USAGE_MSG}\n{HELP_MSG}")
31+
format!("{}\n{}\n{}", descriptor(), usage_msg(), help_msg())
2332
}

src/sudo/cli/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::os::unix::ffi::OsStrExt;
44
use std::{borrow::Cow, mem};
55

66
use crate::common::{SudoPath, SudoString};
7-
use crate::gettext::xlat;
87
use crate::log::user_warn;
98

109
pub mod help;

src/sudo/edit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use std::{io, process};
1010

1111
use crate::common::SudoPath;
1212
use crate::exec::ExitReason;
13-
use crate::gettext::xlat;
1413
use crate::log::{user_error, user_info};
1514
use crate::system::file::{create_temporary_dir, FileLock};
1615
use crate::system::wait::{Wait, WaitError, WaitOptions};

src/sudo/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ fn sudo_process() -> Result<(), Error> {
7373
let usage_msg: &str;
7474
let long_help: fn() -> String;
7575
if cli::is_sudoedit(std::env::args().next()) {
76-
usage_msg = cli::help_edit::USAGE_MSG;
76+
usage_msg = cli::help_edit::usage_msg();
7777
long_help = cli::help_edit::long_help_message;
7878
} else {
79-
usage_msg = cli::help::USAGE_MSG;
79+
usage_msg = cli::help::usage_msg();
8080
long_help = cli::help::long_help_message;
8181
}
8282

src/sudo/pipeline.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use super::diagnostic;
77
use crate::common::resolve::{AuthUser, CurrentUser};
88
use crate::common::{Context, Error};
99
use crate::exec::ExitReason;
10-
use crate::gettext::xlat;
1110
use crate::log::{auth_info, auth_warn};
1211
use crate::pam::PamContext;
1312
use crate::sudo::env::environment;

0 commit comments

Comments
 (0)