Skip to content

Commit

Permalink
misc: treat invalid/unknown CLI options as errors
Browse files Browse the repository at this point in the history
  • Loading branch information
joshstoik1 committed Feb 16, 2024
1 parent ca68e04 commit 5aa64d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion adbyss/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ items = [
]

[dependencies]
argyle = "0.7.*"
argyle = "0.7.2"
dactyl = "0.7.*"
fyi_msg = "0.13.*"
libc = "0.2.*"
Expand Down
17 changes: 17 additions & 0 deletions adbyss/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,23 @@ fn _main() -> Result<(), AdbyssError> {
// Parse CLI arguments.
let args = Argue::new(FLAG_VERSION | FLAG_HELP)?;

// Check for invalid CLI options.
if let Some(boo) = args.check_keys(
&[
b"--disable",
b"--quiet",
b"--show",
b"--stdout",
b"--systemd",
b"--yes",
b"-q",
b"-y",
],
&[b"--config", b"-c"],
) {
return Err(AdbyssError::InvalidCli(String::from_utf8_lossy(boo).into()));
}

// Load configuration. If the user specified one, go with that and print an
// error if the path is invalid. Otherwise look for a config at the default
// path and go with that if it exists. Otherwise just use the internal
Expand Down
3 changes: 3 additions & 0 deletions adbyss_core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub enum AdbyssError {
HostsRead(Box<Path>),
/// # Write error.
HostsWrite(Box<Path>),
/// # Uknown CLI option.
InvalidCli(Box<str>),
/// # No Internet.
NoInternet,
/// # Root required.
Expand All @@ -50,6 +52,7 @@ impl fmt::Display for AdbyssError {
Self::HostsInvalid(path) => f.write_fmt(format_args!("Invalid hostfile: {path:?}")),
Self::HostsRead(path) => f.write_fmt(format_args!("Unable to read hostfile: {path:?}")),
Self::HostsWrite(path) => f.write_fmt(format_args!("Unable to write hostfile: {path:?}")),
Self::InvalidCli(s) => f.write_fmt(format_args!("Invalid/unknown option: {s}")),
Self::NoInternet => f.write_str("No internet connection was available."),
Self::Root => f.write_str("Adbyss requires root privileges."),
Self::SourceFetch(src) => f.write_fmt(format_args!("Unable to fetch source: {}", src.as_str())),
Expand Down

0 comments on commit 5aa64d9

Please sign in to comment.