Skip to content

Commit cd7c045

Browse files
Merge branch 'master' of https://github.com/possi/modman into possi-master
2 parents 799fbd1 + 990da31 commit cd7c045

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

modman

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Global Commands:
4444
--tutorial show a brief tutorial on using modman
4545
--version display the modman script's version
4646
[--force] overwrite existing files, ignore untrusted cert warnings
47+
[--quiet|-q] prevent output of non-interactive commands
4748
[--no-local] skip processing of modman.local files
4849
[--no-clean] skip cleaning of broken symlinks
4950
[--no-shell] skip processing @shell lines
@@ -273,6 +274,12 @@ error ()
273274
{
274275
echo -e "$(bold)$(red)ERROR:$(unbold) "$1
275276
}
277+
#############################################################
278+
# Usual output
279+
log ()
280+
{
281+
[ $QUIET -eq 0 ] && printf "$@" && [ $# -eq 1 ] && echo ""
282+
}
276283

277284
#############################################################
278285
# Check for existence of a module directory and modman file
@@ -377,15 +384,15 @@ set_skipped ()
377384

378385
if [ "$skip" = 1 ]; then
379386
if get_skipped $module; then
380-
echo "Module $module already skipped."
387+
log "Module $module already skipped."
381388
exit 1
382389
else
383390
echo $module >> "$SKIP_FILE"
384-
echo "Module $module added to skip list."
391+
log "Module $module added to skip list."
385392
fi
386393
else
387394
grep -v "^$module$" "$SKIP_FILE" > "$SKIP_FILE.tmp"; mv "$SKIP_FILE.tmp" "$SKIP_FILE"
388-
echo "Module $module removed from skip list."
395+
log "Module $module removed from skip list."
389396
fi
390397

391398
return 0
@@ -407,7 +414,7 @@ get_abs_filename() {
407414

408415
remove_module_links ()
409416
{
410-
echo "Removing links for module $module."
417+
log "Removing links for module $module."
411418
local module_dir="$mm/$module"
412419
for line in $(find $root -type l); do
413420
if [[ $(get_abs_filename "$line") =~ ^"$module_dir".* ]]; then
@@ -466,7 +473,7 @@ apply_modman_file ()
466473
return 1
467474
fi
468475

469-
echo "Deploying $real"
476+
log "Deploying $real"
470477
if [ -z "$import_base" ]; then
471478
import_base=${basedir%%/}
472479
else
@@ -477,7 +484,7 @@ apply_modman_file ()
477484
error "Could not create import base directory: $import_base"
478485
return 1
479486
fi
480-
echo "Created import base directory: $import_base"
487+
log "Created import base directory: $import_base"
481488
fi
482489
if ! set_basedir "$module_dir/$import_path" "$import_base"; then
483490
return 1
@@ -578,7 +585,7 @@ apply_path ()
578585
if [[ "$line" != *"$real"* ]]; then
579586
echo " $($stat_type "$dest") path: $real"
580587
fi
581-
echo "(Run with $(bold)--force$(unbold) to force removal of existing files and directories.)"
588+
log "(Run with $(bold)--force$(unbold) to force removal of existing files and directories.)"
582589
return 1
583590
elif ! [ -L "$dest" ] || [ "$src" != "$(readlink "$dest")" ]; then
584591
warning "Removing conflicting $($stat_type "$dest"): $dest"
@@ -608,7 +615,7 @@ apply_path ()
608615
ln -s "$src" "$dest" && success=1
609616
fi
610617
if [ $success -eq 1 ]; then
611-
printf " Applied: %-30s %s\n" "$target" "$real"
618+
log " Applied: %-30s %s\n" "$target" "$real"
612619
else
613620
error "Unable to $verb ($dest):\n $line"
614621
return 1
@@ -734,6 +741,7 @@ root=$_pwd
734741
735742
# Check for common option overrides
736743
FORCE=0 # --force option off by default
744+
QUIET=0 # --quiet option off by default
737745
NOLOCAL=0 # --no-local option off by default
738746
NOCLEAN=0 # --no-clean off by default
739747
NOSHELL=0 # --no-shell option off by default
@@ -743,6 +751,7 @@ basedir=''
743751
while true; do
744752
case "$1" in
745753
--force) FORCE=1; shift ;;
754+
--quiet|-q) QUIET=1; shift ;;
746755
--no-local) NOLOCAL=1; shift ;;
747756
--no-clean) NOCLEAN=1; shift ;;
748757
--no-shell) NOSHELL=1; shift ;;
@@ -859,12 +868,12 @@ elif [ "$action" = "deploy-all" ]; then
859868
for module in $(ls -1 "$mm"); do
860869
test -d "$mm/$module" && require_wc "$module" || continue;
861870
if get_skipped "$module"; then
862-
echo "Skipping module $module due to .modman-skip file."
871+
log "Skipping module $module due to .modman-skip file."
863872
continue
864873
fi
865-
echo "Deploying $module to $root"
874+
log "Deploying $module to $root"
866875
if apply_modman_file "$mm/$module/modman"; then
867-
echo -e "Deployment of '$module' complete.\n"
876+
log "Deployment of '$module' complete.\n"
868877
if [ $NOLOCAL -eq 0 -a -r "$mm/$module/modman.local" ]; then
869878
apply_modman_file "$mm/$module/modman.local" && echo "Applied local modman file for $module"
870879
fi
@@ -873,7 +882,7 @@ elif [ "$action" = "deploy-all" ]; then
873882
errors=$((errors+1))
874883
fi
875884
done
876-
echo "Deployed all modules with $errors errors."
885+
log "Deployed all modules with $errors errors."
877886
if [ $errors -gt 0 ]; then
878887
exit 1
879888
else
@@ -896,7 +905,7 @@ elif [ "$action" = "update-all" ]; then
896905
if [ -e .git ]; then
897906
if [ -d .git ]; then
898907
if [ "$(git remote)" != "" ]; then
899-
echo "Fetching changes for $module"
908+
log "Fetching changes for $module"
900909
success=0
901910
if [ $FORCE -eq 1 ]; then
902911
if git status -s | grep -vq '??'; then
@@ -910,13 +919,13 @@ elif [ "$action" = "update-all" ]; then
910919
fi
911920
fi
912921
else
913-
echo "Git submodule detected. Determining state..."
922+
log "Git submodule detected. Determining state..."
914923
if [ $(git rev-parse --symbolic-full-name --abbrev-ref HEAD) = "HEAD" ]; then
915-
echo "In detached state, checking out main branch..."
924+
log "In detached state, checking out main branch..."
916925
branch=$(git ls-remote --heads origin | grep $(git rev-parse HEAD) | cut -d / -f 3)
917926
git checkout $branch
918927
fi
919-
echo "Fetching changes for $module"
928+
log "Fetching changes for $module"
920929
success=0
921930
if [ $FORCE -eq 1 ]; then
922931
if git status -s | grep -vq '??'; then
@@ -944,15 +953,15 @@ elif [ "$action" = "update-all" ]; then
944953
cd "$mm/$module"
945954
success=0
946955
if [ -d .svn ]; then
947-
echo "Updating $module"
956+
log "Updating $module"
948957
if [ $FORCE -eq 1 ]; then
949958
svn update --force --non-interactive --trust-server-cert && success=1
950959
else
951960
svn update && success=1
952961
fi
953962
elif [ -e .git ] && [ "$(git remote)" != "" ]; then
954963
tracking_branch=$(get_tracking_branch)
955-
echo "Updating $module"
964+
log "Updating $module"
956965
if [ -z $tracking_branch ]; then
957966
echo "Could not resolve remote tracking branch, code will not be updated."
958967
elif [ $FORCE -eq 1 ]; then
@@ -961,12 +970,12 @@ elif [ "$action" = "update-all" ]; then
961970
git merge $tracking_branch && git submodule update --init --recursive && success=1
962971
fi
963972
elif [ -d .hg ]; then
964-
echo "Updating $module"
973+
log "Updating $module"
965974
hg pull && hg update && success=1
966975
else
967976
success=1
968977
fi
969-
echo
978+
log ""; # Forced new line, respect --quiet
970979
if [ $success -ne 1 ]; then
971980
error "Error occurred while updating $module\n"
972981
update_errors=$((update_errors+1))
@@ -977,7 +986,7 @@ elif [ "$action" = "update-all" ]; then
977986
for module in $(ls -1 "$mm"); do
978987
test -d "$mm/$module" && require_wc "$module" || continue;
979988
if apply_modman_file "$mm/$module/modman"; then
980-
echo -e "Deployment of '$module' complete.\n"
989+
log "Deployment of '$module' complete."
981990
if [ $NOLOCAL -eq 0 -a -r "$mm/$module/modman.local" ]; then
982991
apply_modman_file "$mm/$module/modman.local" && echo "Applied local modman file for $module"
983992
fi
@@ -986,31 +995,34 @@ elif [ "$action" = "update-all" ]; then
986995
deploy_errors=$((deploy_errors+1))
987996
fi
988997
done
989-
echo "Updated all modules with $update_errors update errors and $deploy_errors deploy errors."
998+
log "Updated all modules with $update_errors update errors and $deploy_errors deploy errors."
990999
exit 0
9911000
9921001
###########################
9931002
# Handle "repair" command
9941003
elif [ "$action" = "repair" ]; then
995-
echo "Repairing links, do not interrupt."
1004+
log "Repairing links, do not interrupt."
9961005
mv "$mm" "$mm-repairing" || { error "Could not temporarily rename .modman directory."; exit 1; }
9971006
remove_dead_links
9981007
mv "$mm-repairing" "$mm" || { error "Could not restore .modman directory."; exit 1; }
9991008
for module in $(ls -1 "$mm"); do
10001009
test -d "$mm/$module" && require_wc "$module" || continue;
1010+
log "Deploying $module to $root"
10011011
remove_basedirs "$module" &&
10021012
apply_modman_file "$mm/$module/modman" &&
1003-
echo -e "Repaired $module.\n"
1013+
log "Repaired $module."
10041014
if [ $NOLOCAL -eq 0 -a -r "$mm/$module/modman.local" ]; then
1005-
apply_modman_file "$mm/$module/modman.local" && echo "Applied local modman file for $module"
1015+
if apply_modman_file "$mm/$module/modman.local"; then
1016+
log "Applied local modman file for $module"
1017+
fi
10061018
fi
10071019
done
10081020
exit 0
10091021
10101022
###########################
10111023
# Handle "clean" command
10121024
elif [ "$action" = "clean" ]; then
1013-
echo "Cleaning broken links."
1025+
log "Cleaning broken links."
10141026
NOCLEAN=0
10151027
remove_dead_links
10161028
exit 0

0 commit comments

Comments
 (0)