use std::ffi::OsStr;
use std::ffi::OsString;
use clap::builder::StyledStr;
#[derive(Default, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub struct CompletionCandidate {
value: OsString,
help: Option<StyledStr>,
id: Option<String>,
tag: Option<StyledStr>,
display_order: Option<usize>,
hidden: bool,
}
impl CompletionCandidate {
pub fn new(value: impl Into<OsString>) -> Self {
let value = value.into();
Self {
value,
..Default::default()
}
}
pub fn help(mut self, help: Option<StyledStr>) -> Self {
self.help = help;
self
}
pub fn id(mut self, id: Option<String>) -> Self {
self.id = id;
self
}
pub fn tag(mut self, tag: Option<StyledStr>) -> Self {
self.tag = tag;
self
}
pub fn display_order(mut self, order: Option<usize>) -> Self {
self.display_order = order;
self
}
pub fn hide(mut self, hidden: bool) -> Self {
self.hidden = hidden;
self
}
pub fn add_prefix(mut self, prefix: impl Into<OsString>) -> Self {
let suffix = self.value;
let mut value = prefix.into();
value.push(&suffix);
self.value = value;
self
}
}
impl CompletionCandidate {
pub fn get_value(&self) -> &OsStr {
&self.value
}
pub fn get_help(&self) -> Option<&StyledStr> {
self.help.as_ref()
}
pub fn get_id(&self) -> Option<&String> {
self.id.as_ref()
}
pub fn get_tag(&self) -> Option<&StyledStr> {
self.tag.as_ref()
}
pub fn get_display_order(&self) -> Option<usize> {
self.display_order
}
pub fn is_hide_set(&self) -> bool {
self.hidden
}
}
impl<S: Into<OsString>> From<S> for CompletionCandidate {
fn from(s: S) -> Self {
CompletionCandidate::new(s.into())
}
}