Skip to content

[Command] env-init command is not possible to override locally #873

@anjey-aka-pm

Description

@anjey-aka-pm

Version of Warden

0.14.3

Operating System and Installation Method

Mac OS 14.3.1 via Brew

Describe the Bug

The default command fallback mechanism allow you to locally override any command for your current environment

if (( "$#" )); then
  ## local project directory if running within one; don't fail if it can't be found
  WARDEN_ENV_PATH="$(locateEnvPath 2>/dev/null)" || true

  if [[ -f "${WARDEN_ENV_PATH}/.warden/commands/${1}.cmd" ]]; then
    WARDEN_CMD_VERB="$1"
    WARDEN_CMD_ANYARGS+=("$1")
    WARDEN_CMD_EXEC="${WARDEN_ENV_PATH}/.warden/commands/${1}.cmd"
    WARDEN_CMD_HELP="${WARDEN_ENV_PATH}/.warden/commands/${1}.help"
    shift
  elif [[ -f "${WARDEN_HOME_DIR}/commands/${1}.cmd" ]]; then
    WARDEN_CMD_VERB="$1"
    WARDEN_CMD_ANYARGS+=("$1")
    WARDEN_CMD_EXEC="${WARDEN_HOME_DIR}/commands/${1}.cmd"
    WARDEN_CMD_HELP="${WARDEN_HOME_DIR}/commands/${1}.help"
    shift
  elif [[ -f "${WARDEN_DIR}/commands/${1}.cmd" ]]; then
    WARDEN_CMD_VERB="$1"
    WARDEN_CMD_EXEC="${WARDEN_DIR}/commands/${1}.cmd"
    WARDEN_CMD_HELP="${WARDEN_DIR}/commands/${1}.help"
    shift
  else
    WARDEN_HELP=1
  fi
else
  WARDEN_HELP=1
fi

This works fine when you have your environment initialized already and .env file is present (as it actively search for .env file inside the locateEnvPath. But if you want to initialize your environment first part of the if condition will actually search for /.warden/commands/${1}.cmd (root folder).
I believe it is reasonable to adjust the check to search in the ./.warden/commands/${1}.cmd current folder instead. This way it will be possible to override env-init command as well

To Reproduce

  1. In any empty folder create .warden/commands/env-init.cmd and .warden/commands/env-init.help files
  2. While inside that folder run warden env-init --help or warden env-init
  3. Actual result: fallback to your home folder or core warden command / help files happens.

Expected Behavior

Expected result: your local newly created files are called

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    Status

    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions