chshersh / tool-sync

🧰 Download pre-built binaries of all your favourite tools with a single command
https://crates.io/crates/tool-sync
Mozilla Public License 2.0
69 stars 16 forks source link

[#54] Adding extra path and added a new error for the case where multiple assets are found #102

Closed MitchellBerend closed 1 year ago

MitchellBerend commented 1 year ago

Resolves #54

This pr add an extra path that gets checked once the binary is downloaded from github. Additionally it also adds an error case where multiple matches are found.

Additional tasks

MitchellBerend commented 1 year ago

The config I tested with and its result.

$ cat tools.toml
# This config file was generated for version 0.1.0
#
# # tool-sync default configuration file
# https://github.com/chshersh/tool-sync
# This file was automatically generated by tool-sync
#####################################################
#
#
store_directory = "$HOME/rust/tool-sync/bin"
#
# tool-sync provides native support for some of the tools without the need to configure them
# Uncomment the tools you want to have them
#
# [bat]
# [difftastic]
# [exa]
# [fd]
[ripgrep]
# [tool-sync]
#
# To add configuration for other tools these are the config options:
[github]
        owner     = "cli" 
        repo      = "cli" 
        exe_name  = "gh"

        # Uncomment to download a specific version or tag.
        # Without this tag latest will be used
        tag       = "v2.14.7"

# Asset name to download on linux OSes
        asset_name.linux = "linux_amd64"
#
# uncomment if you want to install on macOS as well
# asset_name.macos = "apple-darwin"
#
# uncomment if you want to install on Windows as well
# asset_name.windows = "x86_64-pc-windows-msvc"
$ cargo run -- --config tools.toml sync 
   Compiling tool-sync v0.1.0 (/home/mitchell/rust/tool-sync)
    Finished dev [unoptimized + debuginfo] target(s) in 2.40s
     Running `target/debug/tool --config tools.toml sync`
❌  github 
Multiple name matches found for this asset:

     * gh_2.14.7_linux_amd64.deb
     * gh_2.14.7_linux_amd64.rpm
     * gh_2.14.7_linux_amd64.tar.gz

Please add one of these to the config.
🔄  All done!                                                                                                                                                             📦  Estimated total download size: 2.01 MiB
✅  ripgrep 13.0.0   Completed!                                                                                                                                           ✨  Successfully installed 1 tools!
📁  Installation directory: /home/mitchell/rust/tool-sync/bin
MitchellBerend commented 1 year ago

@chshersh The hardcoded gh binary on mac now downloads the amd64 version, it does not support arm (yes) but this might be possible in the future. The same is true for x86 and arm for linux, should there be an error in the realm of:

hey your arch is x but this config/hardcoded tool currently downloads y, add to your .tool.toml

MitchellBerend commented 1 year ago

On line 90, you extract name from all original assets fetched from GitHub. I think, it would be better to show only those assets that match the provided query.

The variable naming is not optimal here.

This part has asset contain a Vec<Asset> with only matches. https://github.com/chshersh/tool-sync/blob/265e1f3105291e979c4ccc6704515ea3d66151f8/src/model/tool.rs#L79-L83

This part then pulls out the names of all matches. https://github.com/chshersh/tool-sync/blob/265e1f3105291e979c4ccc6704515ea3d66151f8/src/model/tool.rs#L90-L91

This should probably be ensured in the test though so I will add an asset that does not match.