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

Install multiple binaries from an archive asset #236

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

duong-dt
Copy link

This is to support installing multiple binaries from an archive asset #234 , without having to download such asset multiple times, by accepting multiple -I,--install-file arguments.

  • When multiple -I,--install-file are specified, and -o,--output is specified, then -o,--output must be a directory.
  • When multiple -I,--install-file are specified, the selected asset (either specified by -s,--select or via by -a,--automatic) must be an archive asset.

@candrapersada
Copy link

Copy link
Owner

@devmatteini devmatteini left a comment

Choose a reason for hiding this comment

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

Hi @duong-dt and thanks for your contribution 😄!

I left some comments to check out :)

Comment on lines +54 to +57
executable_names
.iter()
.map(|e| Executable::Selected(e.clone()))
.collect(),
Copy link
Owner

Choose a reason for hiding this comment

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

  1. Take ownership of executable_names instead of cloning strings:
executable_names
    .into_iter()
    .map(Executable::Selected)
    .collect(),
  1. Remove duplicates from executable_names to avoid a scenario like this:
$ dra download -I foo -I foo -I foo any/repo
Extracted archive executable to '/home/user/foo'
Extracted archive executable to '/home/user/foo'
Extracted archive executable to '/home/user/foo'
Installation completed!

Comment on lines +100 to +101
let destination = self.selection_destination_for_install()?;
self.destination_may_not_dir(&destination)?;
Copy link
Owner

Choose a reason for hiding this comment

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

This should be done inside maybe_install function like it was before. This is a specific behaviour of the install feature.

Comment on lines +125 to +137
if self.install.is_more_than_one() {
match destination {
Destination::File(x) => Err(HandlerError::new(format!(
"Multiple install target (-I,--install-file) are selected \
but output (-o,--output) is not a directory\n \
Output: {:?}",
x
))),
Destination::Directory(_) => Ok(()),
}
} else {
Ok(())
}
Copy link
Owner

Choose a reason for hiding this comment

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

Invert the if condition and remove the else branch to have less indentation and be more clear

let github = GithubClient::from_environment();
let release = self.fetch_release(&github)?;
let selected_asset = self.select_asset(release)?;
self.asset_may_not_be_archive(&selected_asset.name)?;
Copy link
Owner

Choose a reason for hiding this comment

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

Not needed here. This is already done when you call installer::install.
Remember to delete the asset_may_not_be_archive function.

}

pub fn finish_with_message(&self, message: &str) {
self.pb.finish_and_clear();
println!("{}", message);
}

pub fn println(&self, message: &str) {
Copy link
Owner

Choose a reason for hiding this comment

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

Rename to show_message

#[cfg(target_family = "unix")]
#[test_case("helloworld-unix", "helloworld", "helloworld-v2"; "executable")]
#[test_case("helloworld.deb", "helloworld", "helloworld-v2"; "deb")]
fn selected_asset_is_not_archive(selected_asset: &str, exec1: &str, exec2: &str) {
Copy link
Owner

Choose a reason for hiding this comment

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

Not needed since that check is removed. See comments in download_handler.rs

use assert_cmd::assert::OutputAssertExt;
use assert_cmd::prelude::CommandCargoExt;

use crate::assertions::assert_file_exists;

#[test]
fn destination_is_not_dir() {
Copy link
Owner

Choose a reason for hiding this comment

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

Remove this test or transform it in a unit test in download_handler.rs.

End to end tests are expensive to write and maintain. In this case, this one doesn't add much value.

This could be a unit test on download_handler.rs on the destination_may_not_dir function.


#[cfg(target_family = "windows")]
#[test_case("helloworld-many-executables-windows.zip", "random-script.exe", "helloworld-v2.exe"; "install 2 executables")]
fn installed_multiple_successfully(selected_asset: &str, exec1: &str, exec2: &str) {
Copy link
Owner

Choose a reason for hiding this comment

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

Could you move this test below the one for unix family?


#[cfg(target_family = "windows")]
#[test_case("helloworld.exe", "helloworld.exe", "helloworld-v2.exe"; "executable")]
fn selected_asset_is_not_archive(selected_asset: &str, exec1: &str, exec2: &str) {
Copy link
Owner

Choose a reason for hiding this comment

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

Not needed since that check is removed. See comments in download_handler.rs

return Err(HandlerError::new(message));
}

let message = format!("{}\n", Color::new("Installation completed!").green());
Copy link
Owner

Choose a reason for hiding this comment

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

Remove \n since it's not needed anymore

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

Successfully merging this pull request may close these issues.

3 participants