GithubHelp home page GithubHelp logo

dotboris / alt Goto Github PK

View Code? Open in Web Editor NEW
81.0 3.0 5.0 1.03 MB

A simple version manager tool for switching between different versions of commands

License: MIT License

Rust 85.08% Shell 1.04% Python 8.94% Nix 4.94%
cli version-manager rust linux osx language-agnostic developer-tools command-line shell

alt's People

Contributors

dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar dotboris avatar renovate[bot] avatar walrusse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

alt's Issues

Invoking shimmed command with sudo fails

Steps to reproduce

You'll need a sacrificial command for this. In my case, I'm going to user ruby.

  1. Define command

    alt def ruby test-sys /usr/bin/ruby
  2. Make sure the shims exist

    alt shim
  3. Run your command as root

    sudo ruby --version

alt will call itself in a loop complaining that it's not configured properly.

Why is this happening?

  1. sudo invokes alt (through a shim)
  2. It passes your user's PATH env var (including your user's shim dir $HOME/.local/alt/shims)
  3. alt tries to find the system version of the command (presuming that alt is not configured for the user you're sudoing into)
  4. alt finds your original user's shim dir ($HOME/.local/alt/shims/ruby) (it didn't filter it out because it thinks the shims dir is the one for the user you sudoed into ex: /root/.local/alt/shims)
  5. alt invokes its own shim
  6. goto 1

Deeper problem

alt can invoke itself in a loop. Seems like it's pretty bad at detecting when it's calling itself.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Lock file maintenance

Detected dependencies

cargo
Cargo.toml
  • anyhow 1.0
  • clap 4.5.4
  • toml 0.8.12
  • console 0.15.8
  • lazy_static 1.4.0
  • dialoguer 0.11.0
  • glob 0.3.1
  • thiserror 1.0
  • regex 1
  • assert_cmd 2.0
  • escargot 0.5
  • insta 1.38.0
  • predicates 3.1.0
  • rand 0.8
  • serde 1.0.197
  • test-case 3.3.1
  • tempfile 3
  • clap 4.5.4
  • clap_complete 4.5.2
  • clap_mangen 0.2.20
github-actions
.github/workflows/ci.yml
  • actions/checkout v4
  • Swatinem/rust-cache v2
  • actions/checkout v4
  • Swatinem/rust-cache v2
  • actions/checkout v4
  • Swatinem/rust-cache v2
  • actions/checkout v4
  • Swatinem/rust-cache v2
  • actions/checkout v4
  • ludeeus/action-shellcheck 2.0.0
  • actions/checkout v4
  • actions/checkout v4
  • actions/setup-python v5
  • actions/checkout v4
  • actions/setup-python v5
.github/workflows/nix.yml
  • actions/checkout v4
  • cachix/install-nix-action v26
  • actions/checkout v4
  • cachix/install-nix-action v26
  • actions/checkout v4
  • cachix/install-nix-action v26
.github/workflows/package.yml
  • actions/checkout v4
  • Swatinem/rust-cache v2
  • actions/setup-python v5
  • actions/upload-artifact v4
.github/workflows/pr.yml
  • actions/checkout v4
  • actions/dependency-review-action v4
.github/workflows/release.yml
  • actions/checkout v4
  • Swatinem/rust-cache v2
  • actions/setup-python v5
  • actions/download-artifact v4
nix
flake.nix
  • nixpkgs nixpkgs-unstable

  • Check this box to trigger a request for Renovate to run again on this repository

The installation instructions leave users with a broken instance of `alt`

If you follow the installation instructions to the letter, you end up with a broken version of alt.

The instructions are roughly like so:

  1. Install the binary
  2. Add the shims dir to your PATH
  3. You're done

The problem with this, is that users are left in a shell where the PATH does not contain the shims dir. This means that alt will not work in their current shell.

ARM CI job fails on Release

The latest release (v1.0.3) failed to build the ARM binaries.

Example: https://travis-ci.org/dotboris/alt/builds/504405085

The failure was caused by the strip command not knowing what to do with the arm binaries.

$ strip "target/$TARGET/release/alt"
strip: Unable to recognise the format of the input file `target/arm-unknown-linux-gnueabi/release/alt'
The command "strip "target/$TARGET/release/alt"" failed and exited with 1 during .

Travis CI is effectively dropping free CI for OSS projects

Recently Travis CI announced that they were effectively dropping their free plan. Technically it's possible to get free access to Travis CI for OSS projects but that requires asking them nicely. I don't think that it's worth the time and effort to jump through the hoops that Travis CI has laid out here.

Currently, alt is running travis-ci.org which is going to go in read-only mode on December 31st. See: https://docs.travis-ci.com/user/migrate/open-source-repository-migration/#q-what-will-happen-to-travis-ciorg-after-december-31st-2020
We can migrate to travis-ci.com. This will give us a plan with some free credits that will eventually run out.

Todo

  • Setup code quality checks with github actions
  • Configure automatic release pushing with github actions
  • Remove travis ci config & badge
  • Remove all travis-ci creds

Automatic deployment / release

A little while back Travis effectively dropped it's free tier for OSS projects making it unusable for us. See #137 for the details. In #137 we have migrated the code quality part of the CI. In process we lost the automated deployment / release. We didn't end up implementing it.

The automatic deployment needs to do the following:

  • Update the changelog
  • Update the version number
  • Commit those changes
  • Tag the new version
  • Build all packages
  • Push packages to github release

Using `alt def` with relative paths results in crash when running binary from different directory

Here's a simple example:

$ alt def node 18 ./opt/node-18.12.1/bin/node
$ alt use node 18
Will now use node 18 (./opt/node-18.12.1/bin/node) when in /home/dotboris
$ node --version
v18.12.1
$ cd code/dotboris-io
$ alt show
Versions from: /home/dotboris/code/dotboris-io/.alt.toml
node
 * 18 (./opt/node-18.12.1/bin/node)
python (using system)
   3 (/usr/bin/python3)
$ node --version
๐Ÿ”ฅ alt failed to run node version 18!
error: Os { code: 2, kind: NotFound, message: "No such file or directory" }
command: node
command version: 18
args: ["--version"]
bin: ./opt/node-18.12.1/bin/node
current dir: Ok("/home/dotboris/code/dotboris-io")
thread 'main' panicked at 'explicit panic', src/exec_cmd.rs:47:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

The core of the issue is that alt def takes the path its given as is and stores it. When this path is relative, it's sensitive to the current directory which doesn't work in most cases.

The simple solution here is to make the path absolute before storing it.

Automatically detect commands with multiple versions

Currently, users are expected to define the different versions of commands by hand in ~/.config/alt/defs.toml. This is pretty annoying.

On most systems it should be pretty simple to detect multiple versions of installed commands. For instance:

  • Commands in the PATH with a version suffix. Things like /usr/bin/python2 and /usr/bin/python3.
  • Homebrew (OSX package manager) supports installing multiple versions of commands. Officially supported older versions of a command have an @ in the package name. Example: node@8 and node@8
  • Java support running multiple versions of the JRE / JDK in a pretty standard directory
  • The alternatives system under linux can let us find commands with multiple versions
  • Package managers could let us find multiple versions of command if we figure out some sort of suffix pattern
  • Install tools like ruby-install and node-build can be queried to find multiple versions

We don't necessarily need to support all of these, but the idea is to have a good enough coverage to let most users just run a command and be ready to go

[ISSUE] Could not find any versions of go

Hi, I would like to use your command to switch between golang versions, but the alt command compliant with the following:

โžœ  ~ alt scan go
Sorry, could not find any versions of go

So, here are some outputs to show you my current situation of my workstation:

โžœ  ~ go version
go version go1.11.13 linux/amd64
โžœ  ~ which go
/usr/bin/go
โžœ  ~ ll /usr/bin/go
lrwxrwxrwx 1 root root 20 Aug 15 15:00 /usr/bin/go -> /etc/alternatives/go
โžœ  ~ ll /etc/alternatives/go
lrwxrwxrwx 1 root root 25 Apr  1  2019 /etc/alternatives/go -> /usr/lib64/go/1.11/bin/go
โžœ  ~ ll /usr/lib64/go/
total 0
drwxr-xr-x 1 root root 46 Aug 13 15:00 1.11
drwxr-xr-x 1 root root 46 Sep  1 07:47 1.12
โžœ  ~ 

Thanks

I should be able to switch versions of a command without opening an editor

Right now, users are expected to edit .alt.toml themselves. This is pretty crappy.

Users should be able to do this from the command line with decent validation (in case they screw up the command or version).

We could even give them a menu kind of like the one from alt scan ... so that they can choose a version.

Shimmed command can no longer run the default system command

Steps to reproduce

  1. Add $HOME/.local/alt/shims to your PATH

  2. Define a command in ~/.config/alt/defs.toml

    [node]
  3. Make sure that you have no .alt.toml file for alt to pick up

  4. Run alt exec node

alt will enter a strange loop where it will exec itself over and over again recursively.

This happens because alt tries to exec the command name when it doesn't find a binary

Use system version without going through the menu

I've gotten pretty used to calling alt use with a version. Something like alt use node 10. This works really well when I have a version. If I want to switch to the system version of a command, I need to go through the menu because there's no shortcut for that.

Running `alt use` without any `.alt.toml` files present results in a crash

Steps to reproduce

mkdir -p /tmp/alt-use-crash
cd /tmp/alt-use-crash
alt def bash phony /usr/bin/bash
alt use bash phony
thread 'main' panicked at 'failed to read use file: Os { code: 21, kind: Other, message: "Is a directory" }', libcore/result.rs:945:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::begin_panic_fmt
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::result::unwrap_failed
   9: alt::use_file::load
  10: alt::cli::run
  11: alt::main
  12: std::rt::lang_start::{{closure}}
  13: std::panicking::try::do_call
  14: __rust_maybe_catch_panic
  15: std::rt::lang_start_internal
  16: main

Setup process is painful

Currently, users are expected to:

  1. Setup a rust dev environment (with cargo)
  2. Build the code from source
  3. Add shims to directory to PATH
  4. Create the definitions file defs.toml

Ideally, we need something that requires the user to run the least number of steps while not being a maintenance nightmare.

Choose system version with alt use ...

Currently, alt use ... only supports picking a version.

In some cases, I might have previously selected a version for a command and then no longer want to specify any version at all.

I should be able to turn back to using the system version.

Do not work on self-build software

Hello,

OS: ubuntu 18

I have downloaded the .deb file from https://github.com/dotboris/alt/releases/tag/v1.2.0 and install it with the apt command.
A warning message is shown when finishing as below. I think it's because I log in as root.

Download is performed unsandboxed as root as file '/root/alt_1.2.0_amd64.deb' couldn't be accessed by user '_apt'. - pkgAcquire::Run (13: Permission denied)

This is a warning, so I just ignore it.

I try to config the multiple version of python. And it works.

I build 3 different versions of llvm and add the bin dir to the PATH. (I do not run command make install on them)

However, alt doesn't work on the llvm .

I'm curious that won't alt works on the software make and build by the source code?

Thanks for your help.
Looking forward to your reply.

"Proper" packaging and distribution

Problem

Currently, alt is installed using a curl ... | bash one-liner. This is not really acceptable. It works, but it's not a good solution.

There are a few problems with this:

  • curl ... | bash is super shady. A lot of people are not fond of installing packages using this.
  • There's no good update mechanism. Updating can be done by just re-running the installer
  • There's no easy / official uninstall method
  • The script doesn't support all platforms (#31)
  • No signing / verification of packages

Solution

The rough idea is to make it so that people can install alt using their system package manager. This is really a two part solution:

  1. Build a package
  2. Push that package to a repository

This something that should be CI driven as much as possible. The best would be to have all of this done automatically when a new version is pushed.

Platforms support

What follows is a rough list of platforms that we want to support. This list doesn't cover everything. It covers what I currently use and what I current use and need.

  • OSX
  • Debian and Friends
  • Arch linux

References

`alt scan ...` crashes if a path in the PATH does not exist

Steps to reproduce

$ env RUST_BACKTRACE=1 PATH="$PATH:/some/bs" alt scan something
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 2, kind: NotFound, message: "No such file or directory" }', libcore/result.rs:945:5
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: std::panicking::rust_panic_with_hook
   5: std::panicking::begin_panic_fmt
   6: rust_begin_unwind
   7: core::panicking::panic_fmt
   8: core::result::unwrap_failed
   9: core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &'a mut F>::call_once
  10: <&'a mut I as core::iter::iterator::Iterator>::next
  11: <alloc::vec::Vec<T> as alloc::vec::SpecExtend<T, I>>::from_iter
  12: alt::scan::path_suffix::scan
  13: alt::scan_cmd::run
  14: alt::cli::run
  15: alt::main
  16: std::rt::lang_start::{{closure}}
  17: std::panicking::try::do_call
  18: __rust_maybe_catch_panic
  19: std::rt::lang_start_internal
  20: main

This is an edge case, but it should be dealt with.

Prebuilt ARM binaries

In my context, I mostly care about OSX since M1 & M2 chips are a thing but supporting ARM on linux is also a fine idea.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.