Skip to content

Commit b2fa971

Browse files
committed
- Add show command instead of info -x
1 parent 00607f9 commit b2fa971

21 files changed

+259
-110
lines changed

rush

Lines changed: 154 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ rush_usage() {
4141
echo " list Show packages in one or all repositories"
4242
echo " search Search in package names and info files"
4343
echo " edit Edit package files"
44+
echo " show Show package files"
4445
echo
4546

4647
if [[ -n $long_usage ]]; then
@@ -534,7 +535,7 @@ rush_info_usage() {
534535
echo
535536

536537
printf "Usage:\n"
537-
printf " rush info PACKAGE [options]\n"
538+
printf " rush info PACKAGE\n"
538539
printf " rush info --help | -h\n"
539540
echo
540541

@@ -544,11 +545,7 @@ rush_info_usage() {
544545
echo " --help, -h"
545546
printf " Show this help\n"
546547
echo
547-
# :command.usage_flags
548-
# :flag.usage
549-
echo " --extended, -x"
550-
printf " Show source code for the main and undo scripts\n"
551-
echo
548+
552549
# :command.usage_args
553550
printf "Arguments:\n"
554551

@@ -694,6 +691,44 @@ rush_edit_usage() {
694691
fi
695692
}
696693

694+
# :command.usage
695+
rush_show_usage() {
696+
if [[ -n $long_usage ]]; then
697+
printf "rush show - Show package files\n"
698+
echo
699+
else
700+
printf "rush show - Show package files\n"
701+
echo
702+
fi
703+
704+
printf "Usage:\n"
705+
printf " rush show PACKAGE [FILE]\n"
706+
printf " rush show --help | -h\n"
707+
echo
708+
709+
if [[ -n $long_usage ]]; then
710+
printf "Options:\n"
711+
# :command.usage_fixed_flags
712+
echo " --help, -h"
713+
printf " Show this help\n"
714+
echo
715+
716+
# :command.usage_args
717+
printf "Arguments:\n"
718+
719+
# :argument.usage
720+
echo " PACKAGE"
721+
printf " Package name\n This can either be the package name without the repository name (in\n this case, the default repository will be used) or in the form of\n 'repo:package'.\n"
722+
echo
723+
724+
# :argument.usage
725+
echo " FILE"
726+
printf " File to show (show all if not specified)\n"
727+
echo
728+
729+
fi
730+
}
731+
697732
# :command.inspect_args
698733
inspect_args() {
699734
readarray -t sorted_keys < <(printf '%s\n' "${!args[@]}" | sort)
@@ -1196,7 +1231,6 @@ rush_info_command() {
11961231
# :src/info_command.sh
11971232
# Collect variables
11981233
package=${args[package]}
1199-
extended=${args[--extended]}
12001234
repo="default"
12011235

12021236
if [[ $package =~ (.*):(.*) ]]; then
@@ -1213,29 +1247,7 @@ rush_info_command() {
12131247
[[ -d $package_path ]] || abort "package not found: $repo/$package"
12141248
[[ -f $infofile ]] || abort "infofile not found: $infofile"
12151249

1216-
# Show the package data
1217-
if [[ $extended ]]; then
1218-
mainfile="$package_path/main"
1219-
undofile="$package_path/undo"
1220-
1221-
green "info:"
1222-
cat "$infofile"
1223-
echo
1224-
1225-
if [[ -f $mainfile ]]; then
1226-
green "main:"
1227-
cat "$mainfile"
1228-
echo
1229-
fi
1230-
1231-
if [[ -f $undofile ]]; then
1232-
green "undo:"
1233-
cat "$undofile"
1234-
echo
1235-
fi
1236-
else
1237-
cat "$infofile"
1238-
fi
1250+
cat "$infofile"
12391251
}
12401252

12411253
# :command.function
@@ -1386,6 +1398,43 @@ rush_edit_command() {
13861398
"$edit" "$file_path"
13871399
}
13881400

1401+
# :command.function
1402+
rush_show_command() {
1403+
# :src/show_command.sh
1404+
# Collect variables
1405+
package=${args[package]}
1406+
file=${args[file]}
1407+
repo="default"
1408+
1409+
if [[ $package =~ (.*):(.*) ]]; then
1410+
repo=${BASH_REMATCH[1]}
1411+
package=${BASH_REMATCH[2]}
1412+
fi
1413+
1414+
repo_path=$(config_get "$repo")
1415+
package_path="$repo_path/$package"
1416+
file_path="$package_path/$file"
1417+
1418+
# Verify we have everything we need
1419+
[[ $repo_path ]] || abort "repo not found: $repo"
1420+
[[ -d $package_path ]] || abort "package not found: $repo/$package"
1421+
1422+
# Show the package data
1423+
if [[ $file ]]; then
1424+
[[ -f $file_path ]] || abort "file not found: $file_path"
1425+
cat "$file_path"
1426+
else
1427+
shopt -s dotglob
1428+
for f in "$package_path"/*; do
1429+
green "$(basename "$f")"
1430+
cat "$f"
1431+
echo
1432+
echo
1433+
done
1434+
shopt -u dotglob
1435+
fi
1436+
}
1437+
13891438
# :command.parse_requirements
13901439
parse_requirements() {
13911440
# :command.fixed_flag_filter
@@ -1509,6 +1558,13 @@ parse_requirements() {
15091558
shift $#
15101559
;;
15111560

1561+
show )
1562+
action="show"
1563+
shift
1564+
rush_show_parse_requirements "$@"
1565+
shift $#
1566+
;;
1567+
15121568
"" )
15131569
rush_usage
15141570
exit 1
@@ -2189,20 +2245,14 @@ rush_info_parse_requirements() {
21892245
args[package]=$1
21902246
shift
21912247
else
2192-
printf "missing required argument: PACKAGE\nusage: rush info PACKAGE [options]\n"
2248+
printf "missing required argument: PACKAGE\nusage: rush info PACKAGE\n"
21932249
exit 1
21942250
fi
21952251
# :command.required_flags_filter
21962252
# :command.parse_requirements_while
21972253
while [[ $# -gt 0 ]]; do
21982254
key="$1"
21992255
case "$key" in
2200-
# :flag.case
2201-
--extended | -x )
2202-
args[--extended]=1
2203-
shift
2204-
;;
2205-
22062256

22072257
-* )
22082258
printf "invalid option: %s\n" "$key"
@@ -2396,6 +2446,65 @@ rush_edit_parse_requirements() {
23962446
# :command.whitelist_filter
23972447
}
23982448

2449+
# :command.parse_requirements
2450+
rush_show_parse_requirements() {
2451+
# :command.fixed_flag_filter
2452+
case "$1" in
2453+
--version | -v )
2454+
version_command
2455+
exit
2456+
;;
2457+
2458+
--help | -h )
2459+
long_usage=yes
2460+
rush_show_usage
2461+
exit 1
2462+
;;
2463+
2464+
esac
2465+
# :command.environment_variables_filter
2466+
# :command.dependencies_filter
2467+
# :command.command_filter
2468+
action="show"
2469+
# :command.required_args_filter
2470+
if [[ $1 && $1 != -* ]]; then
2471+
args[package]=$1
2472+
shift
2473+
else
2474+
printf "missing required argument: PACKAGE\nusage: rush show PACKAGE [FILE]\n"
2475+
exit 1
2476+
fi
2477+
# :command.required_flags_filter
2478+
# :command.parse_requirements_while
2479+
while [[ $# -gt 0 ]]; do
2480+
key="$1"
2481+
case "$key" in
2482+
2483+
-* )
2484+
printf "invalid option: %s\n" "$key"
2485+
exit 1
2486+
;;
2487+
2488+
* )
2489+
# :command.parse_requirements_case
2490+
if [[ ! ${args[package]} ]]; then
2491+
args[package]=$1
2492+
shift
2493+
elif [[ ! ${args[file]} ]]; then
2494+
args[file]=$1
2495+
shift
2496+
else
2497+
printf "invalid argument: %s\n" "$key"
2498+
exit 1
2499+
fi
2500+
;;
2501+
2502+
esac
2503+
done
2504+
# :command.default_assignments
2505+
# :command.whitelist_filter
2506+
}
2507+
23992508
# :command.initialize
24002509
initialize() {
24012510
version="0.5.9"
@@ -2523,6 +2632,14 @@ run() {
25232632
rush_edit_command
25242633
fi
25252634

2635+
elif [[ $action == "show" ]]; then
2636+
if [[ ${args[--help]} ]]; then
2637+
long_usage=yes
2638+
rush_show_usage
2639+
else
2640+
rush_show_command
2641+
fi
2642+
25262643
elif [[ $action == "root" ]]; then
25272644
root_command
25282645
fi

sample-repo/download/main

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22
set -e
3-
cp somefile $USER_CWD/somefile
4-
echo "Saved 'somefile' in the current directory"
3+
cp .somefile $USER_CWD/.somefile
4+
echo "Saved '.somefile' in the current directory"

sample-repo/download/undo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/env bash
22
set -e
3-
rm $USER_CWD/somefile
4-
echo "Removed 'somefile' from the current directory"
3+
rm $USER_CWD/.somefile
4+
echo "Removed '.somefile' from the current directory"

src/bashly.yml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,6 @@ commands:
220220
required: true
221221
help: *package_help
222222

223-
flags:
224-
- long: --extended
225-
short: -x
226-
help: Show source code for the main and undo scripts
227-
228223
examples:
229224
- rush info ruby
230225
- rush info centos:ruby
@@ -277,3 +272,13 @@ commands:
277272
File to edit
278273
Default: main
279274
275+
- name: show
276+
help: Show package files
277+
278+
args:
279+
- name: package
280+
required: true
281+
help: *package_help
282+
283+
- name: file
284+
help: File to show (show all if not specified)

src/info_command.sh

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Collect variables
22
package=${args[package]}
3-
extended=${args[--extended]}
43
repo="default"
54

65
if [[ $package =~ (.*):(.*) ]]; then
@@ -17,26 +16,4 @@ infofile="$package_path/info"
1716
[[ -d $package_path ]] || abort "package not found: $repo/$package"
1817
[[ -f $infofile ]] || abort "infofile not found: $infofile"
1918

20-
# Show the package data
21-
if [[ $extended ]]; then
22-
mainfile="$package_path/main"
23-
undofile="$package_path/undo"
24-
25-
green "info:"
26-
cat "$infofile"
27-
echo
28-
29-
if [[ -f $mainfile ]]; then
30-
green "main:"
31-
cat "$mainfile"
32-
echo
33-
fi
34-
35-
if [[ -f $undofile ]]; then
36-
green "undo:"
37-
cat "$undofile"
38-
echo
39-
fi
40-
else
41-
cat "$infofile"
42-
fi
19+
cat "$infofile"

src/show_command.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Collect variables
2+
package=${args[package]}
3+
file=${args[file]}
4+
repo="default"
5+
6+
if [[ $package =~ (.*):(.*) ]]; then
7+
repo=${BASH_REMATCH[1]}
8+
package=${BASH_REMATCH[2]}
9+
fi
10+
11+
repo_path=$(config_get "$repo")
12+
package_path="$repo_path/$package"
13+
file_path="$package_path/$file"
14+
15+
# Verify we have everything we need
16+
[[ $repo_path ]] || abort "repo not found: $repo"
17+
[[ -d $package_path ]] || abort "package not found: $repo/$package"
18+
19+
# Show the package data
20+
if [[ $file ]]; then
21+
[[ -f $file_path ]] || abort "file not found: $file_path"
22+
cat "$file_path"
23+
else
24+
shopt -s dotglob
25+
for f in "$package_path"/*; do
26+
green "$(basename "$f")"
27+
cat "$f"
28+
echo
29+
echo
30+
done
31+
shopt -u dotglob
32+
fi

test/approvals/rush

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ Package Commands:
2626
list Show packages in one or all repositories
2727
search Search in package names and info files
2828
edit Edit package files
29+
show Show package files

test/approvals/rush_get_download

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
get | download
2-
Saved 'somefile' in the current directory
2+
Saved '.somefile' in the current directory

test/approvals/rush_help

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Package Commands:
2626
list Show packages in one or all repositories
2727
search Search in package names and info files
2828
edit Edit package files
29+
show Show package files
2930

3031
Options:
3132
--help, -h

0 commit comments

Comments
 (0)