Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions rush
Original file line number Diff line number Diff line change
Expand Up @@ -1098,23 +1098,28 @@ list_display_item() {
# src/lib/list_show_repo.sh
list_show_repo() {
local repo_or_package="$1"
local search="$2"
local simple="$3"
local all="$4"
local simple="$2"
local all="$3"
local repo="$repo_or_package"
local explicit_repo=
local package glob repo_path infofile regex package_name

if [[ $repo_or_package =~ (.*):(.*) ]]; then
explicit_repo=1
repo=${BASH_REMATCH[1]}
package=${BASH_REMATCH[2]}
fi

repo_path=$(config_get "$repo")

if [[ ! $repo_path ]]; then
package="$repo"
repo="default"
repo_path=$(config_get "$repo")
if [[ $explicit_repo ]]; then
abort "repo not found: $repo"
else
package="$repo"
repo="default"
repo_path=$(config_get "$repo")
fi
fi

if [[ $package ]]; then
Expand All @@ -1138,11 +1143,7 @@ list_show_repo() {

else
for infofile in "${glob[@]}"; do
if [[ $search ]]; then
regex="$repo_path/(.*${search}.*)/info"
else
regex="$repo_path/(.*)/info"
fi
regex="$repo_path/(.*)/info"

if [[ $infofile =~ $regex ]]; then
package_name="${BASH_REMATCH[1]}"
Expand Down Expand Up @@ -1596,13 +1597,17 @@ rush_default_command() {

# src/commands/default.sh
repo=${args[repo]}

[[ $repo != "default" ]] || abort "cannot use 'default' as the source repo"

repo_path=$(config_get "$repo")

[[ $repo_path ]] || abort "repo not found: $repo"

config_set "default" "$repo_path"
config_del "$repo"
say "default" "$repo ($repo_path)"

}

# :command.function
Expand Down Expand Up @@ -1718,13 +1723,19 @@ rush_snatch_command() {
[[ -n "${args['--verbose']}" ]] && export VERBOSE=1

cleanup() {
rush remove snatched --purge
rm -r "$tmpdir"
local exitcode="$1"

if config_has_key "snatched"; then
rush remove snatched --purge || true
fi

rm -rf "$tmpdir"
return "$exitcode"
}

say "snatch" "$repo_id $package"

trap cleanup EXIT ERR INT TERM
trap 'exitcode=$?; cleanup "$exitcode"' EXIT

rush clone "$repo_id" "$path" --name snatched
if [[ $undo ]]; then
Expand Down Expand Up @@ -1820,15 +1831,14 @@ rush_list_command() {

# src/commands/list.sh
repo_or_package=${args[repo_or_package]}
search=${args[--search]}
simple=${args[--simple]}
all=${args[--all]}

if [[ $repo_or_package ]]; then
list_show_repo "$repo_or_package" "$search" "$simple" "$all"
list_show_repo "$repo_or_package" "$simple" "$all"
else
for k in $(config_keys); do
list_show_repo "$k" "$search" "$simple" "$all"
list_show_repo "$k" "$simple" "$all"
done
fi

Expand Down
5 changes: 4 additions & 1 deletion src/commands/default.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
## Collect variables
repo=${args[repo]}

[[ $repo != "default" ]] || abort "cannot use 'default' as the source repo"

repo_path=$(config_get "$repo")

## Verify we have everything we need
[[ $repo_path ]] || abort "repo not found: $repo"

config_set "default" "$repo_path"
config_del "$repo"
say "default" "$repo ($repo_path)"
say "default" "$repo ($repo_path)"
5 changes: 2 additions & 3 deletions src/commands/list.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
repo_or_package=${args[repo_or_package]}
search=${args[--search]}
simple=${args[--simple]}
all=${args[--all]}

if [[ $repo_or_package ]]; then
list_show_repo "$repo_or_package" "$search" "$simple" "$all"
list_show_repo "$repo_or_package" "$simple" "$all"
else
for k in $(config_keys); do
list_show_repo "$k" "$search" "$simple" "$all"
list_show_repo "$k" "$simple" "$all"
done
fi
12 changes: 9 additions & 3 deletions src/commands/snatch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,19 @@ path="$tmpdir/snatched"
[[ -n "${args['--verbose']}" ]] && export VERBOSE=1

cleanup() {
rush remove snatched --purge
rm -r "$tmpdir"
local exitcode="$1"

if config_has_key "snatched"; then
rush remove snatched --purge || true
fi

rm -rf "$tmpdir"
return "$exitcode"
}

say "snatch" "$repo_id $package"

trap cleanup EXIT ERR INT TERM
trap 'exitcode=$?; cleanup "$exitcode"' EXIT

rush clone "$repo_id" "$path" --name snatched
if [[ $undo ]]; then
Expand Down
23 changes: 12 additions & 11 deletions src/lib/list_show_repo.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
list_show_repo() {
local repo_or_package="$1"
local search="$2"
local simple="$3"
local all="$4"
local simple="$2"
local all="$3"
local repo="$repo_or_package"
local explicit_repo=
local package glob repo_path infofile regex package_name

if [[ $repo_or_package =~ (.*):(.*) ]]; then
explicit_repo=1
repo=${BASH_REMATCH[1]}
package=${BASH_REMATCH[2]}
fi

repo_path=$(config_get "$repo")

if [[ ! $repo_path ]]; then
package="$repo"
repo="default"
repo_path=$(config_get "$repo")
if [[ $explicit_repo ]]; then
abort "repo not found: $repo"
else
package="$repo"
repo="default"
repo_path=$(config_get "$repo")
fi
fi

if [[ $package ]]; then
Expand All @@ -40,11 +45,7 @@ list_show_repo() {

else
for infofile in "${glob[@]}"; do
if [[ $search ]]; then
regex="$repo_path/(.*${search}.*)/info"
else
regex="$repo_path/(.*)/info"
fi
regex="$repo_path/(.*)/info"

if [[ $infofile =~ $regex ]]; then
package_name="${BASH_REMATCH[1]}"
Expand Down
1 change: 1 addition & 0 deletions test/approvals/rush_default_default
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cannot use 'default' as the source repo
1 change: 1 addition & 0 deletions test/approvals/rush_list_nope_thing
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
repo not found: nope
1 change: 1 addition & 0 deletions test/approvals/rush_list_sample_asd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nothing in sample repo
6 changes: 5 additions & 1 deletion test/approve
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ describe "default"
approve "rush default" || return 0
approve "rush default -h"
approve "rush default sample"
approve "rush default default" || return 0
expect_exit_code 1

describe "get"
approve "rush add sample ~/rush-repos/sample-repo"
Expand Down Expand Up @@ -122,7 +124,10 @@ describe "list"
approve "rush list --all"
approve "rush list --all --simple"
approve "rush list hello"
approve "rush list nope:thing" || return 0
expect_exit_code 1
approve "rush list sample"
approve "rush list sample:asd"
approve "rush list nested"
approve "rush list sample:nested"
approve "rush list no-such-package"
Expand Down Expand Up @@ -164,4 +169,3 @@ describe "copy"
describe "completions"
approve "rush completions"
approve "rush completions -h"

Loading