@@ -37,6 +37,7 @@ rush_usage() {
3737 echo " get Install a package (default)"
3838 echo " undo Uninstall a package"
3939 echo " snatch Install a package from a remote repo"
40+ echo " copy Copy a package between local repositories"
4041 echo " info Show information about a package"
4142 echo " list Show packages in one or all repositories"
4243 echo " search Search in package names and info files"
@@ -530,6 +531,56 @@ rush_snatch_usage() {
530531 fi
531532}
532533
534+ # :command.usage
535+ rush_copy_usage () {
536+ if [[ -n $long_usage ]]; then
537+ printf " rush copy - Copy a package between local repositories\n"
538+ echo
539+ else
540+ printf " rush copy - Copy a package between local repositories\n"
541+ echo
542+ fi
543+
544+ printf " Usage:\n"
545+ printf " rush copy SOURCE_PACKAGE [TARGET_PACKAGE] [options]\n"
546+ printf " rush copy --help | -h\n"
547+ echo
548+
549+ if [[ -n $long_usage ]]; then
550+ printf " Options:\n"
551+ # :command.usage_fixed_flags
552+ echo " --help, -h"
553+ printf " Show this help\n"
554+ echo
555+ # :command.usage_flags
556+ # :flag.usage
557+ echo " --force, -f"
558+ printf " Copy the package even if it already exists in the target repository.\n"
559+ echo
560+ # :command.usage_args
561+ printf " Arguments:\n"
562+
563+ # :argument.usage
564+ echo " SOURCE_PACKAGE"
565+ printf " Source 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"
566+ echo
567+
568+ # :argument.usage
569+ echo " TARGET_PACKAGE"
570+ printf " Target 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 If left empty, the package will be copied with the same name to the\n default repository.\n"
571+ echo
572+
573+ # :command.usage_examples
574+ printf " Examples:\n"
575+
576+ printf " rush copy james:python\n"
577+ printf " rush copy james:python bobby\n"
578+ printf " rush copy james:python bobby:python3 --force\n"
579+ echo
580+
581+ fi
582+ }
583+
533584# :command.usage
534585rush_info_usage () {
535586 if [[ -n $long_usage ]]; then
@@ -1244,6 +1295,59 @@ rush_snatch_command() {
12441295 rush get " snatched:$package "
12451296}
12461297
1298+ # :command.function
1299+ rush_copy_command () {
1300+ # :src/copy_command.sh
1301+ source_package=${args[source_package]}
1302+ target_package=${args[target_package]}
1303+ force=${args[--force]}
1304+ source_repo=default
1305+ target_repo=default
1306+
1307+ if [[ $source_package =~ (.* ):(.* ) ]]; then
1308+ source_repo=${BASH_REMATCH[1]}
1309+ source_package=${BASH_REMATCH[2]}
1310+ fi
1311+
1312+ if [[ -z " $target_package " ]]; then
1313+ target_package=" $source_package "
1314+ elif [[ $target_package =~ (.* ):(.* ) ]]; then
1315+ target_repo=${BASH_REMATCH[1]}
1316+ target_package=${BASH_REMATCH[2]}
1317+ fi
1318+
1319+ source_repo_path=$( config_get " $source_repo " )
1320+ target_repo_path=$( config_get " $target_repo " )
1321+ source_package_path=" $source_repo_path /$source_package "
1322+ target_package_path=" $target_repo_path /$target_package "
1323+
1324+ if [[ $source_repo == " default" ]]; then
1325+ source_display_name=" $source_package "
1326+ else
1327+ source_display_name=" $source_repo :$source_package "
1328+ fi
1329+
1330+ if [[ $target_repo == " default" ]]; then
1331+ target_display_name=" $target_package "
1332+ else
1333+ target_display_name=" $target_repo :$target_package "
1334+ fi
1335+
1336+ [[ $source_repo_path ]] || abort " source repo not found: $source_repo "
1337+ [[ $target_repo_path ]] || abort " target repo not found: $target_repo "
1338+ [[ -d $source_package_path ]] || abort " source package not found: $source_repo :$source_package "
1339+ if [[ -d $target_package_path ]]; then
1340+ if [[ $force ]]; then
1341+ rm -rf " $target_package_path "
1342+ else
1343+ abort " target package already exists: $target_repo :$target_package \nrun again with --force to copy anyway"
1344+ fi
1345+ fi
1346+
1347+ say " copy" " $source_display_name to $target_display_name "
1348+ cp -R " $source_package_path " " $target_package_path "
1349+ }
1350+
12471351# :command.function
12481352rush_info_command () {
12491353 # :src/info_command.sh
@@ -1262,7 +1366,7 @@ rush_info_command() {
12621366
12631367 # Verify we have everything we need
12641368 [[ $repo_path ]] || abort " repo not found: $repo "
1265- [[ -d $package_path ]] || abort " package not found: $repo / $package "
1369+ [[ -d $package_path ]] || abort " package not found: $repo : $package "
12661370 [[ -f $infofile ]] || abort " infofile not found: $infofile "
12671371
12681372 cat " $infofile "
@@ -1435,7 +1539,7 @@ rush_show_command() {
14351539
14361540 # Verify we have everything we need
14371541 [[ $repo_path ]] || abort " repo not found: $repo "
1438- [[ -d $package_path ]] || abort " package not found: $repo / $package "
1542+ [[ -d $package_path ]] || abort " package not found: $repo : $package "
14391543
14401544 # Show the package data
14411545 if [[ $file ]]; then
@@ -1548,6 +1652,13 @@ parse_requirements() {
15481652 shift $#
15491653 ;;
15501654
1655+ copy )
1656+ action=" copy"
1657+ shift
1658+ rush_copy_parse_requirements " $@ "
1659+ shift $#
1660+ ;;
1661+
15511662 info | i )
15521663 action=" info"
15531664 shift
@@ -2250,6 +2361,71 @@ rush_snatch_parse_requirements() {
22502361 # :command.whitelist_filter
22512362}
22522363
2364+ # :command.parse_requirements
2365+ rush_copy_parse_requirements () {
2366+ # :command.fixed_flag_filter
2367+ case " $1 " in
2368+ --version | -v )
2369+ version_command
2370+ exit
2371+ ;;
2372+
2373+ --help | -h )
2374+ long_usage=yes
2375+ rush_copy_usage
2376+ exit 1
2377+ ;;
2378+
2379+ esac
2380+ # :command.environment_variables_filter
2381+ # :command.dependencies_filter
2382+ # :command.command_filter
2383+ action=" copy"
2384+ # :command.required_args_filter
2385+ if [[ $1 && $1 != -* ]]; then
2386+ args[source_package]=$1
2387+ shift
2388+ else
2389+ printf " missing required argument: SOURCE_PACKAGE\nusage: rush copy SOURCE_PACKAGE [TARGET_PACKAGE] [options]\n"
2390+ exit 1
2391+ fi
2392+ # :command.required_flags_filter
2393+ # :command.parse_requirements_while
2394+ while [[ $# -gt 0 ]]; do
2395+ key=" $1 "
2396+ case " $key " in
2397+ # :flag.case
2398+ --force | -f )
2399+ args[--force]=1
2400+ shift
2401+ ;;
2402+
2403+
2404+ -* )
2405+ printf " invalid option: %s\n" " $key "
2406+ exit 1
2407+ ;;
2408+
2409+ * )
2410+ # :command.parse_requirements_case
2411+ if [[ ! ${args[source_package]} ]]; then
2412+ args[source_package]=$1
2413+ shift
2414+ elif [[ ! ${args[target_package]} ]]; then
2415+ args[target_package]=$1
2416+ shift
2417+ else
2418+ printf " invalid argument: %s\n" " $key "
2419+ exit 1
2420+ fi
2421+ ;;
2422+
2423+ esac
2424+ done
2425+ # :command.default_assignments
2426+ # :command.whitelist_filter
2427+ }
2428+
22532429# :command.parse_requirements
22542430rush_info_parse_requirements () {
22552431 # :command.fixed_flag_filter
@@ -2630,6 +2806,14 @@ run() {
26302806 rush_snatch_command
26312807 fi
26322808
2809+ elif [[ $action == " copy" ]]; then
2810+ if [[ ${args[--help]} ]]; then
2811+ long_usage=yes
2812+ rush_copy_usage
2813+ else
2814+ rush_copy_command
2815+ fi
2816+
26332817 elif [[ $action == " info" ]]; then
26342818 if [[ ${args[--help]} ]]; then
26352819 long_usage=yes
0 commit comments