Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI helper to convert asdf tool versions file to mise.toml #970

Closed
Nezteb opened this issue Oct 31, 2023 · 3 comments · Fixed by #3693
Closed

CLI helper to convert asdf tool versions file to mise.toml #970

Nezteb opened this issue Oct 31, 2023 · 3 comments · Fixed by #3693

Comments

@Nezteb
Copy link
Contributor

Nezteb commented Oct 31, 2023

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 pushed a commit that referenced this issue Apr 9, 2024
Co-authored-by: Miles Parfitt <miles.parfitt@bendigoadelaide.com.au>
@jdx
Copy link
Owner

jdx commented Nov 30, 2024

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:

pub fn parse(path: &Path) -> eyre::Result<Box<dyn ConfigFile>> {
if let Ok(settings) = Settings::try_get() {
if settings.paranoid {
trust_check(path)?;
}
}
match detect_config_file_type(path) {
Some(ConfigFileType::MiseToml) => Ok(Box::new(MiseToml::from_file(path)?)),
Some(ConfigFileType::ToolVersions) => Ok(Box::new(ToolVersions::from_file(path)?)),
Some(ConfigFileType::LegacyVersion) => Ok(Box::new(LegacyVersionFile::from_file(path)?)),
#[allow(clippy::box_default)]
_ => Ok(Box::new(MiseToml::default())),
}
}

@jdx jdx pinned this issue Nov 30, 2024
@jdx
Copy link
Owner

jdx commented Dec 5, 2024

I think the above script could be done more simply: .tool-versions | tr ' ' '@' | xargs -n2 mise use

@jdx jdx changed the title CLI helper to convert asdf tool versions file to RTX config TOML file CLI helper to convert asdf tool versions file to mise config TOML file Dec 11, 2024
@jdx jdx changed the title CLI helper to convert asdf tool versions file to mise config TOML file CLI helper to convert asdf tool versions file to mise.toml Dec 11, 2024
@pdecat
Copy link
Contributor

pdecat commented Dec 16, 2024

Slight variation of previous comment to handle renaming of the original file and squeeze multiple spaces: mv .tool-versions{,.bak} ; cat .tool-versions.bak | tr -s ' ' '@' | xargs -n2 mise use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants