Skip to content

Commit

Permalink
added --skip-dependencies and --only-dependencies options for facilit…
Browse files Browse the repository at this point in the history
…ating installs where homebrew needs to be run as a different user

github brikis98/docker-osx-dev issue brikis98#152
  • Loading branch information
ComaVN committed Dec 14, 2015
1 parent c4df976 commit 2142dc7
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 6 deletions.
48 changes: 42 additions & 6 deletions src/docker-osx-dev
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ function assert_non_empty {
fi
}

#
# Usage: assert_mutually_exclusive VAR_NAME1 VAR_NAME2 ... VAR_NAMEn
#
# Asserts that at most one of $VAR_NAME1, $VAR_NAME2, ..., $VAR_NAMEn is defined
#
function assert_mutually_exclusive {
local found
while [[ $# > 0 ]]; do
local readonly var_name="$1"
if test -n "${!var_name+x}" ; then
if test -n "$found" ; then
log_error "$var_name conflicts with $found"
instructions
exit 1
else
found=$var_name
fi
fi
shift
done
}

#
# Usage: index_of VALUE ARRAY
#
Expand Down Expand Up @@ -871,6 +893,8 @@ function instructions {
echo -e " -e, --exclude-path PATH\t\tExclude PATH while syncing. Behaves identically to rsync's --exclude parameter. May be specified multiple times. Default: $DEFAULT_EXCLUDES"
echo -e " -c, --compose-file COMPOSE_FILE\tRead in this docker-compose file and sync any volumes specified in it. Default: $DEFAULT_COMPOSE_FILE"
echo -e " -i, --ignore-file IGNORE_FILE\t\tRead in this ignore file and exclude any paths within it while syncing (see --exclude). Default: $DEFAULT_IGNORE_FILE"
echo -e " --only-dependencies\t\t\tDuring install, only install the homebrew dependencies. Useful if homebrew is needs to be run as a different user."
echo -e " --skip-dependencies\t\t\tDuring install, don't install the homebrew dependencies. Useful if homebrew is needs to be run as a different user."
echo -e " -l, --log-level LOG_LEVEL\t\tSpecify the logging level. One of: $LOG_LEVELS. Default: ${DEFAULT_LOG_LEVEL}"
echo -e " -h, --help\t\t\t\tPrint this help text and exit."
echo -e
Expand Down Expand Up @@ -1094,12 +1118,16 @@ function sync {
#
function install {
log_info "Starting install of docker-osx-dev"
install_dependencies
init_docker_host
install_rsync_on_docker_host
add_docker_host
add_environment_variables
print_next_steps
if test -z "$SKIP_DEPENDENCIES" ; then
install_dependencies
fi
if test -z "$ONLY_DEPENDENCIES" ; then
init_docker_host
install_rsync_on_docker_host
add_docker_host
add_environment_variables
print_next_steps
fi
}

#
Expand Down Expand Up @@ -1208,6 +1236,12 @@ function handle_command {
DOCKER_MACHINE_NAME="$2"
shift
;;
--only-dependencies)
ONLY_DEPENDENCIES=true
;;
--skip-dependencies)
SKIP_DEPENDENCIES=true
;;
-h|--help)
instructions
exit 0
Expand All @@ -1222,6 +1256,8 @@ function handle_command {
shift
done

assert_mutually_exclusive "ONLY_DEPENDENCIES" "SKIP_DEPENDENCIES"

case "$cmd" in
"$SYNC_COMMAND" | "$SYNC_ONLY_COMMAND" | "$WATCH_ONLY_COMMAND")
configure_log_level "$log_level"
Expand Down
31 changes: 31 additions & 0 deletions test/docker-osx-dev.bats
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,37 @@ load test_helper
assert_success
}

@test "assert_mutually_exclusive exits on conflicting variables" {
FOO=1
BAR=2
run assert_mutually_exclusive "FOO" "BAR"
assert_failure
}

@test "assert_mutually_exclusive exits on conflicting but empty variables" {
FOO=
BAR=
run assert_mutually_exclusive "FOO" "BAR"
assert_failure
}

@test "assert_mutually_exclusive doesn't exit without any variables" {
run assert_mutually_exclusive "FOO" "BAR"
assert_success
}

@test "assert_mutually_exclusive doesn't exit with only the first variable" {
FOO=1
run assert_mutually_exclusive "FOO" "BAR"
assert_success
}

@test "assert_mutually_exclusive doesn't exit with only the last variable" {
BAR=2
run assert_mutually_exclusive "FOO" "BAR"
assert_success
}

@test "env_is_defined returns true for USER variable being defined" {
run env_is_defined "USER"
assert_success
Expand Down

0 comments on commit 2142dc7

Please sign in to comment.