From 79a50ce92924ad1c8e315744437618005d099db4 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sun, 19 Nov 2023 12:08:53 +0000 Subject: [PATCH 1/2] - Add `--undo` to the `rush snatch` command --- doc/rush-add.1 | 2 +- doc/rush-add.md | 3 +-- doc/rush-clone.1 | 2 +- doc/rush-clone.md | 3 +-- doc/rush-completions.1 | 2 +- doc/rush-completions.md | 3 +-- doc/rush-config.1 | 2 +- doc/rush-config.md | 3 +-- doc/rush-copy.1 | 2 +- doc/rush-copy.md | 3 +-- doc/rush-default.1 | 2 +- doc/rush-default.md | 3 +-- doc/rush-edit.1 | 2 +- doc/rush-edit.md | 3 +-- doc/rush-get.1 | 2 +- doc/rush-get.md | 3 +-- doc/rush-info.1 | 2 +- doc/rush-info.md | 3 +-- doc/rush-list.1 | 2 +- doc/rush-list.md | 3 +-- doc/rush-pull.1 | 2 +- doc/rush-pull.md | 3 +-- doc/rush-push.1 | 2 +- doc/rush-push.md | 3 +-- doc/rush-remove.1 | 2 +- doc/rush-remove.md | 3 +-- doc/rush-search.1 | 2 +- doc/rush-search.md | 3 +-- doc/rush-show.1 | 2 +- doc/rush-show.md | 3 +-- doc/rush-snatch.1 | 7 +++++- doc/rush-snatch.md | 11 ++++++++-- doc/rush-undo.1 | 2 +- doc/rush-undo.md | 3 +-- doc/rush.1 | 2 +- doc/rush.md | 2 +- rush | 38 ++++++++++++++++++++++++--------- src/bashly.yml | 5 +++++ src/lib/config.sh | 11 +++++----- src/lib/ini.sh | 2 +- src/lib/send_completions.sh | 2 +- src/snatch_command.sh | 7 +++++- test/approvals/rush_completions | 2 +- test/approvals/rush_snatch_h | 4 ++++ 44 files changed, 100 insertions(+), 73 deletions(-) diff --git a/doc/rush-add.1 b/doc/rush-add.1 index 84b45f0..545940d 100644 --- a/doc/rush-add.1 +++ b/doc/rush-add.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-add" "1" "September 2023" "" "Register a local repository." +.TH "rush-add" "1" "November 2023" "" "Register a local repository." .hy .SH NAME .PP diff --git a/doc/rush-add.md b/doc/rush-add.md index f14e4c6..751265c 100644 --- a/doc/rush-add.md +++ b/doc/rush-add.md @@ -1,6 +1,6 @@ % rush-add(1) | Register a local repository. % -% September 2023 +% November 2023 NAME ================================================== @@ -52,4 +52,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-clone.1 b/doc/rush-clone.1 index 9a07462..a75aa5b 100644 --- a/doc/rush-clone.1 +++ b/doc/rush-clone.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-clone" "1" "September 2023" "" "Clone a GitHub package repository." +.TH "rush-clone" "1" "November 2023" "" "Clone a GitHub package repository." .hy .SH NAME .PP diff --git a/doc/rush-clone.md b/doc/rush-clone.md index 1548aef..f749a7c 100644 --- a/doc/rush-clone.md +++ b/doc/rush-clone.md @@ -1,6 +1,6 @@ % rush-clone(1) | Clone a GitHub package repository. % -% September 2023 +% November 2023 NAME ================================================== @@ -104,4 +104,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-completions.1 b/doc/rush-completions.1 index 605a852..94cfb97 100644 --- a/doc/rush-completions.1 +++ b/doc/rush-completions.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-completions" "1" "September 2023" "" "Generate bash completions." +.TH "rush-completions" "1" "November 2023" "" "Generate bash completions." .hy .SH NAME .PP diff --git a/doc/rush-completions.md b/doc/rush-completions.md index 4a0920f..99c6545 100644 --- a/doc/rush-completions.md +++ b/doc/rush-completions.md @@ -1,6 +1,6 @@ % rush-completions(1) | Generate bash completions. % -% September 2023 +% November 2023 NAME ================================================== @@ -24,4 +24,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-config.1 b/doc/rush-config.1 index ad377e1..c2a5a9c 100644 --- a/doc/rush-config.1 +++ b/doc/rush-config.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-config" "1" "September 2023" "" "Show or edit the configuration file." +.TH "rush-config" "1" "November 2023" "" "Show or edit the configuration file." .hy .SH NAME .PP diff --git a/doc/rush-config.md b/doc/rush-config.md index 6352130..37e13c3 100644 --- a/doc/rush-config.md +++ b/doc/rush-config.md @@ -1,6 +1,6 @@ % rush-config(1) | Show or edit the configuration file. % -% September 2023 +% November 2023 NAME ================================================== @@ -34,4 +34,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-copy.1 b/doc/rush-copy.1 index ee4b32a..3e0c268 100644 --- a/doc/rush-copy.1 +++ b/doc/rush-copy.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-copy" "1" "September 2023" "" "Copy a package between local repositories." +.TH "rush-copy" "1" "November 2023" "" "Copy a package between local repositories." .hy .SH NAME .PP diff --git a/doc/rush-copy.md b/doc/rush-copy.md index 2e46b27..9feda8e 100644 --- a/doc/rush-copy.md +++ b/doc/rush-copy.md @@ -1,6 +1,6 @@ % rush-copy(1) | Copy a package between local repositories. % -% September 2023 +% November 2023 NAME ================================================== @@ -67,4 +67,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-default.1 b/doc/rush-default.1 index 93cd829..92d308c 100644 --- a/doc/rush-default.1 +++ b/doc/rush-default.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-default" "1" "September 2023" "" "Set a default repository." +.TH "rush-default" "1" "November 2023" "" "Set a default repository." .hy .SH NAME .PP diff --git a/doc/rush-default.md b/doc/rush-default.md index 7169d05..a9be783 100644 --- a/doc/rush-default.md +++ b/doc/rush-default.md @@ -1,6 +1,6 @@ % rush-default(1) | Set a default repository. % -% September 2023 +% November 2023 NAME ================================================== @@ -44,4 +44,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-edit.1 b/doc/rush-edit.1 index 6ef7289..e383290 100644 --- a/doc/rush-edit.1 +++ b/doc/rush-edit.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-edit" "1" "September 2023" "" "Edit package files." +.TH "rush-edit" "1" "November 2023" "" "Edit package files." .hy .SH NAME .PP diff --git a/doc/rush-edit.md b/doc/rush-edit.md index c119eb0..92ec92c 100644 --- a/doc/rush-edit.md +++ b/doc/rush-edit.md @@ -1,6 +1,6 @@ % rush-edit(1) | Edit package files. % -% September 2023 +% November 2023 NAME ================================================== @@ -44,4 +44,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-get.1 b/doc/rush-get.1 index 68de636..d6ca816 100644 --- a/doc/rush-get.1 +++ b/doc/rush-get.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-get" "1" "September 2023" "" "Install a package." +.TH "rush-get" "1" "November 2023" "" "Install a package." .hy .SH NAME .PP diff --git a/doc/rush-get.md b/doc/rush-get.md index 9812aea..057595e 100644 --- a/doc/rush-get.md +++ b/doc/rush-get.md @@ -1,6 +1,6 @@ % rush-get(1) | Install a package. % -% September 2023 +% November 2023 NAME ================================================== @@ -79,4 +79,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-info.1 b/doc/rush-info.1 index f0c5796..a2e47cc 100644 --- a/doc/rush-info.1 +++ b/doc/rush-info.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-info" "1" "September 2023" "" "Show information about a package." +.TH "rush-info" "1" "November 2023" "" "Show information about a package." .hy .SH NAME .PP diff --git a/doc/rush-info.md b/doc/rush-info.md index c210ba4..c051886 100644 --- a/doc/rush-info.md +++ b/doc/rush-info.md @@ -1,6 +1,6 @@ % rush-info(1) | Show information about a package. % -% September 2023 +% November 2023 NAME ================================================== @@ -49,4 +49,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-list.1 b/doc/rush-list.1 index 2c8fa08..ddbb4ae 100644 --- a/doc/rush-list.1 +++ b/doc/rush-list.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-list" "1" "September 2023" "" "Show packages in one or all repositories." +.TH "rush-list" "1" "November 2023" "" "Show packages in one or all repositories." .hy .SH NAME .PP diff --git a/doc/rush-list.md b/doc/rush-list.md index 1d191dd..3d330a5 100644 --- a/doc/rush-list.md +++ b/doc/rush-list.md @@ -1,6 +1,6 @@ % rush-list(1) | Show packages in one or all repositories. % -% September 2023 +% November 2023 NAME ================================================== @@ -71,4 +71,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-pull.1 b/doc/rush-pull.1 index 97786d6..f3be3c9 100644 --- a/doc/rush-pull.1 +++ b/doc/rush-pull.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-pull" "1" "September 2023" "" "Git pull one or all repositories." +.TH "rush-pull" "1" "November 2023" "" "Git pull one or all repositories." .hy .SH NAME .PP diff --git a/doc/rush-pull.md b/doc/rush-pull.md index 9559110..43273de 100644 --- a/doc/rush-pull.md +++ b/doc/rush-pull.md @@ -1,6 +1,6 @@ % rush-pull(1) | Git pull one or all repositories. % -% September 2023 +% November 2023 NAME ================================================== @@ -41,4 +41,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-push.1 b/doc/rush-push.1 index 2165610..ad9f31e 100644 --- a/doc/rush-push.1 +++ b/doc/rush-push.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-push" "1" "September 2023" "" "Git push one or all repositories." +.TH "rush-push" "1" "November 2023" "" "Git push one or all repositories." .hy .SH NAME .PP diff --git a/doc/rush-push.md b/doc/rush-push.md index de4ea97..1fb2cf2 100644 --- a/doc/rush-push.md +++ b/doc/rush-push.md @@ -1,6 +1,6 @@ % rush-push(1) | Git push one or all repositories. % -% September 2023 +% November 2023 NAME ================================================== @@ -64,4 +64,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-remove.1 b/doc/rush-remove.1 index 98005ab..937c190 100644 --- a/doc/rush-remove.1 +++ b/doc/rush-remove.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-remove" "1" "September 2023" "" "Unregister a local repository." +.TH "rush-remove" "1" "November 2023" "" "Unregister a local repository." .hy .SH NAME .PP diff --git a/doc/rush-remove.md b/doc/rush-remove.md index 6740bb7..a9381a8 100644 --- a/doc/rush-remove.md +++ b/doc/rush-remove.md @@ -1,6 +1,6 @@ % rush-remove(1) | Unregister a local repository. % -% September 2023 +% November 2023 NAME ================================================== @@ -56,4 +56,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-search.1 b/doc/rush-search.1 index 4d2af66..60e2046 100644 --- a/doc/rush-search.1 +++ b/doc/rush-search.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-search" "1" "September 2023" "" "Search in package names and info files." +.TH "rush-search" "1" "November 2023" "" "Search in package names and info files." .hy .SH NAME .PP diff --git a/doc/rush-search.md b/doc/rush-search.md index 85606a1..da582b5 100644 --- a/doc/rush-search.md +++ b/doc/rush-search.md @@ -1,6 +1,6 @@ % rush-search(1) | Search in package names and info files. % -% September 2023 +% November 2023 NAME ================================================== @@ -35,4 +35,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-show.1 b/doc/rush-show.1 index d0fa4c1..50c9924 100644 --- a/doc/rush-show.1 +++ b/doc/rush-show.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-show" "1" "September 2023" "" "Show package files." +.TH "rush-show" "1" "November 2023" "" "Show package files." .hy .SH NAME .PP diff --git a/doc/rush-show.md b/doc/rush-show.md index bb68acf..eedaeec 100644 --- a/doc/rush-show.md +++ b/doc/rush-show.md @@ -1,6 +1,6 @@ % rush-show(1) | Show package files. % -% September 2023 +% November 2023 NAME ================================================== @@ -42,4 +42,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-snatch.1 b/doc/rush-snatch.1 index 4a80ba4..49539a3 100644 --- a/doc/rush-snatch.1 +++ b/doc/rush-snatch.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-snatch" "1" "September 2023" "" "Install a package from a remote repo." +.TH "rush-snatch" "1" "November 2023" "" "Install a package from a remote repo." .hy .SH NAME .PP @@ -54,12 +54,17 @@ This may mean different things in different packages. .SS --verbose, -v .PP Show additional details if possible. +.SS --undo, -u +.PP +Run the undo script instead of the main script. .SH EXAMPLES .IP .nf \f[C] rush snatch james python +rush snatch james python --undo + rush snatch james/other-rush-repo python \f[R] .fi diff --git a/doc/rush-snatch.md b/doc/rush-snatch.md index 71a7e3d..09aa0bf 100644 --- a/doc/rush-snatch.md +++ b/doc/rush-snatch.md @@ -1,6 +1,6 @@ % rush-snatch(1) | Install a package from a remote repo. % -% September 2023 +% November 2023 NAME ================================================== @@ -60,12 +60,20 @@ This may mean different things in different packages. Show additional details if possible. +--undo, -u +-------------------------------------------------- + +Run the undo script instead of the main script. + + EXAMPLES ================================================== ~~~ rush snatch james python +rush snatch james python --undo + rush snatch james/other-rush-repo python ~~~ @@ -76,4 +84,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush-undo.1 b/doc/rush-undo.1 index 37c26ae..82b4bef 100644 --- a/doc/rush-undo.1 +++ b/doc/rush-undo.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush-undo" "1" "September 2023" "" "Uninstall a package." +.TH "rush-undo" "1" "November 2023" "" "Uninstall a package." .hy .SH NAME .PP diff --git a/doc/rush-undo.md b/doc/rush-undo.md index 82e709f..16f5c6d 100644 --- a/doc/rush-undo.md +++ b/doc/rush-undo.md @@ -1,6 +1,6 @@ % rush-undo(1) | Uninstall a package. % -% September 2023 +% November 2023 NAME ================================================== @@ -58,4 +58,3 @@ SEE ALSO **rush**(1) - diff --git a/doc/rush.1 b/doc/rush.1 index 5d367e4..597bf8b 100644 --- a/doc/rush.1 +++ b/doc/rush.1 @@ -14,7 +14,7 @@ . ftr VB CB . ftr VBI CBI .\} -.TH "rush" "1" "September 2023" "Version 0.7.11" "Personal package manager." +.TH "rush" "1" "November 2023" "Version 0.7.11" "Personal package manager." .hy .SH NAME .PP diff --git a/doc/rush.md b/doc/rush.md index 450b943..9caff23 100644 --- a/doc/rush.md +++ b/doc/rush.md @@ -1,6 +1,6 @@ % rush(1) Version 0.7.11 | Personal package manager. % Danny Ben Shitrit \ -% September 2023 +% November 2023 NAME ================================================== diff --git a/rush b/rush index 5199e34..c37c0b9 100755 --- a/rush +++ b/rush @@ -1,5 +1,5 @@ #!/usr/bin/env bash -# This script was generated by bashly 1.1.0 (https://bashly.dannyb.co) +# This script was generated by bashly 1.1.2 (https://bashly.dannyb.co) # Modifying it manually is not recommended # :wrapper.bash3_bouncer @@ -608,6 +608,11 @@ rush_snatch_usage() { printf " Show additional details if possible.\n" echo + # :flag.usage + printf " %s\n" "--undo, -u" + printf " Run the undo script instead of the main script.\n" + echo + # :command.usage_fixed_flags printf " %s\n" "--help, -h" printf " Show this help\n" @@ -629,6 +634,7 @@ rush_snatch_usage() { # :command.usage_examples printf "%s\n" "$(bold "Examples:")" printf " rush snatch james python\n" + printf " rush snatch james python --undo\n" printf " rush snatch james/other-rush-repo python\n" echo @@ -1048,22 +1054,21 @@ magenta_underlined() { print_in_color "\e[4;35m" "$*"; } cyan_underlined() { print_in_color "\e[4;36m" "$*"; } # src/lib/config.sh - config_show() { config_load ini_show } config_get() { - local key="$1" - local default_value="$2" + local key="${1-}" + local default_value="${2-}" config_load echo "${ini["$key"]:-$default_value}" } config_set() { - local key="$1" + local key="${1-}" shift local value="$*" @@ -1073,7 +1078,7 @@ config_set() { } config_del() { - local key="$1" + local key="${1-}" config_load unset "ini[$key]" @@ -1095,7 +1100,7 @@ config_reload() { } config_load() { - [[ "$config_loaded" == "true" ]] && return + [[ "${config_loaded-}" == "true" ]] && return declare -g CONFIG_FILE=${CONFIG_FILE:=config.ini} declare -g config_loaded=true @@ -1108,7 +1113,6 @@ config_save() { } # src/lib/ini.sh - ini_load() { declare -gA ini @@ -1129,6 +1133,7 @@ ini_load() { elif [[ $line =~ $key_regex ]]; then key="${BASH_REMATCH[1]}" value="${BASH_REMATCH[2]}" + [[ $value == *\$* ]] && eval "value=\"$value\"" ini["${section}${key}"]="$value" fi done <"$ini_file" @@ -1254,7 +1259,7 @@ send_completions() { echo $' ;;' echo $'' echo $' \'snatch\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_rush_completions_filter "--force --help --verbose -f -h -v")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_rush_completions_filter "--force --help --undo --verbose -f -h -u -v")" -- "$cur" )' echo $' ;;' echo $'' echo $' \'search\'*)' @@ -1679,6 +1684,7 @@ rush_snatch_command() { # Collect variables repo_id=${args[github_user]} package=${args[package]} + undo=${args[--undo]} path="$HOME/rush-repos/snatched" [[ -n "${args['--force']}" ]] && export FORCE=1 [[ -n "${args['--verbose']}" ]] && export VERBOSE=1 @@ -1692,7 +1698,11 @@ rush_snatch_command() { trap cleanup EXIT ERR INT TERM rush clone "$repo_id" "$path" --name snatched - rush get "snatched:$package" + if [[ $undo ]]; then + rush undo "snatched:$package" + else + rush get "snatched:$package" + fi } @@ -2846,6 +2856,14 @@ rush_snatch_parse_requirements() { shift ;; + # :flag.case + --undo | -u) + + # :flag.case_no_arg + args['--undo']=1 + shift + ;; + -?*) printf "invalid option: %s\n" "$key" >&2 exit 1 diff --git a/src/bashly.yml b/src/bashly.yml index 25e4627..2d19334 100644 --- a/src/bashly.yml +++ b/src/bashly.yml @@ -279,8 +279,13 @@ commands: short: -v help: Show additional details if possible. + - long: --undo + short: -u + help: Run the undo script instead of the main script. + examples: - rush snatch james python + - rush snatch james python --undo - rush snatch james/other-rush-repo python - name: copy diff --git a/src/lib/config.sh b/src/lib/config.sh index 6069472..4795a7a 100644 --- a/src/lib/config.sh +++ b/src/lib/config.sh @@ -8,7 +8,6 @@ ## - Use any of the following functions to access and manipulate the values. ## - INI sections are optional (i.e., sectionless key=value pairs are allowed). ## - ## Show all the key=value pairs from your config file config_show() { config_load @@ -28,8 +27,8 @@ config_show() { ## theme="$(config_get interface.theme)" ## config_get() { - local key="$1" - local default_value="$2" + local key="${1-}" + local default_value="${2-}" config_load echo "${ini["$key"]:-$default_value}" @@ -40,7 +39,7 @@ config_get() { ## config_set cloud.provider aws ## config_set() { - local key="$1" + local key="${1-}" shift local value="$*" @@ -54,7 +53,7 @@ config_set() { ## config_del login.email ## config_del() { - local key="$1" + local key="${1-}" config_load unset "ini[$key]" @@ -93,7 +92,7 @@ config_reload() { ## Load an INI file (unless loaded) and populate the associative array ## NOTE: Normally there is no need to call this function, it is called as needed config_load() { - [[ "$config_loaded" == "true" ]] && return + [[ "${config_loaded-}" == "true" ]] && return declare -g CONFIG_FILE=${CONFIG_FILE:=config.ini} declare -g config_loaded=true diff --git a/src/lib/ini.sh b/src/lib/ini.sh index 26bf8d2..862b734 100644 --- a/src/lib/ini.sh +++ b/src/lib/ini.sh @@ -25,7 +25,6 @@ ## unset ini[section1.key1] ## ini_save path/to/config.ini ## - ## Load an INI file and populate the associative array `ini`. ini_load() { declare -gA ini @@ -47,6 +46,7 @@ ini_load() { elif [[ $line =~ $key_regex ]]; then key="${BASH_REMATCH[1]}" value="${BASH_REMATCH[2]}" + [[ $value == *\$* ]] && eval "value=\"$value\"" ini["${section}${key}"]="$value" fi done <"$ini_file" diff --git a/src/lib/send_completions.sh b/src/lib/send_completions.sh index b037294..ddad8c1 100644 --- a/src/lib/send_completions.sh +++ b/src/lib/send_completions.sh @@ -59,7 +59,7 @@ send_completions() { echo $' ;;' echo $'' echo $' \'snatch\'*)' - echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_rush_completions_filter "--force --help --verbose -f -h -v")" -- "$cur" )' + echo $' while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_rush_completions_filter "--force --help --undo --verbose -f -h -u -v")" -- "$cur" )' echo $' ;;' echo $'' echo $' \'search\'*)' diff --git a/src/snatch_command.sh b/src/snatch_command.sh index 5e4a855..4ffd1ea 100644 --- a/src/snatch_command.sh +++ b/src/snatch_command.sh @@ -1,6 +1,7 @@ # Collect variables repo_id=${args[github_user]} package=${args[package]} +undo=${args[--undo]} path="$HOME/rush-repos/snatched" [[ -n "${args['--force']}" ]] && export FORCE=1 [[ -n "${args['--verbose']}" ]] && export VERBOSE=1 @@ -14,4 +15,8 @@ say "snatch" "$repo_id $package" trap cleanup EXIT ERR INT TERM rush clone "$repo_id" "$path" --name snatched -rush get "snatched:$package" +if [[ $undo ]]; then + rush undo "snatched:$package" +else + rush get "snatched:$package" +fi diff --git a/test/approvals/rush_completions b/test/approvals/rush_completions index 756d8de..57fd5d9 100644 --- a/test/approvals/rush_completions +++ b/test/approvals/rush_completions @@ -57,7 +57,7 @@ _rush_completions() { ;; 'snatch'*) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_rush_completions_filter "--force --help --verbose -f -h -v")" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "$(_rush_completions_filter "--force --help --undo --verbose -f -h -u -v")" -- "$cur" ) ;; 'search'*) diff --git a/test/approvals/rush_snatch_h b/test/approvals/rush_snatch_h index a772a3a..c295abe 100644 --- a/test/approvals/rush_snatch_h +++ b/test/approvals/rush_snatch_h @@ -20,6 +20,9 @@ rush snatch --verbose, -v Show additional details if possible. + --undo, -u + Run the undo script instead of the main script. + --help, -h Show this help @@ -36,4 +39,5 @@ rush snatch Examples: rush snatch james python + rush snatch james python --undo rush snatch james/other-rush-repo python From dccf9f0d4f48868e3bc0292b557663f237da24e6 Mon Sep 17 00:00:00 2001 From: Danny Ben Shitrit Date: Sun, 19 Nov 2023 12:17:57 +0000 Subject: [PATCH 2/2] add tests for snatch --undo --- test/approvals/rush_snatch_dannyben_hello_undo | 12 ++++++++++++ test/approve | 1 + 2 files changed, 13 insertions(+) create mode 100644 test/approvals/rush_snatch_dannyben_hello_undo diff --git a/test/approvals/rush_snatch_dannyben_hello_undo b/test/approvals/rush_snatch_dannyben_hello_undo new file mode 100644 index 0000000..70344e2 --- /dev/null +++ b/test/approvals/rush_snatch_dannyben_hello_undo @@ -0,0 +1,12 @@ +snatch | dannyben hello +clone | https://github.com/dannyben/rush-repo.git +Cloning into '/root/rush-repos/snatched'... +undo | snatched:hello +Executing undo +REPO: snatched +REPO_PATH: /root/rush-repos/snatched +USER_CWD: /test +VERBOSE: +FORCE: +remove | snatched +remove | purged /root/rush-repos/snatched diff --git a/test/approve b/test/approve index 5f72188..c76f1b5 100755 --- a/test/approve +++ b/test/approve @@ -85,6 +85,7 @@ describe "snatch" approve "rush snatch" || return 0 approve "rush snatch -h" approve "rush snatch dannyben hello" + approve "rush snatch dannyben hello --undo" approve "rush snatch dannyben hello --force --verbose" [[ -d $dir ]] && fail "Expected directory $dir to not exist"