-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate ldns parsing from clap parsing (#19)
* Separate ldns parsing from clap parsing Co-authored-by: Jannik Peters <[email protected]> * nsec3-hash: sort ldns argument parsing alphabetically * abort ldns parsing early on malfored argv[0] * add 'Error' prefix to ldns parsing errors * use clap default exit code of 2 for dnst versions of commands * remove args_overide_self from nsec3hash * move parse_os and parse_os_with out of LdnsCommand --------- Co-authored-by: Jannik Peters <[email protected]>
- Loading branch information
1 parent
fd099ce
commit bae3b00
Showing
7 changed files
with
171 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,33 @@ | ||
use std::path::Path; | ||
|
||
use clap::Parser; | ||
use dnst::commands::{nsec3hash::Nsec3Hash, LdnsCommand}; | ||
|
||
fn main() { | ||
if let Err(err) = dnst::Args::parse().execute() { | ||
// If none of the ldns-* tools matched, then we continue with clap | ||
// argument parsing. | ||
let args = try_ldns_compatibility().unwrap_or_else(dnst::Args::parse); | ||
|
||
if let Err(err) = args.execute() { | ||
eprintln!("{}", err); | ||
} | ||
} | ||
|
||
fn try_ldns_compatibility() -> Option<dnst::Args> { | ||
let binary_path = std::env::args_os().next()?; | ||
|
||
let binary_name = Path::new(&binary_path).file_name()?.to_str()?; | ||
|
||
let res = match binary_name { | ||
"ldns-nsec3-hash" => Nsec3Hash::parse_ldns_args(), | ||
_ => return None, | ||
}; | ||
|
||
match res { | ||
Ok(args) => Some(args), | ||
Err(e) => { | ||
eprintln!("{e}"); | ||
std::process::exit(1) | ||
} | ||
} | ||
} |