mirror of
https://github.com/tealdeer-rs/tealdeer.git
synced 2026-08-24 17:14:18 +02:00
124 lines
3.7 KiB
Rust
124 lines
3.7 KiB
Rust
//! Definition of the CLI arguments and options.
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use clap::{ArgGroup, Parser, builder::ArgAction};
|
|
|
|
use crate::types::{ColorOptions, PlatformType};
|
|
|
|
// Note: flag names are specified explicitly in clap attributes
|
|
// to improve readability and allow contributors to grep names like "clear-cache"
|
|
#[derive(Parser, Debug)]
|
|
#[command(
|
|
about = "A fast TLDR client",
|
|
version,
|
|
disable_version_flag = true,
|
|
author,
|
|
help_template = "{before-help}{name} {version}: {about-with-newline}{author-with-newline}
|
|
{usage-heading} {usage}
|
|
|
|
{all-args}{after-help}",
|
|
after_help = "To view the user documentation, please visit https://docs.tealdeer.org.
|
|
|
|
To view usage examples, run tldr tldr or tldr tealdeer.",
|
|
arg_required_else_help = true,
|
|
help_expected = true,
|
|
group = ArgGroup::new("command_or_file").args(&["command", "render"]),
|
|
)]
|
|
pub(crate) struct Cli {
|
|
/// The command to show (e.g. `tar` or `git log`)
|
|
#[arg(num_args(1..))]
|
|
pub command: Vec<String>,
|
|
|
|
/// List all commands in the cache
|
|
#[arg(short = 'l', long = "list")]
|
|
pub list: bool,
|
|
|
|
/// Edit custom page with `EDITOR`
|
|
#[arg(long, requires = "command")]
|
|
pub edit_page: bool,
|
|
|
|
/// Edit custom patch with `EDITOR`
|
|
#[arg(long, requires = "command", conflicts_with = "edit_page")]
|
|
pub edit_patch: bool,
|
|
|
|
/// Render a specific markdown file
|
|
#[arg(
|
|
short = 'f',
|
|
long = "render",
|
|
value_name = "FILE",
|
|
conflicts_with = "command"
|
|
)]
|
|
pub render: Option<PathBuf>,
|
|
|
|
/// Override the operating system, can be specified multiple times in order of preference
|
|
#[arg(
|
|
short = 'p',
|
|
long = "platform",
|
|
value_name = "PLATFORM",
|
|
action = ArgAction::Append,
|
|
)]
|
|
pub platforms: Option<Vec<PlatformType>>,
|
|
|
|
/// Override the language
|
|
#[arg(short = 'L', long = "language")]
|
|
pub language: Option<String>,
|
|
|
|
/// Update the local cache
|
|
#[arg(short = 'u', long = "update")]
|
|
pub update: bool,
|
|
|
|
/// If auto update is configured, disable it for this run
|
|
#[arg(long = "no-auto-update")]
|
|
pub no_auto_update: bool,
|
|
|
|
/// Clear the local cache
|
|
#[arg(short = 'c', long = "clear-cache")]
|
|
pub clear_cache: bool,
|
|
|
|
/// Override config file location
|
|
#[arg(long = "config-path", value_name = "FILE")]
|
|
pub config_path: Option<PathBuf>,
|
|
|
|
/// Override config values after reading config file (example: `updates.auto_update = true`)
|
|
#[arg(long, action = ArgAction::Append, value_name = "OVERRIDE")]
|
|
pub override_config: Vec<String>,
|
|
|
|
/// Use a pager to page output
|
|
#[arg(long = "pager", requires = "command_or_file")]
|
|
pub pager: bool,
|
|
|
|
/// Display the raw markdown instead of rendering it
|
|
#[arg(short = 'r', long = "raw", requires = "command_or_file")]
|
|
pub raw: bool,
|
|
|
|
/// Suppress informational messages
|
|
#[arg(short = 'q', long = "quiet")]
|
|
pub quiet: bool,
|
|
|
|
/// Show file and directory paths used by tealdeer
|
|
#[arg(long = "show-paths")]
|
|
pub show_paths: bool,
|
|
|
|
/// Create a basic config
|
|
#[arg(long = "seed-config")]
|
|
pub seed_config: bool,
|
|
|
|
/// Control whether to use color
|
|
#[arg(long = "color", value_name = "WHEN")]
|
|
pub color: Option<ColorOptions>,
|
|
|
|
/// Display the short variants of placeholders
|
|
#[arg(long)]
|
|
pub short_options: bool,
|
|
|
|
/// Display the long variants of placeholders
|
|
#[arg(long)]
|
|
pub long_options: bool,
|
|
|
|
/// Print the version
|
|
// Note: We override the version flag because clap uses `-V` by default,
|
|
// while TLDR specification requires `-v` to be used.
|
|
#[arg(short = 'v', long = "version", action = ArgAction::Version)]
|
|
pub version: (),
|
|
}
|