diff --git a/bash_tealdeer b/bash_tealdeer index 874356e..aadcc05 100644 --- a/bash_tealdeer +++ b/bash_tealdeer @@ -6,7 +6,7 @@ _tealdeer() _init_completion || return case $prev in - -h|--help|-v|--version|-l|--list|-u|--update|-c|--clear-cache|-p|--pager|-m|--markdown|--config-path|--seed-config|-q|--quiet) + -h|--help|-v|--version|-l|--list|-u|--update|-c|--clear-cache|-p|--pager|-m|--markdown|--show-paths|--seed-config|-q|--quiet) return ;; -f|--render) diff --git a/docs/src/config.md b/docs/src/config.md index 38e367b..79afcdf 100644 --- a/docs/src/config.md +++ b/docs/src/config.md @@ -8,7 +8,7 @@ the config file can be done manually or with the help of `tldr`: The configuration file path follows OS conventions. It can be queried with the following command: - $ tldr --config-path + $ tldr --show-paths On Linux, this will usually be `~/.config/tealdeer/config.toml`. diff --git a/fish_tealdeer b/fish_tealdeer index d571739..1aa95c5 100644 --- a/fish_tealdeer +++ b/fish_tealdeer @@ -13,7 +13,7 @@ complete -c tldr -s c -l clear-cache -d 'Clear the local cache.' -f complete -c tldr -s p -l pager -d 'Use a pager to page output.' -f complete -c tldr -s m -l markdown -d 'Display the raw markdown instead of rendering it.' -f complete -c tldr -s q -l quiet -d 'Suppress informational messages.' -f -complete -c tldr -l config-path -d 'Show config file path.' -f +complete -c tldr -l show-paths -d 'Show file and directory paths used by tealdeer.' -f complete -c tldr -l seed-config -d 'Create a basic config.' -f complete -c tldr -l color -d 'Controls when to use color.' -xa 'always auto never' diff --git a/src/cache.rs b/src/cache.rs index 0faddf4..802c06e 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -33,7 +33,7 @@ impl Cache { } /// Return the path to the cache directory. - fn get_cache_dir() -> Result { + pub fn get_cache_dir() -> Result { // Allow overriding the cache directory by setting the // $TEALDEER_CACHE_DIR env variable. if let Ok(value) = env::var("TEALDEER_CACHE_DIR") { diff --git a/src/main.rs b/src/main.rs index ef3e2aa..94d6506 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,7 +42,7 @@ mod tokenizer; mod types; use crate::cache::Cache; -use crate::config::{get_config_path, make_default_config, Config, MAX_CACHE_AGE}; +use crate::config::{get_config_dir, get_config_path, make_default_config, Config, MAX_CACHE_AGE}; use crate::dedup::Dedup; use crate::error::TealdeerError::{CacheError, ConfigError, UpdateError}; use crate::formatter::print_lines; @@ -73,6 +73,7 @@ struct Args { flag_clear_cache: bool, flag_pager: bool, flag_quiet: bool, + flag_show_paths: bool, flag_config_path: bool, flag_seed_config: bool, flag_markdown: bool, @@ -179,7 +180,7 @@ fn update_cache(cache: &Cache, quietly: bool) { } } -/// Show the config path +/// Show the config path (DEPRECATED) fn show_config_path() { match get_config_path() { Ok(config_file_path) => { @@ -196,6 +197,36 @@ fn show_config_path() { } } +/// Show file paths +fn show_paths() { + let config_dir = get_config_dir() + .map(|mut path| { + path.push(""); // Trailing path separator + path.to_str().unwrap_or("[Invalid]").to_string() + }) + .unwrap_or_else(|e| format!("[Error: {}]", e)); + let config_path = get_config_path() + .map(|path| path.to_str().unwrap_or("[Invalid]").to_string()) + .unwrap_or_else(|e| format!("[Error: {}]", e)); + let cache_dir = Cache::get_cache_dir() + .map(|mut path| { + path.push(""); // Trailing path separator + path.to_str().unwrap_or("[Invalid]").to_string() + }) + .unwrap_or_else(|e| format!("[Error: {}]", e)); + let pages_dir = Cache::get_cache_dir() + .map(|path| path.join("tldr-master")) + .map(|mut path| { + path.push(""); // Trailing path separator + path.to_str().unwrap_or("[Invalid]").to_string() + }) + .unwrap_or_else(|e| format!("[Error: {}]", e)); + println!("Config dir: {}", config_dir); + println!("Config path: {}", config_path); + println!("Cache dir: {}", cache_dir); + println!("Pages dir: {}", pages_dir); +} + /// Create seed config file and exit fn create_config_and_exit() { match make_default_config() { @@ -315,8 +346,12 @@ fn main() { // Show config file and path, pass through if args.flag_config_path { + eprintln!("Warning: The --config-path flag is deprecated, use --show-paths instead"); show_config_path(); } + if args.flag_show_paths { + show_paths(); + } // Create a basic config and exit if args.flag_seed_config { @@ -450,7 +485,8 @@ fn main() { } // Some flags can be run without a command. - if !(args.flag_update || args.flag_clear_cache || args.flag_config_path) { + if !(args.flag_update || args.flag_clear_cache || args.flag_config_path || args.flag_show_paths) + { eprintln!("{}", USAGE); process::exit(1); } diff --git a/src/usage.docopt b/src/usage.docopt index 4a70c86..9ba0968 100644 --- a/src/usage.docopt +++ b/src/usage.docopt @@ -16,7 +16,8 @@ Options: -p --pager Use a pager to page output -m --markdown Display the raw markdown instead of rendering it -q --quiet Suppress informational messages - --config-path Show config file path + --show-paths Show file and directory paths used by tealdeer + --config-path Show config file path (deprecated) --seed-config Create a basic config --color Control when to use color [always, auto, never] [default: auto] diff --git a/tests/lib.rs b/tests/lib.rs index f45e314..d880584 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -202,22 +202,34 @@ fn test_setup_seed_config() { } #[test] -fn test_show_config_path() { +fn test_show_paths() { let testenv = TestEnv::new(); testenv .command() - .args(&["--config-path"]) + .args(&["--show-paths"]) .assert() .success() .stdout(contains(format!( - "Config path is: {}", + "Config dir: {}", + testenv.config_dir.path().to_str().unwrap(), + ))) + .stdout(contains(format!( + "Config path: {}", testenv .config_dir .path() .join("config.toml") .to_str() .unwrap(), + ))) + .stdout(contains(format!( + "Cache dir: {}", + testenv.cache_dir.path().to_str().unwrap(), + ))) + .stdout(contains(format!( + "Pages dir: {}", + testenv.cache_dir.path().join("tldr-master").to_str().unwrap(), ))); } diff --git a/zsh_tealdeer b/zsh_tealdeer index 2c8e284..2f55a38 100644 --- a/zsh_tealdeer +++ b/zsh_tealdeer @@ -23,7 +23,7 @@ _tealdeer() { "($I -p --pager)"{-p,--pager}"[Use a pager to page output]" "($I -m --markdown)"{-m,--markdown}"[Display the raw markdown instead of rendering it]" "($I -q --quiet)"{-q,--quiet}"[Suppress informational messages]" - "($I)--config-path[Show config file path]" + "($I)--show-paths[Show file and directory paths used by tealdeer]" "($I)--seed-config[Create a basic config]" "($I)--color[Controls when to use color]:when:(( always