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

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

Merged
merged 12 commits into from
Sep 20, 2022

Conversation

MitchellBerend
Copy link
Collaborator

@MitchellBerend MitchellBerend commented Sep 19, 2022

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

  • Documentation for changes provided/changed
  • Tests added

@MitchellBerend MitchellBerend added enhancement New feature or request config TOML configuration, config-related CLI options output Fancy (and not so) output of the tool labels Sep 19, 2022
@MitchellBerend
Copy link
Collaborator Author

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 MitchellBerend marked this pull request as ready for review September 19, 2022 16:26
Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a helpful message improvement 👍🏻

As always, a few comments 🙂

Comment on lines +80 to +82
.iter()
.filter(|&asset| asset.name.contains(asset_name))
.map(|asset| asset.to_owned())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder, could we use into_iter() instead of iter() to avoid cloning values and return owned values from the list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not work here unfortunately since assets is used again on line 90.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this an error?

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.

So, I imagine, if you add an asset with non-matching name in the multiple_asset_found test, the test would expect this non-matching asset as well. And I think we want to show only matching assets.

Or do I read the code incorrectly? 🤔

@MitchellBerend
Copy link
Collaborator Author

@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

Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more question in the review.

About arm64 — agree, let's keep it for future improvements. Currently, tool-sync matches only on env::consts::OS but when we want to support an arch, we need to handle env::consts::ARCH as well. This will complicate the logic significantly (especially when we want to support automatic asset name guess) so this would require a proper thinking ahead 🙂

Comment on lines +80 to +82
.iter()
.filter(|&asset| asset.name.contains(asset_name))
.map(|asset| asset.to_owned())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this an error?

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.

So, I imagine, if you add an asset with non-matching name in the multiple_asset_found test, the test would expect this non-matching asset as well. And I think we want to show only matching assets.

Or do I read the code incorrectly? 🤔

@MitchellBerend
Copy link
Collaborator Author

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.

let mut asset = assets
.iter()
.filter(|&asset| asset.name.contains(asset_name))
.map(|asset| asset.to_owned())
.collect::<Vec<Asset>>();

This part then pulls out the names of all matches.

let assets: Vec<String> =
asset.iter().map(|item| item.name.clone()).collect();

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

Copy link
Owner

@chshersh chshersh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks terrific 🏆

@chshersh chshersh merged commit 51489f4 into chshersh:main Sep 20, 2022
@MitchellBerend MitchellBerend deleted the 54-support-exe_name-in-asset branch September 20, 2022 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
config TOML configuration, config-related CLI options enhancement New feature or request output Fancy (and not so) output of the tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support path 'asset_name/bin/<exe_name>' inside assets
2 participants