use clap::{Arg, ArgMatches};

use super::{CmdArg, CmdArgOption};

/// The query argument.
pub struct ArgQuery {}

impl CmdArg for ArgQuery {
    fn name() -> &'static str {
        "QUERY"
    }

    fn build<'b, 'c>() -> Arg<'b, 'c> {
        Arg::with_name("QUERY").help("Secret query")
    }
}

impl<'a> CmdArgOption<'a> for ArgQuery {
    type Value = Option<String>;

    fn value<'b: 'a>(matches: &'a ArgMatches<'b>) -> Self::Value {
        let parts: Vec<String> = Self::values_raw(matches)?.map(|s| s.to_string()).collect();
        Some(parts.join(" "))
    }
}
