diff --git a/dockerc b/dockerc index 764ad60..2c71cd2 100755 --- a/dockerc +++ b/dockerc @@ -713,17 +713,17 @@ ABSTRACT_CONTEXT='false' # Unless context is '--': in this case, use no compose file argument if [ "$CONTEXT" != '--' ]; then - CONTEXT_ONLY_ROOT_STANDARD='false' + CONTEXT_SKIP_ROOT_STANDARD='false' if [ "$CONTEXT" = '-' ] || [ "$CONTEXT" = '.' ]; then # Use default context CONTEXT='' - elif [ "$(echo "$CONTEXT" | cut -c1)" = '.' ]; then + elif [ "$(echo "$CONTEXT" | cut -c1)" = '-' ]; then # Only look for standard root level compose files - CONTEXT_ONLY_ROOT_STANDARD='true' - # Remove leading dot - CONTEXT="${CONTEXT#.}" + CONTEXT_SKIP_ROOT_STANDARD='true' + # Remove leading dash + CONTEXT="${CONTEXT#-}" fi # Iterate over directories: @@ -761,15 +761,19 @@ if [ "$CONTEXT" != '--' ]; then EOF fi - # Check for standard root level compose file + if [ "$CONTEXT_SKIP_ROOT_STANDARD" != 'true' ]; then + + # Check for standard root level compose file + + # Look for root compose file + COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" '' '' "$COMPOSE_EXTENSION") + COMPOSE_LOOK_CODE=$? + if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then + # Compose file found + LVL1_COMPOSE_FILE_ARGS="$LVL1_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE" + LVL1_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true') + fi - # Look for root compose file - COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" '' '' "$COMPOSE_EXTENSION") - COMPOSE_LOOK_CODE=$? - if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then - # Compose file found - LVL1_COMPOSE_FILE_ARGS="$LVL1_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE" - LVL1_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true') fi # Parse context parts @@ -830,7 +834,7 @@ if [ "$CONTEXT" != '--' ]; then fi done <<-EOF - $(echo "$CONTEXT" | tr '-' "\n" | tr '.' "\n") + $(echo "$CONTEXT" | tr '.' "\n") EOF if [ -n "$LVL2_COMPOSE_FILE_ARGS" ]; then @@ -840,108 +844,104 @@ if [ "$CONTEXT" != '--' ]; then fi - if [ "$CONTEXT_ONLY_ROOT_STANDARD" != 'true' ]; then + LVL2_COMPOSE_FILE_ARGS='' + LVL2_ENV_FILE_ARGS="$LVL1_ENV_FILE_ARGS" + LVL2_ABSTRACT_CONTEXT='false' - LVL2_COMPOSE_FILE_ARGS='' - LVL2_ENV_FILE_ARGS="$LVL1_ENV_FILE_ARGS" - LVL2_ABSTRACT_CONTEXT='false' + # Check for non-standard root level compose files - # Check for non-standard root level compose files - - # Extract first context part - CONTEXT_FIRST="${CONTEXT%%.*}" - CONTEXT_REST="$([ "$CONTEXT" = "$CONTEXT_FIRST" ] && echo '' || echo "${CONTEXT#*.}")" - - # Look for universal env files - ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '.-' "$CONTEXT_FIRST") - ENV_LOOK_CODE=$? - if [ "$ENV_LOOK_CODE" -eq 0 ]; then - while read -r ENV_LOOK_FILE; do - LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE" - done <<-EOF - $(echo "$ENV_LOOK_FILES") - EOF - fi + # Extract first context part + CONTEXT_FIRST="${CONTEXT%%.*}" + CONTEXT_REST="$([ "$CONTEXT" = "$CONTEXT_FIRST" ] && echo '' || echo "${CONTEXT#*.}")" - # Look for context env files - ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '' "$CONTEXT_FIRST") - ENV_LOOK_CODE=$? - if [ "$ENV_LOOK_CODE" -eq 0 ]; then - while read -r ENV_LOOK_FILE; do - LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE" - done <<-EOF - $(echo "$ENV_LOOK_FILES") - EOF - fi + # Look for universal env files + ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '.-' "$CONTEXT_FIRST") + ENV_LOOK_CODE=$? + if [ "$ENV_LOOK_CODE" -eq 0 ]; then + while read -r ENV_LOOK_FILE; do + LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE" + done <<-EOF + $(echo "$ENV_LOOK_FILES") + EOF + fi - # Look for root compose file - COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" "-$CONTEXT_FIRST" '' "$COMPOSE_EXTENSION") - COMPOSE_LOOK_CODE=$? - if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then - # Compose file found - LVL2_COMPOSE_FILE_ARGS="$LVL2_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE" - LVL2_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true') - fi + # Look for context env files + ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '' "$CONTEXT_FIRST") + ENV_LOOK_CODE=$? + if [ "$ENV_LOOK_CODE" -eq 0 ]; then + while read -r ENV_LOOK_FILE; do + LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE" + done <<-EOF + $(echo "$ENV_LOOK_FILES") + EOF + fi + + # Look for root compose file + COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" "-$CONTEXT_FIRST" '' "$COMPOSE_EXTENSION") + COMPOSE_LOOK_CODE=$? + if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then + # Compose file found + LVL2_COMPOSE_FILE_ARGS="$LVL2_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE" + LVL2_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true') + fi + + # Parse context parts + if [ -n "$CONTEXT_REST" ]; then + + LVL2_PREFIX='' + + while read -r CONTEXT_PART; do + + if [ -z "$CONTEXT_PART" ]; then + # Skip empty parts + continue + fi + + LVL2_PREFIX="$LVL2_PREFIX.$CONTEXT_PART" + + # Look for universal env files + ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '.-' "$CONTEXT_PART") + ENV_LOOK_CODE=$? + if [ "$ENV_LOOK_CODE" -eq 0 ]; then + while read -r ENV_LOOK_FILE; do + LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE" + done <<-EOF + $(echo "$ENV_LOOK_FILES") + EOF + fi + + # Look for context env files + ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '' "$LVL2_PREFIX") + ENV_LOOK_CODE=$? + if [ "$ENV_LOOK_CODE" -eq 0 ]; then + while read -r ENV_LOOK_FILE; do + LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE" + done <<-EOF + $(echo "$ENV_LOOK_FILES") + EOF + fi - # Parse context parts - if [ -n "$CONTEXT_REST" ]; then - - LVL2_PREFIX='' - - while read -r CONTEXT_PART; do - - if [ -z "$CONTEXT_PART" ]; then - # Skip empty parts - continue - fi - - LVL2_PREFIX="$LVL2_PREFIX.$CONTEXT_PART" - - # Look for universal env files - ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '.-' "$CONTEXT_PART") - ENV_LOOK_CODE=$? - if [ "$ENV_LOOK_CODE" -eq 0 ]; then - while read -r ENV_LOOK_FILE; do - LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE" - done <<-EOF - $(echo "$ENV_LOOK_FILES") - EOF - fi - - # Look for context env files - ENV_LOOK_FILES=$(look_env_files "$COMPOSE_DIR" '' "$LVL2_PREFIX") - ENV_LOOK_CODE=$? - if [ "$ENV_LOOK_CODE" -eq 0 ]; then - while read -r ENV_LOOK_FILE; do - LVL2_ENV_FILE_ARGS="$LVL2_ENV_FILE_ARGS --env-file $ENV_LOOK_FILE" - done <<-EOF - $(echo "$ENV_LOOK_FILES") - EOF - fi - - # Look for context compose file - COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" "-$CONTEXT_FIRST" "$LVL2_PREFIX" "$COMPOSE_EXTENSION") - COMPOSE_LOOK_CODE=$? - if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then - # Context compose file found - LVL2_COMPOSE_FILE_ARGS="$LVL2_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE" - LVL2_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true') - - else - # Context compose file not found: invalidate LVL2 and break loop - LVL2_COMPOSE_FILE_ARGS='' - break - fi - - done <<-EOF - $(echo "$CONTEXT_REST" | tr '-' "\n" | tr '.' "\n") - EOF - - if [ -n "$LVL2_COMPOSE_FILE_ARGS" ]; then - # Context resolved: break loop + # Look for context compose file + COMPOSE_LOOK_FILE=$(look_compose_file "$COMPOSE_DIR" "$COMPOSE_PREFIX" "-$CONTEXT_FIRST" "$LVL2_PREFIX" "$COMPOSE_EXTENSION") + COMPOSE_LOOK_CODE=$? + if [ "$COMPOSE_LOOK_CODE" -ne 1 ]; then + # Context compose file found + LVL2_COMPOSE_FILE_ARGS="$LVL2_COMPOSE_FILE_ARGS -f $COMPOSE_LOOK_FILE" + LVL2_ABSTRACT_CONTEXT=$([ "$COMPOSE_LOOK_CODE" -eq 0 ] && echo 'false' || echo 'true') + + else + # Context compose file not found: invalidate LVL2 and break loop + LVL2_COMPOSE_FILE_ARGS='' break fi + done <<-EOF + $(echo "$CONTEXT_REST" | tr '.' "\n") + EOF + + if [ -n "$LVL2_COMPOSE_FILE_ARGS" ]; then + # Context resolved: break loop + break fi fi diff --git a/test/test/structure_1_22_00/cwd/docker-compose.long-name.yml b/test/test/structure_1_22_00/cwd/docker-compose.long-name.yml new file mode 100644 index 0000000..e69de29 diff --git a/test/test/structure_1_22_00/test_disambiguation.py b/test/test/structure_1_22_00/test_disambiguation.py index 91a3e11..74e03c6 100644 --- a/test/test/structure_1_22_00/test_disambiguation.py +++ b/test/test/structure_1_22_00/test_disambiguation.py @@ -7,7 +7,6 @@ def test_dev(file = __file__): 'dev', ) dockerc.assert_context_ok( - # TODO: change behavior format_dockerc_stdout( b'docker compose' b' -f ./docker-compose.yml' @@ -22,11 +21,9 @@ def test_dash_dev(file = __file__): '-dev', ) dockerc.assert_context_ok( - # TODO: change behavior format_dockerc_stdout( b'docker compose' - b' -f ./docker-compose.yml' - b' -f ./docker-compose.dev.yml' + b' -f ./docker-compose-dev.yml' b' up -d' ), ) diff --git a/test/test/structure_1_22_00/test_long.py b/test/test/structure_1_22_00/test_long.py new file mode 100644 index 0000000..b06e5fb --- /dev/null +++ b/test/test/structure_1_22_00/test_long.py @@ -0,0 +1,16 @@ +from test.src.format_dockerc_stdout import format_dockerc_stdout +from test.src.TestDirContext import TestDirContext + +def test_long(file = __file__): + with TestDirContext(file) as ctx: + dockerc = ctx.run_dockerc( + 'long-name', + ) + dockerc.assert_context_ok( + format_dockerc_stdout( + b'docker compose' + b' -f ./docker-compose.yml' + b' -f ./docker-compose.long-name.yml' + b' up -d' + ), + )