zoxide/src/app/_app.rs

138 lines
3.4 KiB
Rust
Raw Normal View History

2021-05-19 21:24:06 +00:00
use clap::{AppSettings, ArgEnum, Clap, ValueHint};
2021-05-03 21:03:23 +00:00
use std::path::PathBuf;
const ENV_HELP: &str = "ENVIRONMENT VARIABLES:
_ZO_DATA_DIR Path for zoxide data files
_ZO_ECHO Prints the matched directory before navigating to it when set to 1
_ZO_EXCLUDE_DIRS List of directory globs to be excluded
_ZO_FZF_OPTS Custom flags to pass to fzf
_ZO_MAXAGE Maximum total age after which entries start getting deleted
_ZO_RESOLVE_SYMLINKS Resolve symlinks when storing paths";
#[derive(Debug, Clap)]
#[clap(
bin_name = env!("CARGO_PKG_NAME"),
about,
author,
after_help = ENV_HELP,
global_setting(AppSettings::ColoredHelp),
global_setting(AppSettings::DisableHelpSubcommand),
global_setting(AppSettings::GlobalVersion),
global_setting(AppSettings::VersionlessSubcommands),
2021-05-03 21:12:43 +00:00
version = option_env!("ZOXIDE_VERSION").unwrap_or_default()
2021-05-03 21:03:23 +00:00
)]
2021-05-03 21:12:43 +00:00
pub enum App {
2021-05-03 21:03:23 +00:00
Add(Add),
Import(Import),
Init(Init),
Query(Query),
Remove(Remove),
}
/// Add a new directory or increment its rank
#[derive(Clap, Debug)]
pub struct Add {
#[clap(min_values = 1, required = true, value_hint = ValueHint::DirPath)]
pub paths: Vec<PathBuf>,
2021-05-03 21:03:23 +00:00
}
/// Import entries from another application
#[derive(Clap, Debug)]
pub struct Import {
2021-05-19 21:24:06 +00:00
#[clap(value_hint = ValueHint::FilePath)]
2021-05-03 21:03:23 +00:00
pub path: PathBuf,
/// Application to import from
#[clap(arg_enum, long)]
2021-05-03 21:12:43 +00:00
pub from: ImportFrom,
2021-05-03 21:03:23 +00:00
/// Merge into existing database
#[clap(long)]
pub merge: bool,
}
#[derive(ArgEnum, Debug)]
2021-05-03 21:12:43 +00:00
pub enum ImportFrom {
2021-05-03 21:03:23 +00:00
Autojump,
Z,
}
/// Generate shell configuration
#[derive(Clap, Debug)]
pub struct Init {
#[clap(arg_enum)]
2021-05-03 21:12:43 +00:00
pub shell: InitShell,
2021-05-03 21:03:23 +00:00
/// Prevents zoxide from defining any commands
#[clap(long)]
pub no_aliases: bool,
/// Renames the 'z' command and corresponding aliases
#[clap(long, default_value = "z")]
pub cmd: String,
/// Chooses event upon which an entry is added to the database
#[clap(arg_enum, long, default_value = "pwd")]
2021-05-03 21:12:43 +00:00
pub hook: InitHook,
}
#[derive(ArgEnum, Clone, Copy, Debug, Eq, PartialEq)]
pub enum InitHook {
None,
Prompt,
Pwd,
2021-05-03 21:03:23 +00:00
}
#[derive(ArgEnum, Debug)]
2021-05-03 21:12:43 +00:00
pub enum InitShell {
2021-05-03 21:03:23 +00:00
Bash,
Elvish,
Fish,
Nushell,
Posix,
Powershell,
Xonsh,
Zsh,
}
/// Search for a directory in the database
#[derive(Clap, Debug)]
pub struct Query {
pub keywords: Vec<String>,
2021-05-08 03:05:34 +00:00
/// Show deleted directories
#[clap(long)]
pub all: bool,
2021-05-03 21:03:23 +00:00
/// Use interactive selection
#[clap(long, short, conflicts_with = "list")]
pub interactive: bool,
/// List all matching directories
#[clap(long, short, conflicts_with = "interactive")]
pub list: bool,
/// Print score with results
2021-06-01 03:29:24 +00:00
#[clap(long, short, conflicts_with = "interactive")]
2021-05-03 21:03:23 +00:00
pub score: bool,
/// Exclude a path from results
2021-05-19 21:24:06 +00:00
#[clap(long, value_hint = ValueHint::DirPath, value_name = "path")]
2021-05-03 21:03:23 +00:00
pub exclude: Option<String>,
}
/// Remove a directory from the database
#[derive(Clap, Debug)]
pub struct Remove {
// Use interactive selection
#[clap(conflicts_with = "paths", long, short, value_name = "keywords")]
2021-05-03 21:03:23 +00:00
pub interactive: Option<Vec<String>>,
2021-05-19 21:24:06 +00:00
#[clap(
conflicts_with = "interactive",
required_unless_present = "interactive",
value_hint = ValueHint::DirPath
)]
pub paths: Vec<String>,
2021-05-03 21:03:23 +00:00
}