feat(cli): implement verbosity on mobile commands (#5044)

This commit is contained in:
Lucas Fernandes Nogueira 2022-08-25 16:06:00 -03:00 committed by GitHub
parent 927ccc465d
commit badad2b9a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 57 additions and 27 deletions

View File

@ -192,9 +192,9 @@ where
Commands::Init(options) => init::command(options)?,
Commands::Plugin(cli) => plugin::command(cli)?,
Commands::Signer(cli) => signer::command(cli)?,
Commands::Android(cli) => mobile::android::command(cli)?,
Commands::Android(c) => mobile::android::command(c, cli.verbose)?,
#[cfg(target_os = "macos")]
Commands::Ios(cli) => mobile::ios::command(cli)?,
Commands::Ios(c) => mobile::ios::command(c, cli.verbose)?,
}
Ok(())

View File

@ -83,12 +83,13 @@ enum Commands {
AndroidStudioScript(android_studio_script::Options),
}
pub fn command(cli: Cli) -> Result<()> {
pub fn command(cli: Cli, verbosity: usize) -> Result<()> {
let noise_level = super::verbosity_to_noise_level(verbosity);
match cli.command {
Commands::Init(options) => init_command(options, MobileTarget::Android)?,
Commands::Open => open::command()?,
Commands::Dev(options) => dev::command(options)?,
Commands::Build(options) => build::command(options)?,
Commands::Dev(options) => dev::command(options, noise_level)?,
Commands::Build(options) => build::command(options, noise_level)?,
Commands::AndroidStudioScript(options) => android_studio_script::command(options)?,
}

View File

@ -31,7 +31,7 @@ pub fn command(options: Options) -> Result<()> {
} else {
Profile::Debug
};
let noise_level = NoiseLevel::Polite;
let noise_level = NoiseLevel::FranklyQuitePedantic;
with_config(None, |root_conf, config, metadata| {
ensure_init(config.project_dir(), MobileTarget::Android)

View File

@ -67,7 +67,7 @@ impl From<Options> for crate::build::Options {
}
}
pub fn command(options: Options) -> Result<()> {
pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
delete_codegen_vars();
with_config(Some(Default::default()), |root_conf, config, _metadata| {
set_var("WRY_RUSTWEBVIEWCLIENT_CLASS_EXTENSION", "");
@ -80,7 +80,8 @@ pub fn command(options: Options) -> Result<()> {
init_dot_cargo(root_conf, Some(&env)).map_err(Error::InitDotCargo)?;
let open = options.open;
run_build(options, config, env).map_err(|e| Error::BuildFailed(format!("{:#}", e)))?;
run_build(options, config, env, noise_level)
.map_err(|e| Error::BuildFailed(format!("{:#}", e)))?;
if open {
open_and_wait(config);
@ -91,13 +92,17 @@ pub fn command(options: Options) -> Result<()> {
.map_err(Into::into)
}
fn run_build(mut options: Options, config: &AndroidConfig, env: Env) -> Result<()> {
fn run_build(
mut options: Options,
config: &AndroidConfig,
env: Env,
noise_level: NoiseLevel,
) -> Result<()> {
let profile = if options.debug {
Profile::Debug
} else {
Profile::Release
};
let noise_level = NoiseLevel::Polite;
if !(options.apk || options.aab) {
// if the user didn't specify the format to build, we'll do both

View File

@ -62,7 +62,7 @@ impl From<Options> for crate::dev::Options {
}
}
pub fn command(options: Options) -> Result<()> {
pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
delete_codegen_vars();
with_config(Some(Default::default()), |root_conf, config, metadata| {
set_var(
@ -72,7 +72,8 @@ pub fn command(options: Options) -> Result<()> {
set_var("WRY_RUSTWEBVIEW_CLASS_INIT", WEBVIEW_CLASS_INIT);
ensure_init(config.project_dir(), MobileTarget::Android)
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
run_dev(options, root_conf, config, metadata).map_err(|e| Error::DevFailed(format!("{:#}", e)))
run_dev(options, root_conf, config, metadata, noise_level)
.map_err(|e| Error::DevFailed(format!("{:#}", e)))
})
.map_err(Into::into)
}
@ -82,6 +83,7 @@ fn run_dev(
root_conf: &Config,
config: &AndroidConfig,
metadata: &AndroidMetadata,
noise_level: NoiseLevel,
) -> Result<()> {
let mut dev_options = options.clone().into();
let mut interface = crate::dev::setup(&mut dev_options)?;
@ -121,7 +123,7 @@ fn run_dev(
if open {
open_and_wait(config)
} else {
match run(options, root_conf, config, metadata) {
match run(options, root_conf, config, metadata, noise_level) {
Ok(c) => Ok(Box::new(c) as Box<dyn DevProcess>),
Err(Error::FailedToPromptForDevice(e)) => {
log::error!("{}", e);
@ -139,13 +141,13 @@ fn run(
root_conf: &Config,
config: &AndroidConfig,
metadata: &AndroidMetadata,
noise_level: NoiseLevel,
) -> Result<DevChild, Error> {
let profile = if options.debug {
Profile::Debug
} else {
Profile::Release
};
let noise_level = NoiseLevel::Polite;
let build_app_bundle = metadata.asset_packs().is_some();

View File

@ -91,12 +91,13 @@ enum Commands {
XcodeScript(xcode_script::Options),
}
pub fn command(cli: Cli) -> Result<()> {
pub fn command(cli: Cli, verbosity: usize) -> Result<()> {
let noise_level = super::verbosity_to_noise_level(verbosity);
match cli.command {
Commands::Init(options) => init_command(options, MobileTarget::Ios)?,
Commands::Open => open::command()?,
Commands::Dev(options) => dev::command(options)?,
Commands::Build(options) => build::command(options)?,
Commands::Dev(options) => dev::command(options, noise_level)?,
Commands::Build(options) => build::command(options, noise_level)?,
Commands::XcodeScript(options) => xcode_script::command(options)?,
}

View File

@ -63,7 +63,7 @@ impl From<Options> for crate::build::Options {
}
}
pub fn command(options: Options) -> Result<()> {
pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
with_config(Some(Default::default()), |root_conf, config, _metadata| {
ensure_init(config.project_dir(), MobileTarget::Ios)
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
@ -72,7 +72,8 @@ pub fn command(options: Options) -> Result<()> {
init_dot_cargo(root_conf, None).map_err(Error::InitDotCargo)?;
let open = options.open;
run_build(options, config, env).map_err(|e| Error::BuildFailed(format!("{:#}", e)))?;
run_build(options, config, env, noise_level)
.map_err(|e| Error::BuildFailed(format!("{:#}", e)))?;
if open {
open_and_wait(config);
@ -83,13 +84,17 @@ pub fn command(options: Options) -> Result<()> {
.map_err(Into::into)
}
fn run_build(mut options: Options, config: &AppleConfig, env: Env) -> Result<()> {
fn run_build(
mut options: Options,
config: &AppleConfig,
env: Env,
noise_level: NoiseLevel,
) -> Result<()> {
let profile = if options.debug {
Profile::Debug
} else {
Profile::Release
};
let noise_level = NoiseLevel::Polite;
let bundle_identifier = {
let tauri_config = get_tauri_config(None)?;

View File

@ -53,16 +53,22 @@ impl From<Options> for crate::dev::Options {
}
}
pub fn command(options: Options) -> Result<()> {
pub fn command(options: Options, noise_level: NoiseLevel) -> Result<()> {
with_config(Some(Default::default()), |root_conf, config, _metadata| {
ensure_init(config.project_dir(), MobileTarget::Ios)
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
run_dev(options, root_conf, config).map_err(|e| Error::DevFailed(format!("{:#}", e)))
run_dev(options, root_conf, config, noise_level)
.map_err(|e| Error::DevFailed(format!("{:#}", e)))
})
.map_err(Into::into)
}
fn run_dev(options: Options, root_conf: &Config, config: &AppleConfig) -> Result<()> {
fn run_dev(
options: Options,
root_conf: &Config,
config: &AppleConfig,
noise_level: NoiseLevel,
) -> Result<()> {
let mut dev_options = options.clone().into();
let mut interface = crate::dev::setup(&mut dev_options)?;
@ -101,7 +107,7 @@ fn run_dev(options: Options, root_conf: &Config, config: &AppleConfig) -> Result
if open {
open_and_wait(config)
} else {
match run(options, root_conf, config) {
match run(options, root_conf, config, noise_level) {
Ok(c) => Ok(Box::new(c) as Box<dyn DevProcess>),
Err(Error::FailedToPromptForDevice(e)) => {
log::error!("{}", e);
@ -118,13 +124,13 @@ fn run(
options: MobileOptions,
root_conf: &Config,
config: &AppleConfig,
noise_level: NoiseLevel,
) -> Result<DevChild, Error> {
let profile = if options.debug {
Profile::Debug
} else {
Profile::Release
};
let noise_level = NoiseLevel::Polite;
let env = env()?;
init_dot_cargo(root_conf, None).map_err(Error::InitDotCargo)?;

View File

@ -44,7 +44,7 @@ pub fn command(options: Options) -> Result<()> {
let profile = profile_from_configuration(&options.configuration);
let macos = macos_from_platform(&options.platform);
let noise_level = NoiseLevel::Polite;
let noise_level = NoiseLevel::FranklyQuitePedantic;
with_config(None, |root_conf, config, metadata| {
let env = env()?;

View File

@ -16,6 +16,7 @@ use cargo_mobile::{
bossy,
config::{app::Raw as RawAppConfig, metadata::Metadata, Config, Raw},
env::Error as EnvError,
opts::NoiseLevel,
};
use interprocess::local_socket::{LocalSocketListener, LocalSocketStream};
use serde::{Deserialize, Serialize};
@ -346,3 +347,12 @@ fn log_finished(outputs: Vec<PathBuf>, kind: &str) {
log::info!(action = "Finished"; "{} {}{} at:\n{}", outputs.len(), kind, if outputs.len() == 1 { "" } else { "s" }, printable_paths);
}
}
fn verbosity_to_noise_level(verbosity: usize) -> NoiseLevel {
match verbosity {
0 => NoiseLevel::Polite,
1 => NoiseLevel::LoudAndProud,
2.. => NoiseLevel::FranklyQuitePedantic,
_ => panic!(),
}
}