intermodal/src/xor_args.rs
Casey Rodarmor 5ba885dbc4
Take input to imdl torrent create as positional
Allow taking the `--input` argument to `imdl torrent create` as a
positional argument, so the following now works:

    imdl torrent create foo

Taking input by flag `--input` still works.

type: changed
fixes:
- https://github.com/casey/intermodal/issues/375
2020-04-21 22:23:39 -07:00

18 lines
356 B
Rust

use crate::common::*;
pub(crate) fn xor_args<T: Clone>(
a_name: &str,
a: &Option<T>,
b_name: &str,
b: &Option<T>,
) -> Result<T> {
let target = a.as_ref().xor(b.as_ref()).ok_or_else(|| {
Error::internal(format!(
"Expected exactly one of the arguments `{}` or `{}` to be set",
a_name, b_name
))
})?;
Ok(target.clone())
}