Lazy initialize help template
This commit is contained in:
parent
868a242e05
commit
845fe79b5e
2
build.rs
2
build.rs
|
@ -3,7 +3,7 @@ mod cmd;
|
||||||
|
|
||||||
use std::{env, io};
|
use std::{env, io};
|
||||||
|
|
||||||
use clap::CommandFactory;
|
use clap::CommandFactory as _;
|
||||||
use clap_complete::shells::{Bash, Elvish, Fish, PowerShell, Zsh};
|
use clap_complete::shells::{Bash, Elvish, Fish, PowerShell, Zsh};
|
||||||
use clap_complete_fig::Fig;
|
use clap_complete_fig::Fig;
|
||||||
use cmd::Cmd;
|
use cmd::Cmd;
|
||||||
|
|
|
@ -2,9 +2,14 @@
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
use clap::builder::{IntoResettable, Resettable, StyledStr};
|
||||||
use clap::{Parser, Subcommand, ValueEnum, ValueHint};
|
use clap::{Parser, Subcommand, ValueEnum, ValueHint};
|
||||||
|
|
||||||
const HELP_TEMPLATE: &str = color_print::cstr!("\
|
struct HelpTemplate;
|
||||||
|
|
||||||
|
impl IntoResettable<StyledStr> for HelpTemplate {
|
||||||
|
fn into_resettable(self) -> Resettable<StyledStr> {
|
||||||
|
color_print::cstr!("\
|
||||||
{before-help}<bold><underline>{name} {version}</underline></bold>
|
{before-help}<bold><underline>{name} {version}</underline></bold>
|
||||||
{author}
|
{author}
|
||||||
https://github.com/ajeetdsouza/zoxide
|
https://github.com/ajeetdsouza/zoxide
|
||||||
|
@ -22,13 +27,15 @@ https://github.com/ajeetdsouza/zoxide
|
||||||
{tab}<bold>_ZO_EXCLUDE_DIRS</bold> {tab}List of directory globs to be excluded
|
{tab}<bold>_ZO_EXCLUDE_DIRS</bold> {tab}List of directory globs to be excluded
|
||||||
{tab}<bold>_ZO_FZF_OPTS</bold> {tab}Custom flags to pass to fzf
|
{tab}<bold>_ZO_FZF_OPTS</bold> {tab}Custom flags to pass to fzf
|
||||||
{tab}<bold>_ZO_MAXAGE</bold> {tab}Maximum total age after which entries start getting deleted
|
{tab}<bold>_ZO_MAXAGE</bold> {tab}Maximum total age after which entries start getting deleted
|
||||||
{tab}<bold>_ZO_RESOLVE_SYMLINKS</bold>{tab}Resolve symlinks when storing paths");
|
{tab}<bold>_ZO_RESOLVE_SYMLINKS</bold>{tab}Resolve symlinks when storing paths").into_resettable()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(
|
#[clap(
|
||||||
about,
|
about,
|
||||||
author,
|
author,
|
||||||
help_template = HELP_TEMPLATE,
|
help_template = HelpTemplate,
|
||||||
disable_help_subcommand = true,
|
disable_help_subcommand = true,
|
||||||
propagate_version = true,
|
propagate_version = true,
|
||||||
version,
|
version,
|
||||||
|
@ -46,7 +53,7 @@ pub enum Cmd {
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(
|
#[clap(
|
||||||
author,
|
author,
|
||||||
help_template = HELP_TEMPLATE,
|
help_template = HelpTemplate,
|
||||||
)]
|
)]
|
||||||
pub struct Add {
|
pub struct Add {
|
||||||
#[clap(num_args = 1.., required = true, value_hint = ValueHint::DirPath)]
|
#[clap(num_args = 1.., required = true, value_hint = ValueHint::DirPath)]
|
||||||
|
@ -57,7 +64,7 @@ pub struct Add {
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(
|
#[clap(
|
||||||
author,
|
author,
|
||||||
help_template = HELP_TEMPLATE,
|
help_template = HelpTemplate,
|
||||||
)]
|
)]
|
||||||
pub struct Edit {
|
pub struct Edit {
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
|
@ -80,7 +87,7 @@ pub enum EditCommand {
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(
|
#[clap(
|
||||||
author,
|
author,
|
||||||
help_template = HELP_TEMPLATE,
|
help_template = HelpTemplate,
|
||||||
)]
|
)]
|
||||||
pub struct Import {
|
pub struct Import {
|
||||||
#[clap(value_hint = ValueHint::FilePath)]
|
#[clap(value_hint = ValueHint::FilePath)]
|
||||||
|
@ -106,7 +113,7 @@ pub enum ImportFrom {
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(
|
#[clap(
|
||||||
author,
|
author,
|
||||||
help_template = HELP_TEMPLATE,
|
help_template = HelpTemplate,
|
||||||
)]
|
)]
|
||||||
pub struct Init {
|
pub struct Init {
|
||||||
#[clap(value_enum)]
|
#[clap(value_enum)]
|
||||||
|
@ -149,7 +156,7 @@ pub enum InitShell {
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(
|
#[clap(
|
||||||
author,
|
author,
|
||||||
help_template = HELP_TEMPLATE,
|
help_template = HelpTemplate,
|
||||||
)]
|
)]
|
||||||
pub struct Query {
|
pub struct Query {
|
||||||
pub keywords: Vec<String>,
|
pub keywords: Vec<String>,
|
||||||
|
@ -179,7 +186,7 @@ pub struct Query {
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
#[clap(
|
#[clap(
|
||||||
author,
|
author,
|
||||||
help_template = HELP_TEMPLATE,
|
help_template = HelpTemplate,
|
||||||
)]
|
)]
|
||||||
pub struct Remove {
|
pub struct Remove {
|
||||||
#[clap(value_hint = ValueHint::DirPath)]
|
#[clap(value_hint = ValueHint::DirPath)]
|
||||||
|
|
Loading…
Reference in New Issue