From d5dbe3084ba36d5e9c549bc8ba948d9275014b3b Mon Sep 17 00:00:00 2001 From: cyqsimon <28627918+cyqsimon@users.noreply.github.com> Date: Fri, 21 Jan 2022 16:12:10 +0800 Subject: [PATCH] Add `no-auto-update` flag (#257) * Added `no-auto-update` * Updated usage.txt * Add `no-auto-update` to completion scripts * Apply review suggestions --- completion/bash_tealdeer | 2 +- completion/fish_tealdeer | 27 ++++++++++++++------------- completion/zsh_tealdeer | 1 + docs/src/usage.txt | 1 + src/cli.rs | 4 ++++ src/main.rs | 7 ++++--- 6 files changed, 25 insertions(+), 17 deletions(-) diff --git a/completion/bash_tealdeer b/completion/bash_tealdeer index 2a1429d..ec54b89 100644 --- a/completion/bash_tealdeer +++ b/completion/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|-r|--raw|--show-paths|--seed-config|-q|--quiet) + -h|--help|-v|--version|-l|--list|-u|--update|--no-auto-update|-c|--clear-cache|-p|--pager|-r|--raw|--show-paths|--seed-config|-q|--quiet) return ;; -f|--render) diff --git a/completion/fish_tealdeer b/completion/fish_tealdeer index ee68e2a..2bcf551 100644 --- a/completion/fish_tealdeer +++ b/completion/fish_tealdeer @@ -3,19 +3,20 @@ # https://github.com/dbrgn/tealdeer/ # -complete -c tldr -s h -l help -d 'Print the help message.' -f -complete -c tldr -s v -l version -d 'Show version information.' -f -complete -c tldr -s l -l list -d 'List all commands in the cache.' -f -complete -c tldr -s f -l render -d 'Render a specific markdown file.' -r -complete -c tldr -s p -l platform -d 'Override the operating system.' -xa 'linux macos sunos windows' -complete -c tldr -s u -l update -d 'Update the local cache.' -f -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 r -l raw -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 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' +complete -c tldr -s h -l help -d 'Print the help message.' -f +complete -c tldr -s v -l version -d 'Show version information.' -f +complete -c tldr -s l -l list -d 'List all commands in the cache.' -f +complete -c tldr -s f -l render -d 'Render a specific markdown file.' -r +complete -c tldr -s p -l platform -d 'Override the operating system.' -xa 'linux macos sunos windows' +complete -c tldr -s u -l update -d 'Update the local cache.' -f +complete -c tldr -l no-auto-update -d 'Disable auto-update, override config file' -f +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 r -l raw -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 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' function __tealdeer_entries tldr --list | string replace -a -i -r "\,\s" "\n" diff --git a/completion/zsh_tealdeer b/completion/zsh_tealdeer index 28cd34b..872b474 100644 --- a/completion/zsh_tealdeer +++ b/completion/zsh_tealdeer @@ -22,6 +22,7 @@ _tealdeer() { ))' "($I -L --language)"{-L,--language}"[Override the language settings]:lang" "($I -u --update)"{-u,--update}"[Update the local cache]" + "($I)--no-auto-update[Disable auto-update, override config file]" "($I -c --clear-cache)"{-c,--clear-cache}"[Clear the local cache]" "($I)--pager[Use a pager to page output]" "($I -r --raw)"{-r,--raw}"[Display the raw markdown instead of rendering it]" diff --git a/docs/src/usage.txt b/docs/src/usage.txt index 8e7ae5b..789b6e3 100644 --- a/docs/src/usage.txt +++ b/docs/src/usage.txt @@ -15,6 +15,7 @@ OPTIONS: windows, sunos, osx] -L, --language Override the language -u, --update Update the local cache + --no-auto-update If auto update is configured, disable it for this run -c, --clear-cache Clear the local cache --pager Use a pager to page output -r, --raw Display the raw markdown instead of rendering it diff --git a/src/cli.rs b/src/cli.rs index 38a451a..c7bf0aa 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -60,6 +60,10 @@ pub(crate) struct Args { #[clap(short = 'u', long = "update")] pub update: bool, + /// If auto update is configured, disable it for this run + #[clap(long = "no-auto-update", requires = "command_or_file")] + pub no_auto_update: bool, + /// Clear the local cache #[clap(short = 'c', long = "clear-cache")] pub clear_cache: bool, diff --git a/src/main.rs b/src/main.rs index d96b03d..17e7358 100644 --- a/src/main.rs +++ b/src/main.rs @@ -49,11 +49,12 @@ const APP_INFO: AppInfo = AppInfo { }; const ARCHIVE_URL: &str = "https://tldr.sh/assets/tldr.zip"; -/// The cache should get updated if this was requested by the user, or if auto -/// updates are enabled and the cache age is longer than the auto update interval. +/// The cache should be updated if it was explicitly requested, +/// or if an automatic update is due and allowed. fn should_update_cache(args: &Args, config: &Config) -> bool { args.update - || (config.updates.auto_update + || (!args.no_auto_update + && config.updates.auto_update && Cache::last_update().map_or(true, |ago| ago >= config.updates.auto_update_interval)) }