add version flag

This commit is contained in:
Alexander Mohr 2025-05-25 16:27:14 +02:00
parent cf4dd9ca5d
commit 9f4dbf13b0
4 changed files with 42 additions and 4807 deletions

File diff suppressed because it is too large Load diff

2648
worf/Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -180,7 +180,8 @@ impl FromStr for KeyDetectionType {
pub struct Config {
/// Forks the menu so you can close the terminal
#[clap(short = 'f', long = "fork")]
fork: Option<bool>,
#[serde(default = "default_false")]
fork: bool,
/// Selects a config file to use
#[clap(short = 'c', long = "conf")]
@ -188,7 +189,8 @@ pub struct Config {
/// Prints the version and then exits
#[clap(short = 'v', long = "version")]
version: Option<bool>, // todo support or drop
#[serde(default = "default_false")]
version: bool,
/// Defines the style sheet to be loaded.
/// Defaults to `$XDG_CONF_DIR/worf/style.css`
@ -225,11 +227,13 @@ pub struct Config {
/// Set to 'false' to disable images, defaults to true
#[clap(short = 'I', long = "allow-images")]
allow_images: Option<bool>,
#[serde(default = "default_true")]
allow_images: bool,
/// If `true` pango markup is parsed
#[clap(short = 'm', long = "allow-markup")]
allow_markup: Option<bool>,
#[serde(default = "default_true")]
allow_markup: bool,
#[clap(short = 'k', long = "cache-file")]
cache_file: Option<String>, // todo support this
@ -257,7 +261,8 @@ pub struct Config {
/// Defines whether the scrollbar is visible
#[clap(short = 'b', long = "hide-scroll")]
hide_scroll: Option<bool>,
#[serde(default = "default_false")]
hide_scroll: bool,
/// Defines the matching method, defaults to contains
#[clap(short = 'M', long = "matching")]
@ -266,7 +271,8 @@ pub struct Config {
/// Control if search is case-insensitive or not.
/// Defaults to true
#[clap(short = 'i', long = "insensitive")]
insensitive: Option<bool>,
#[serde(default = "default_true")]
insensitive: bool,
#[clap(short = 'q', long = "parse-search")]
parse_search: Option<bool>, // todo support this
@ -278,6 +284,7 @@ pub struct Config {
)]
location: Option<Vec<Anchor>>,
// todo support this
#[clap(short = 'a', long = "no-actions")]
no_actions: Option<bool>,
@ -344,13 +351,20 @@ pub struct Config {
/// If set to `true` the search field willOption<> be hidden.
#[clap(long = "hide-search")]
hide_search: Option<bool>,
#[serde(default = "default_false")]
hide_search: bool,
#[clap(long = "dynamic-lines")]
dynamic_lines: Option<bool>, // todo support this
#[serde(default = "default_false")]
dynamic_lines: bool, // todo support this
layer: Option<String>, // todo support this
copy_exec: Option<String>, // todo support this
#[clap(long = "single_click")]
single_click: Option<bool>, // todo support this
#[clap(long = "pre-display-exec")]
pre_display_exec: Option<bool>, // todo support this
@ -376,7 +390,7 @@ pub struct Config {
impl Config {
#[must_use]
pub fn fork(&self) -> bool {
self.fork.unwrap_or(false)
self.fork
}
#[must_use]
@ -417,7 +431,7 @@ impl Config {
#[must_use]
pub fn hide_scroll(&self) -> bool {
self.hide_scroll.unwrap_or(false)
self.hide_scroll
}
#[must_use]
@ -482,7 +496,7 @@ impl Config {
#[must_use]
pub fn allow_images(&self) -> bool {
self.allow_images.unwrap_or(true)
self.allow_images
}
#[must_use]
@ -521,12 +535,12 @@ impl Config {
#[must_use]
pub fn insensitive(&self) -> bool {
self.insensitive.unwrap_or(true)
self.insensitive
}
#[must_use]
pub fn hide_search(&self) -> bool {
self.hide_search.unwrap_or(false)
self.hide_search
}
#[must_use]
@ -536,7 +550,7 @@ impl Config {
#[must_use]
pub fn allow_markup(&self) -> bool {
self.allow_markup.unwrap_or(false)
self.allow_markup
}
#[must_use]
@ -575,15 +589,20 @@ impl Config {
pub fn lines_additional_space(&self) -> i32 {
self.lines_additional_space.unwrap_or(0)
}
#[must_use]
pub fn version(&self) -> bool {
self.version
}
}
fn default_false() -> bool {
false
}
// fn default_true() -> bool {
// true
// }
fn default_true() -> bool {
true
}
//
// // TODO

View file

@ -20,6 +20,12 @@ fn main() -> anyhow::Result<()> {
args
}
};
if config.version() {
println!("worf version {}", env!("CARGO_PKG_VERSION"));
return Ok(());
}
fork_if_configured(&config);
if let Some(show) = &config.show() {