Skip to content

Commit 7e5e050

Browse files
committed
Add preferred flag
1 parent 36595cf commit 7e5e050

File tree

11 files changed

+75
-54
lines changed

11 files changed

+75
-54
lines changed

crossbundle/cli/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ path = "src/main.rs"
2020
[dependencies]
2121
crossbow = { path = "../../", version = "0.2.1", default-features = false, features = ["update-manifest"] }
2222
crossbundle-tools = { path = "../tools", version = "0.2.1", default-features = false }
23-
android-tools = { version = "0.2.10", optional = true }
23+
android-tools = { version = "0.2.11", optional = true }
2424
clap = { version = "3.2", features = ["derive"] }
2525
serde = { version = "1.0", features = ["derive"] }
2626

crossbundle/cli/src/commands/install/bundletool.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ pub struct BundletoolInstallCommand {
1111
/// Required. Version of download bundletool. For example:
1212
/// --version 1.8.2
1313
#[clap(long, short, default_value = "1.8.2")]
14-
version: String,
14+
pub version: String,
1515
/// Path to install bundletool. By default bundletool will be downloaded and saved in
1616
/// home directory
1717
#[clap(long, short)]
18-
path: Option<PathBuf>,
18+
pub path: Option<PathBuf>,
1919
/// Force install bundletool even if found.
2020
#[clap(long, short)]
21-
force: bool,
21+
pub force: bool,
2222
}
2323

2424
impl BundletoolInstallCommand {

crossbundle/cli/src/commands/install/command_line_tools.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use super::*;
2+
use android_tools::sdk_install_path;
23
use clap::Parser;
3-
use crossbundle_tools::{commands::android::*, types::AndroidSdk, types::Config};
4+
use crossbundle_tools::{commands::android::*, types::Config};
45
use std::path::{Path, PathBuf};
56

67
#[cfg(target_os = "windows")]
@@ -44,24 +45,22 @@ impl CommandLineToolsInstallCommand {
4445
)?;
4546
self.download_and_save_file(command_line_tools_download_url, &file_path)?;
4647

47-
let sdk = AndroidSdk::from_env()?;
48-
let sdk_path = sdk.sdk_path();
49-
5048
if let Some(path) = &self.install_path {
5149
config.status_message(
5250
"Extracting zip archive contents into",
5351
path.to_str().unwrap(),
5452
)?;
5553
extract_archive(&file_path, path)?;
5654
} else {
55+
let sdk_path = sdk_install_path()?;
5756
config.status_message(
5857
"Extracting zip archive contents into",
5958
&sdk_path.to_str().unwrap(),
6059
)?;
6160
extract_archive(&file_path, Path::new(&sdk_path))?;
6261
}
6362

64-
config.status("Deleting zip archive was left after installation")?;
63+
config.status("Deleting zip archive thaw was left after installation")?;
6564
remove(vec![file_path])?;
6665
Ok(())
6766
}
@@ -78,8 +77,9 @@ impl CommandLineToolsInstallCommand {
7877
download_url: PathBuf,
7978
file_path: &Path,
8079
) -> crate::error::Result<()> {
81-
for sdkmanager in std::fs::read_dir(file_path.parent().unwrap())? {
82-
let zip_path = sdkmanager?.path();
80+
remove(vec![file_path.to_path_buf()])?;
81+
for dir in std::fs::read_dir(file_path.parent().unwrap())? {
82+
let zip_path = dir?.path();
8383
if zip_path.ends_with(self.file_name()) {
8484
return Ok(());
8585
}

crossbundle/cli/src/commands/install/mod.rs

+42-20
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub mod command_line_tools;
55
#[cfg(feature = "android")]
66
pub mod sdkmanager;
77

8-
use crate::error::Result;
8+
use crate::error::*;
99
use clap::Parser;
1010
use crossbundle_tools::types::Config;
1111

@@ -16,7 +16,17 @@ use self::{
1616
};
1717

1818
#[derive(Parser, Clone, Debug)]
19-
pub enum InstallCommand {
19+
pub struct InstallCommand {
20+
/// This flag installs all necessary tools, sdk, and ndk.
21+
/// Also, if specified - has higher priority than subcommand.
22+
#[clap(long)]
23+
pub preferred: bool,
24+
#[clap(subcommand)]
25+
pub subcommand: Option<InstallCommandSubcommand>,
26+
}
27+
28+
#[derive(Parser, Clone, Debug)]
29+
pub enum InstallCommandSubcommand {
2030
/// Install bundletool. You can specify version of bundletool. By default, we have
2131
/// 1.8.2 bundletool version in usage
2232
#[cfg(feature = "android")]
@@ -28,40 +38,52 @@ pub enum InstallCommand {
2838
CommandLineTools(CommandLineToolsInstallCommand),
2939
/// Allows you to view, install, update, and uninstall packages for the Android SDK
3040
#[cfg(feature = "android")]
31-
SdkManager(SdkManagerInstallCommand),
41+
Sdkmanager(SdkManagerInstallCommand),
3242
}
3343

3444
impl InstallCommand {
3545
pub fn handle_command(&self, config: &Config) -> Result<()> {
36-
#[cfg(feature = "android")]
37-
match self {
46+
if self.preferred {
47+
config.status("Installing all preferred tools")?;
3848
#[cfg(feature = "android")]
39-
InstallCommand::Bundletool(cmd) => cmd.install(config)?,
49+
CommandLineToolsInstallCommand::default().install(config)?;
4050
#[cfg(feature = "android")]
41-
InstallCommand::CommandLineTools(cmd) => cmd.install(config)?,
51+
BundletoolInstallCommand::default().install(config)?;
4252
#[cfg(feature = "android")]
43-
InstallCommand::SdkManager(cmd) => cmd.run(config)?,
53+
SdkManagerInstallCommand {
54+
preferred_tools: true,
55+
..Default::default()
56+
}
57+
.run(config)?;
58+
return Ok(());
59+
}
60+
if let Some(subcommand) = &self.subcommand {
61+
#[cfg(feature = "android")]
62+
match subcommand {
63+
#[cfg(feature = "android")]
64+
InstallCommandSubcommand::Bundletool(cmd) => cmd.install(config)?,
65+
#[cfg(feature = "android")]
66+
InstallCommandSubcommand::CommandLineTools(cmd) => cmd.install(config)?,
67+
#[cfg(feature = "android")]
68+
InstallCommandSubcommand::Sdkmanager(cmd) => cmd.run(config)?,
69+
}
4470
}
4571
Ok(())
4672
}
4773
}
4874

4975
/// Download from url and saves it in specified file
50-
pub fn download_to_file(
51-
download_url: &str,
52-
file_path: &std::path::Path,
53-
) -> crate::error::Result<()> {
76+
pub fn download_to_file(download_url: &str, file_path: &std::path::Path) -> Result<()> {
5477
let response = ureq::get(download_url)
5578
.call()
56-
.map_err(crate::error::Error::DownloadFailed)?;
57-
let mut out = std::fs::File::create(file_path).map_err(|cause| {
58-
crate::error::Error::JarFileCreationFailed {
79+
.map_err(Error::DownloadFailed)?;
80+
let mut out =
81+
std::fs::File::create(file_path).map_err(|cause| Error::JarFileCreationFailed {
5982
path: file_path.to_path_buf(),
6083
cause,
61-
}
62-
})?;
84+
})?;
6385
std::io::copy(&mut response.into_reader(), &mut out).map_err(|cause| {
64-
crate::error::Error::CopyToFileFailed {
86+
Error::CopyToFileFailed {
6587
path: file_path.to_path_buf(),
6688
cause,
6789
}
@@ -70,9 +92,9 @@ pub fn download_to_file(
7092
}
7193

7294
/// Using default file path related on $HOME path for all installed commands
73-
pub fn default_file_path(file_name: String) -> crate::error::Result<std::path::PathBuf> {
95+
pub fn default_file_path(file_name: String) -> Result<std::path::PathBuf> {
7496
let default_file_path = dirs::home_dir()
75-
.ok_or(crate::error::Error::HomeDirNotFound)?
97+
.ok_or(Error::HomeDirNotFound)?
7698
.join(file_name);
7799
Ok(default_file_path)
78100
}

crossbundle/cli/src/commands/install/sdkmanager.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -9,49 +9,49 @@ pub struct SdkManagerInstallCommand {
99
/// Install all preferred tools for correct crossbundle work. It will install
1010
/// build-tools;31.0.0, ndk;23.1.7779620 and platforms;android-31
1111
#[clap(long, short)]
12-
preferred_tools: bool,
12+
pub preferred_tools: bool,
1313
/// List installed and available packages. Use the channel option to include a package
1414
/// from a channel up to and including channel_id. For example, specify the canary
1515
/// channel to list packages from all channels
1616
#[clap(long, short)]
17-
list: bool,
17+
pub list: bool,
1818
/// Install package. To see all available packages use --list.
19-
/// Example: crossbundle install sdk-manager "ndk;23.1.7779620"
19+
/// Example: crossbundle install sdkmanager "ndk;23.1.7779620"
2020
#[clap(long, short, multiple_values = true)]
21-
install: Option<Vec<String>>,
21+
pub install: Option<Vec<String>>,
2222
/// Android package that needs to be uninstalled
2323
#[clap(long)]
24-
uninstall: Option<String>,
24+
pub uninstall: Option<String>,
2525
/// Update all installed packages
2626
#[clap(long)]
27-
update: bool,
27+
pub update: bool,
2828
/// Use the specified SDK path instead of the SDK containing this tool
2929
#[clap(long, short)]
30-
sdk_root: Option<std::path::PathBuf>,
30+
pub sdk_root: Option<std::path::PathBuf>,
3131
/// Include packages in channels up to and including channel_id. Available channels
3232
/// are: 0 (Stable), 1 (Beta), 2 (Dev), and 3 (Canary)
3333
#[clap(long, short)]
34-
channel: Option<u32>,
34+
pub channel: Option<u32>,
3535
/// Include obsolete packages in the package listing or package updates. For use with
3636
/// --list and --update only
3737
#[clap(long)]
38-
include_obsolete: bool,
38+
pub include_obsolete: bool,
3939
/// Force all connections to use HTTP rather than HTTPS
4040
#[clap(long, short)]
41-
no_https: bool,
41+
pub no_https: bool,
4242
/// Verbose output mode. Errors, warnings and informational messages are printed
4343
#[clap(long, short)]
44-
verbose: bool,
44+
pub verbose: bool,
4545
/// Connect via a proxy of the given type: either http for high level protocols such
4646
/// as HTTP or FTP, or socks for a SOCKS (V4 or V5) proxy
4747
#[clap(long)]
48-
proxy: Option<String>,
48+
pub proxy: Option<String>,
4949
/// IP or DNS address of the proxy to use
5050
#[clap(long)]
51-
proxy_host: Option<String>,
51+
pub proxy_host: Option<String>,
5252
/// Proxy port number to connect to
5353
#[clap(long)]
54-
proxy_port: Option<String>,
54+
pub proxy_port: Option<String>,
5555
}
5656

5757
impl SdkManagerInstallCommand {
@@ -71,7 +71,7 @@ impl SdkManagerInstallCommand {
7171
}
7272

7373
/// Install package. To see all available packages use --list.
74-
/// Example: crossbundle install sdk-manager "ndk;23.1.7779620"
74+
/// Example: crossbundle install sdkmanager "ndk;23.1.7779620"
7575
pub fn install(&mut self, install: Vec<String>) -> &mut Self {
7676
self.install = Some(install);
7777
self

crossbundle/cli/src/commands/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ pub enum Commands {
2020
/// with `crossbundle`
2121
New(new::NewCommand),
2222
/// Installs bundletool and Android Studio's sdkmanager
23-
#[clap(subcommand)]
2423
Install(install::InstallCommand),
2524
}
2625

crossbundle/tools/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ apple-bundle = { version = "0.1.4", optional = true }
1616
simctl = { version = "0.1.1", package = "creator-simctl", optional = true }
1717
# Android crates
1818
android-manifest = { version = "0.1.10", optional = true }
19-
android-tools = { version = "0.2.10", optional = true }
19+
android-tools = { version = "0.2.11", optional = true }
2020

2121
serde = { version = "1.0", features = ["derive"] }
2222
serde_plain = "1.0"

docs/src/crossbundle/command-install.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ The [sdkmanager](https://developer.android.com/studio/command-line/sdkmanager) i
3030
To install packages use the command below. We prefer to use --preferred-tools flag to install minimal required tools needed for crossbundle correct working. This command will setup build-tools, android-ndk and android platforms:
3131

3232
```sh
33-
crossbundle install sdk-manager --preferred-tools
33+
crossbundle install sdkmanager --preferred-tools
3434
```
3535

3636
Also you can install packages manually. To see all available tools use the -h flag. List installed and available packages:
3737

3838
```sh
39-
crossbundle install sdk-manager --list
39+
crossbundle install sdkmanager --list
4040
```
4141

4242
And then enter the command.
4343

4444
```sh
45-
crossbundle install sdk-manager --install "build-tools;31.0.0" "ndk;23.1.7779620" "platforms;android-31"
45+
crossbundle install sdkmanager --install "build-tools;31.0.0" "ndk;23.1.7779620" "platforms;android-31"
4646
```
4747

4848
The command will install packages into `$HOME\AppData\Local\Android\Sdk\` for Windows, `$HOME/Library/Android/sdk/` for macOS, and `$HOME/Android/sdk/` for Linux.

docs/src/install/android-linux.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ To prepare to run and test your Crossbow app on the Android emulator, follow the
6969

7070
```sh
7171
# Run following command to install System Image for Android SDK 31
72-
crossbundle install sdk-manager --install "system-images;android-31;google_apis;x86_64"
72+
crossbundle install sdkmanager --install "system-images;android-31;google_apis;x86_64"
7373
# Run this command to create a new emulator
7474
avdmanager create avd -n Phone -k "system-images;android-31;google_apis;x86_64"
7575
# And finally run this command to start the emulator

docs/src/install/android-macos.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ To prepare to run and test your Crossbow app on the Android emulator, follow the
6767

6868
```sh
6969
# Run following command to install System Image for Android SDK 31
70-
crossbundle install sdk-manager --install "system-images;android-31;google_apis;x86_64"
70+
crossbundle install sdkmanager --install "system-images;android-31;google_apis;x86_64"
7171
# Run this command to create a new emulator
7272
avdmanager create avd -n Phone -k "system-images;android-31;google_apis;x86_64"
7373
# And finally run this command to start the emulator

docs/src/install/android-windows.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ To prepare to run and test your Crossbow app on the Android emulator, follow the
8080

8181
```sh
8282
# Run following command to install System Image for Android SDK 31
83-
crossbundle install sdk-manager --install "system-images;android-31;google_apis;x86_64"
83+
crossbundle install sdkmanager --install "system-images;android-31;google_apis;x86_64"
8484
# Run this command to create a new emulator
8585
avdmanager create avd -n Phone -k "system-images;android-31;google_apis;x86_64"
8686
# And finally run this command to start the emulator

0 commit comments

Comments
 (0)