jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
10.45k stars 302 forks source link

CLI helper to convert asdf tool versions file to RTX config TOML file #970

Open Nezteb opened 1 year ago

Nezteb commented 1 year ago

I think it'd be cool if there was a helper command (something like rtx convert maybe) that checks the current working directory and if there is a .tool-versions file, it attempts to generate a .rtx.toml file from it. If a .rtx.toml file already exists in the current directory, the command could just print the generated .rtx.toml to the console so the user can manually copy-paste if they would prefer.

I made a bash alias for this:

function asdfToRtx() {
  input=".tool-versions"
  output=".rtx.toml"

  declare -A language_map=(
    ["nodejs"]="node"
  )

  if [[ -e $output ]]; then
    echo "[tools]"
  else
    echo "[tools]" > $output
  fi

  # Read the input file line by line
  while IFS= read -r line
  do
    # Split the line into name and version
    name=$(echo $line | awk '{print $1}')
    version=$(echo $line | awk '{print $2}')

    # Rename languages if needed
    if [[ -n "${language_map[$name]}" ]]; then
      name="${language_map[$name]}"
    fi

    line="$name = \"$version\""

    if [[ -e $output ]]; then
      echo $line
    else
      echo $line >> $output
    fi

  done < $input
}
jdx commented 3 days ago

we have mise cfg generate as a common that could probably use a --tool-versions option. This is an easy change if someone wants to contribute. We already have code that can be used to parse .tool-versions:

https://github.com/jdx/mise/blob/c2f0a5a567eb96e5adff5b023dcbeced5e1e93b0/src/config/config_file/mod.rs#L208-L221