Skip to content

Commit 6b8b29e

Browse files
committed
Canonicalize away from #[clap...] macros
And some realpath cleanups.
1 parent b690a9a commit 6b8b29e

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

file/file.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use std::{
2525
#[derive(Parser)]
2626
#[command(author, version, about, long_about, disable_help_flag = true)]
2727
struct Args {
28-
#[clap(long, action = clap::ArgAction::HelpLong)]
28+
#[arg(long, action = clap::ArgAction::HelpLong)]
2929
help: Option<bool>,
3030

3131
/// Apply default position-sensitive system tests and context-sensitive system tests to the file.

file/od.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ struct Args {
6969
/// Input files
7070
files: Vec<PathBuf>,
7171

72-
#[clap(skip)]
72+
#[arg(skip)]
7373
/// Offset in the file where dumping is to commence, must start with "+"]
7474
offset: Option<String>,
7575
}

pathnames/realpath.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,26 @@ use gettextrs::{bind_textdomain_codeset, gettext, setlocale, textdomain, LocaleC
1212
use plib::PROJECT_NAME;
1313
use std::path::{Component, Path, PathBuf};
1414

15+
/// realpath -- return resolved canonical path
16+
#[derive(Parser)]
17+
#[command(version, about)]
18+
struct Args {
19+
/// Error if the path cannot be resolved
20+
#[arg(short = 'e', overrides_with = "_canonicalize_missing")]
21+
canonicalize_existing: bool,
22+
23+
/// Do not error if the path cannot be resolved (default)
24+
#[arg(short = 'E', overrides_with = "canonicalize_existing")]
25+
_canonicalize_missing: bool,
26+
27+
/// Don't print errors when paths cannot be resolved
28+
#[arg(short, long)]
29+
quiet: bool,
30+
31+
#[arg(value_name = "PATH", default_value = ".")]
32+
paths: Vec<PathBuf>,
33+
}
34+
1535
/// Returns a normalized path.
1636
/// If `must_exist`, returns an error if the path cannot be resolved
1737
fn normalize<P: AsRef<Path>>(path: P) -> std::io::Result<PathBuf> {
@@ -42,26 +62,6 @@ fn normalize<P: AsRef<Path>>(path: P) -> std::io::Result<PathBuf> {
4262
Ok(out)
4363
}
4464

45-
/// realpath -- return resolved canonical path
46-
#[derive(Parser)]
47-
#[clap(version)]
48-
struct Args {
49-
/// Error if the path cannot be resolved
50-
#[clap(short = 'e', long, overrides_with = "_canonicalize_missing")]
51-
canonicalize_existing: bool,
52-
53-
/// Do not error if the path cannot be resolved (default)
54-
#[clap(short = 'E', overrides_with = "canonicalize_existing")]
55-
_canonicalize_missing: bool,
56-
57-
/// Don't print errors when paths cannot be resolved
58-
#[clap(short, long)]
59-
quiet: bool,
60-
61-
#[clap(value_name = "PATH", default_value = ".")]
62-
paths: Vec<PathBuf>,
63-
}
64-
6565
fn main() -> Result<(), Box<dyn std::error::Error>> {
6666
let args = Args::parse();
6767

pathnames/tests/realpath/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,13 @@ fn realpath_args_canonicalization() {
145145
realpath_test(&["foobar"], &out_str, "", 0);
146146
realpath_test(&["-E", "foobar"], &out_str, "", 0);
147147

148-
// Canonicalization flag must be explicitly suplied
148+
// Canonicalization flag must be explicitly supplied
149149
realpath_test(
150150
&["-e", "foobar"],
151151
"",
152152
"realpath: foobar: No such file or directory (os error 2)\n",
153153
1,
154154
);
155-
realpath_test(
156-
&["--canonicalize-existing", "foobar"],
157-
"",
158-
"realpath: foobar: No such file or directory (os error 2)\n",
159-
1,
160-
);
161155

162156
// POSIX-style overriding (last wins)
163157
realpath_test(&["-e", "-E", "foobar"], &out_str, "", 0);

0 commit comments

Comments
 (0)