Skip to content

Commit 990da31

Browse files
Jascha Starkepossi
Jascha Starke
authored andcommitted
#81 --quiet: prevent output of non-interactive commands
1 parent d58b80f commit 990da31

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

modman

Lines changed: 34 additions & 22 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] 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
@@ -271,6 +272,12 @@ error ()
271272
{
272273
echo -e "$(bold)$(red)ERROR:$(unbold) "$1
273274
}
275+
#############################################################
276+
# Usual output
277+
log ()
278+
{
279+
[ $QUIET -eq 0 ] && printf "$@" && [ $# -eq 1 ] && echo ""
280+
}
274281

275282
#############################################################
276283
# Check for existence of a module directory and modman file
@@ -375,15 +382,15 @@ set_skipped ()
375382

376383
if [ "$skip" = 1 ]; then
377384
if get_skipped $module; then
378-
echo "Module $module already skipped."
385+
log "Module $module already skipped."
379386
exit 1
380387
else
381388
echo $module >> "$SKIP_FILE"
382-
echo "Module $module added to skip list."
389+
log "Module $module added to skip list."
383390
fi
384391
else
385392
grep -v "^$module$" "$SKIP_FILE" > "$SKIP_FILE.tmp"; mv "$SKIP_FILE.tmp" "$SKIP_FILE"
386-
echo "Module $module removed from skip list."
393+
log "Module $module removed from skip list."
387394
fi
388395

389396
return 0
@@ -397,7 +404,7 @@ get_abs_filename() {
397404

398405
remove_module_links ()
399406
{
400-
echo "Removing links for module $module."
407+
log "Removing links for module $module."
401408
local module_dir="$mm/$module"
402409
for line in $(find $root -type l); do
403410
if [[ $(get_abs_filename "$line") =~ ^"$module_dir".* ]]; then
@@ -466,7 +473,7 @@ apply_modman_file ()
466473
error "Could not create import base directory: $import_base"
467474
return 1
468475
fi
469-
echo "Created import base directory: $import_base"
476+
log "Created import base directory: $import_base"
470477
fi
471478
if ! set_basedir "$module_dir/$import_path" "$import_base"; then
472479
return 1
@@ -567,7 +574,7 @@ apply_path ()
567574
if [[ "$line" != *"$real"* ]]; then
568575
echo " $($stat_type "$dest") path: $real"
569576
fi
570-
echo "(Run with $(bold)--force$(unbold) to force removal of existing files and directories.)"
577+
log "(Run with $(bold)--force$(unbold) to force removal of existing files and directories.)"
571578
return 1
572579
elif ! [ -L "$dest" ] || [ "$src" != "$(readlink "$dest")" ]; then
573580
warning "Removing conflicting $($stat_type "$dest"): $dest"
@@ -597,7 +604,7 @@ apply_path ()
597604
ln -s "$src" "$dest" && success=1
598605
fi
599606
if [ $success -eq 1 ]; then
600-
printf " Applied: %-30s %s\n" "$target" "$real"
607+
log " Applied: %-30s %s\n" "$target" "$real"
601608
else
602609
error "Unable to $verb ($dest):\n $line"
603610
return 1
@@ -739,6 +746,7 @@ fi
739746
740747
# Check for common option overrides
741748
FORCE=0 # --force option off by default
749+
QUIET=0 # --quiet option off by default
742750
NOLOCAL=0 # --no-local option off by default
743751
NOCLEAN=0 # --no-clean off by default
744752
NOSHELL=0 # --no-shell option off by default
@@ -747,6 +755,7 @@ basedir=''
747755
while true; do
748756
case "$1" in
749757
--force) FORCE=1; shift ;;
758+
--quiet|-q) QUIET=1; shift ;;
750759
--no-local) NOLOCAL=1; shift ;;
751760
--no-clean) NOCLEAN=1; shift ;;
752761
--no-shell) NOSHELL=1; shift ;;
@@ -836,12 +845,12 @@ elif [ "$action" = "deploy-all" ]; then
836845
for module in $(ls -1 "$mm"); do
837846
test -d "$mm/$module" && require_wc "$module" || continue;
838847
if get_skipped "$module"; then
839-
echo "Skipping module $module due to .modman-skip file."
848+
log "Skipping module $module due to .modman-skip file."
840849
continue
841850
fi
842-
echo "Deploying $module to $root"
851+
log "Deploying $module to $root"
843852
if apply_modman_file "$mm/$module/modman"; then
844-
echo -e "Deployment of '$module' complete.\n"
853+
log "Deployment of '$module' complete.\n"
845854
if [ $NOLOCAL -eq 0 -a -r "$mm/$module/modman.local" ]; then
846855
apply_modman_file "$mm/$module/modman.local" && echo "Applied local modman file for $module"
847856
fi
@@ -850,7 +859,7 @@ elif [ "$action" = "deploy-all" ]; then
850859
errors=$((errors+1))
851860
fi
852861
done
853-
echo "Deployed all modules with $errors errors."
862+
log "Deployed all modules with $errors errors."
854863
exit 0
855864
856865
###############################
@@ -867,7 +876,7 @@ elif [ "$action" = "update-all" ]; then
867876
cd "$mm/$module"
868877
success=1
869878
if [ -d .git ] && [ "$(git remote)" != "" ]; then
870-
echo "Fetching changes for $module"
879+
log "Fetching changes for $module"
871880
success=0
872881
if [ $FORCE -eq 1 ]; then
873882
if git status -s | grep -vq '??'; then
@@ -894,15 +903,15 @@ elif [ "$action" = "update-all" ]; then
894903
cd "$mm/$module"
895904
success=0
896905
if [ -d .svn ]; then
897-
echo "Updating $module"
906+
log "Updating $module"
898907
if [ $FORCE -eq 1 ]; then
899908
svn update --force --non-interactive --trust-server-cert && success=1
900909
else
901910
svn update && success=1
902911
fi
903912
elif [ -d .git ] && [ "$(git remote)" != "" ]; then
904913
tracking_branch=$(get_tracking_branch)
905-
echo "Updating $module"
914+
log "Updating $module"
906915
if [ -z $tracking_branch ]; then
907916
echo "Could not resolve remote tracking branch, code will not be updated."
908917
elif [ $FORCE -eq 1 ]; then
@@ -911,12 +920,12 @@ elif [ "$action" = "update-all" ]; then
911920
git merge $tracking_branch && git submodule update --init --recursive && success=1
912921
fi
913922
elif [ -d .hg ]; then
914-
echo "Updating $module"
923+
log "Updating $module"
915924
hg pull && hg update && success=1
916925
else
917926
success=1
918927
fi
919-
echo
928+
log ""; # Forced new line, respect --quiet
920929
if [ $success -ne 1 ]; then
921930
error "Error occurred while updating $module\n"
922931
update_errors=$((update_errors+1))
@@ -927,7 +936,7 @@ elif [ "$action" = "update-all" ]; then
927936
for module in $(ls -1 "$mm"); do
928937
test -d "$mm/$module" && require_wc "$module" || continue;
929938
if apply_modman_file "$mm/$module/modman"; then
930-
echo -e "Deployment of '$module' complete.\n"
939+
log "Deployment of '$module' complete."
931940
if [ $NOLOCAL -eq 0 -a -r "$mm/$module/modman.local" ]; then
932941
apply_modman_file "$mm/$module/modman.local" && echo "Applied local modman file for $module"
933942
fi
@@ -936,31 +945,34 @@ elif [ "$action" = "update-all" ]; then
936945
deploy_errors=$((deploy_errors+1))
937946
fi
938947
done
939-
echo "Updated all modules with $update_errors update errors and $deploy_errors deploy errors."
948+
log "Updated all modules with $update_errors update errors and $deploy_errors deploy errors."
940949
exit 0
941950
942951
###########################
943952
# Handle "repair" command
944953
elif [ "$action" = "repair" ]; then
945-
echo "Repairing links, do not interrupt."
954+
log "Repairing links, do not interrupt."
946955
mv "$mm" "$mm-repairing" || { error "Could not temporarily rename .modman directory."; exit 1; }
947956
remove_dead_links
948957
mv "$mm-repairing" "$mm" || { error "Could not restore .modman directory."; exit 1; }
949958
for module in $(ls -1 "$mm"); do
950959
test -d "$mm/$module" && require_wc "$module" || continue;
960+
log "Deploying $module to $root"
951961
remove_basedirs "$module" &&
952962
apply_modman_file "$mm/$module/modman" &&
953-
echo -e "Repaired $module.\n"
963+
log "Repaired $module."
954964
if [ $NOLOCAL -eq 0 -a -r "$mm/$module/modman.local" ]; then
955-
apply_modman_file "$mm/$module/modman.local" && echo "Applied local modman file for $module"
965+
if apply_modman_file "$mm/$module/modman.local"; then
966+
log "Applied local modman file for $module"
967+
fi
956968
fi
957969
done
958970
exit 0
959971
960972
###########################
961973
# Handle "clean" command
962974
elif [ "$action" = "clean" ]; then
963-
echo "Cleaning broken links."
975+
log "Cleaning broken links."
964976
NOCLEAN=0
965977
remove_dead_links
966978
exit 0

0 commit comments

Comments
 (0)