mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 13:37:09 +00:00
feat(cli): persist verbosity for the IDE scripts (#5047)
This commit is contained in:
parent
80a301ea63
commit
69aaff5507
@ -13,6 +13,7 @@ use cargo_mobile::{
|
||||
config::Config,
|
||||
device::PromptError,
|
||||
env::Error as EnvError,
|
||||
opts::NoiseLevel,
|
||||
os,
|
||||
util::prompt,
|
||||
};
|
||||
@ -84,7 +85,7 @@ enum Commands {
|
||||
}
|
||||
|
||||
pub fn command(cli: Cli, verbosity: usize) -> Result<()> {
|
||||
let noise_level = super::verbosity_to_noise_level(verbosity);
|
||||
let noise_level = NoiseLevel::from_occurrences(verbosity as u64);
|
||||
match cli.command {
|
||||
Commands::Init(options) => init_command(options, MobileTarget::Android)?,
|
||||
Commands::Open => open::command()?,
|
||||
@ -98,19 +99,19 @@ pub fn command(cli: Cli, verbosity: usize) -> Result<()> {
|
||||
|
||||
fn with_config<T>(
|
||||
cli_options: Option<CliOptions>,
|
||||
f: impl FnOnce(&Config, &AndroidConfig, &AndroidMetadata) -> Result<T, Error>,
|
||||
f: impl FnOnce(&Config, &AndroidConfig, &AndroidMetadata, CliOptions) -> Result<T, Error>,
|
||||
) -> Result<T, Error> {
|
||||
let (config, metadata) = {
|
||||
let (config, metadata, cli_options) = {
|
||||
let tauri_config =
|
||||
get_tauri_config(None).map_err(|e| Error::InvalidTauriConfig(e.to_string()))?;
|
||||
let tauri_config_guard = tauri_config.lock().unwrap();
|
||||
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
|
||||
get_config(
|
||||
tauri_config_,
|
||||
cli_options.unwrap_or_else(|| read_options(tauri_config_, MobileTarget::Android)),
|
||||
)
|
||||
let cli_options =
|
||||
cli_options.unwrap_or_else(|| read_options(tauri_config_, MobileTarget::Android));
|
||||
let (config, metadata) = get_config(tauri_config_, &cli_options);
|
||||
(config, metadata, cli_options)
|
||||
};
|
||||
f(&config, config.android(), metadata.android())
|
||||
f(&config, config.android(), metadata.android(), cli_options)
|
||||
}
|
||||
|
||||
fn env() -> Result<Env, Error> {
|
||||
|
||||
@ -4,7 +4,7 @@ use clap::Parser;
|
||||
|
||||
use cargo_mobile::{
|
||||
android::target::Target,
|
||||
opts::{NoiseLevel, Profile},
|
||||
opts::Profile,
|
||||
target::{call_for_targets_with_fallback, TargetTrait},
|
||||
};
|
||||
|
||||
@ -31,9 +31,8 @@ pub fn command(options: Options) -> Result<()> {
|
||||
} else {
|
||||
Profile::Debug
|
||||
};
|
||||
let noise_level = NoiseLevel::LoudAndProud;
|
||||
|
||||
with_config(None, |root_conf, config, metadata| {
|
||||
with_config(None, |root_conf, config, metadata, cli_options| {
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
|
||||
@ -46,7 +45,14 @@ pub fn command(options: Options) -> Result<()> {
|
||||
&env,
|
||||
|target: &Target| {
|
||||
target
|
||||
.build(config, metadata, &env, noise_level, true, profile)
|
||||
.build(
|
||||
config,
|
||||
metadata,
|
||||
&env,
|
||||
cli_options.noise_level,
|
||||
true,
|
||||
profile,
|
||||
)
|
||||
.map_err(Error::AndroidStudioScriptFailed)
|
||||
},
|
||||
)
|
||||
|
||||
@ -69,26 +69,29 @@ impl From<Options> for crate::build::Options {
|
||||
|
||||
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", "");
|
||||
set_var("WRY_RUSTWEBVIEW_CLASS_INIT", "");
|
||||
with_config(
|
||||
Some(Default::default()),
|
||||
|root_conf, config, _metadata, _cli_options| {
|
||||
set_var("WRY_RUSTWEBVIEWCLIENT_CLASS_EXTENSION", "");
|
||||
set_var("WRY_RUSTWEBVIEW_CLASS_INIT", "");
|
||||
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
|
||||
let env = env()?;
|
||||
init_dot_cargo(root_conf, Some(&env)).map_err(Error::InitDotCargo)?;
|
||||
let env = env()?;
|
||||
init_dot_cargo(root_conf, Some(&env)).map_err(Error::InitDotCargo)?;
|
||||
|
||||
let open = options.open;
|
||||
run_build(options, config, env, noise_level)
|
||||
.map_err(|e| Error::BuildFailed(format!("{:#}", e)))?;
|
||||
let open = options.open;
|
||||
run_build(options, config, env, noise_level)
|
||||
.map_err(|e| Error::BuildFailed(format!("{:#}", e)))?;
|
||||
|
||||
if open {
|
||||
open_and_wait(config);
|
||||
}
|
||||
if open {
|
||||
open_and_wait(config);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -131,6 +134,7 @@ fn run_build(
|
||||
let cli_options = CliOptions {
|
||||
features: build_options.features.clone(),
|
||||
args: build_options.args.clone(),
|
||||
noise_level,
|
||||
vars: Default::default(),
|
||||
};
|
||||
write_options(cli_options, &bundle_identifier, MobileTarget::Android)?;
|
||||
|
||||
@ -64,17 +64,20 @@ impl From<Options> for crate::dev::Options {
|
||||
|
||||
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",
|
||||
WEBVIEW_CLIENT_CLASS_EXTENSION,
|
||||
);
|
||||
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, noise_level)
|
||||
.map_err(|e| Error::DevFailed(format!("{:#}", e)))
|
||||
})
|
||||
with_config(
|
||||
Some(Default::default()),
|
||||
|root_conf, config, metadata, _cli_options| {
|
||||
set_var(
|
||||
"WRY_RUSTWEBVIEWCLIENT_CLASS_EXTENSION",
|
||||
WEBVIEW_CLIENT_CLASS_EXTENSION,
|
||||
);
|
||||
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, noise_level)
|
||||
.map_err(|e| Error::DevFailed(format!("{:#}", e)))
|
||||
},
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -116,6 +119,7 @@ fn run_dev(
|
||||
let cli_options = CliOptions {
|
||||
features: options.features.clone(),
|
||||
args: options.args.clone(),
|
||||
noise_level,
|
||||
vars: Default::default(),
|
||||
};
|
||||
write_options(cli_options, &bundle_identifier, MobileTarget::Android)?;
|
||||
|
||||
@ -3,10 +3,13 @@ use crate::Result;
|
||||
use cargo_mobile::os;
|
||||
|
||||
pub fn command() -> Result<()> {
|
||||
with_config(Some(Default::default()), |_, config, _metadata| {
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
os::open_file_with("Android Studio", config.project_dir()).map_err(Error::OpenFailed)
|
||||
})
|
||||
with_config(
|
||||
Some(Default::default()),
|
||||
|_root_conf, config, _metadata, _cli_options| {
|
||||
ensure_init(config.project_dir(), MobileTarget::Android)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
os::open_file_with("Android Studio", config.project_dir()).map_err(Error::OpenFailed)
|
||||
},
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -107,7 +107,7 @@ pub fn exec(
|
||||
let tauri_config_guard = tauri_config.lock().unwrap();
|
||||
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
|
||||
|
||||
let (config, metadata) = get_config(tauri_config_, Default::default());
|
||||
let (config, metadata) = get_config(tauri_config_, &Default::default());
|
||||
|
||||
let asset_dir = config.app().asset_dir();
|
||||
if !asset_dir.is_dir() {
|
||||
|
||||
@ -12,6 +12,7 @@ use cargo_mobile::{
|
||||
config::Config,
|
||||
device::PromptError,
|
||||
env::{Env, Error as EnvError},
|
||||
opts::NoiseLevel,
|
||||
os, util,
|
||||
util::prompt,
|
||||
};
|
||||
@ -92,7 +93,7 @@ enum Commands {
|
||||
}
|
||||
|
||||
pub fn command(cli: Cli, verbosity: usize) -> Result<()> {
|
||||
let noise_level = super::verbosity_to_noise_level(verbosity);
|
||||
let noise_level = NoiseLevel::from_occurrences(verbosity as u64);
|
||||
match cli.command {
|
||||
Commands::Init(options) => init_command(options, MobileTarget::Ios)?,
|
||||
Commands::Open => open::command()?,
|
||||
@ -106,19 +107,18 @@ pub fn command(cli: Cli, verbosity: usize) -> Result<()> {
|
||||
|
||||
fn with_config<T>(
|
||||
cli_options: Option<CliOptions>,
|
||||
f: impl FnOnce(&Config, &AppleConfig, &AppleMetadata) -> Result<T, Error>,
|
||||
f: impl FnOnce(&Config, &AppleConfig, &AppleMetadata, CliOptions) -> Result<T, Error>,
|
||||
) -> Result<T, Error> {
|
||||
let (config, metadata) = {
|
||||
let (config, metadata, cli_options) = {
|
||||
let tauri_config =
|
||||
get_tauri_config(None).map_err(|e| Error::InvalidTauriConfig(e.to_string()))?;
|
||||
let tauri_config_guard = tauri_config.lock().unwrap();
|
||||
let tauri_config_ = tauri_config_guard.as_ref().unwrap();
|
||||
get_config(
|
||||
tauri_config_,
|
||||
cli_options.unwrap_or_else(|| read_options(tauri_config_, MobileTarget::Ios)),
|
||||
)
|
||||
let cli_options = cli_options.unwrap_or_else(|| read_options(tauri_config_, MobileTarget::Ios));
|
||||
let (config, metadata) = get_config(tauri_config_, &cli_options);
|
||||
(config, metadata, cli_options)
|
||||
};
|
||||
f(&config, config.apple(), metadata.apple())
|
||||
f(&config, config.apple(), metadata.apple(), cli_options)
|
||||
}
|
||||
|
||||
fn device_prompt<'a>(env: &'_ Env) -> Result<Device<'a>, PromptError<ios_deploy::DeviceListError>> {
|
||||
|
||||
@ -64,23 +64,26 @@ impl From<Options> for crate::build::Options {
|
||||
}
|
||||
|
||||
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()))?;
|
||||
with_config(
|
||||
Some(Default::default()),
|
||||
|root_conf, config, _metadata, _cli_options| {
|
||||
ensure_init(config.project_dir(), MobileTarget::Ios)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
|
||||
let env = env()?;
|
||||
init_dot_cargo(root_conf, None).map_err(Error::InitDotCargo)?;
|
||||
let env = env()?;
|
||||
init_dot_cargo(root_conf, None).map_err(Error::InitDotCargo)?;
|
||||
|
||||
let open = options.open;
|
||||
run_build(options, config, env, noise_level)
|
||||
.map_err(|e| Error::BuildFailed(format!("{:#}", e)))?;
|
||||
let open = options.open;
|
||||
run_build(options, config, env, noise_level)
|
||||
.map_err(|e| Error::BuildFailed(format!("{:#}", e)))?;
|
||||
|
||||
if open {
|
||||
open_and_wait(config);
|
||||
}
|
||||
if open {
|
||||
open_and_wait(config);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
Ok(())
|
||||
},
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -117,6 +120,7 @@ fn run_build(
|
||||
let cli_options = CliOptions {
|
||||
features: build_options.features.clone(),
|
||||
args: build_options.args.clone(),
|
||||
noise_level,
|
||||
vars: Default::default(),
|
||||
};
|
||||
write_options(cli_options, &bundle_identifier, MobileTarget::Ios)?;
|
||||
|
||||
@ -54,12 +54,15 @@ impl From<Options> for crate::dev::Options {
|
||||
}
|
||||
|
||||
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, noise_level)
|
||||
.map_err(|e| Error::DevFailed(format!("{:#}", e)))
|
||||
})
|
||||
with_config(
|
||||
Some(Default::default()),
|
||||
|root_conf, config, _metadata, _cli_options| {
|
||||
ensure_init(config.project_dir(), MobileTarget::Ios)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
run_dev(options, root_conf, config, noise_level)
|
||||
.map_err(|e| Error::DevFailed(format!("{:#}", e)))
|
||||
},
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -101,6 +104,7 @@ fn run_dev(
|
||||
let cli_options = CliOptions {
|
||||
features: options.features.clone(),
|
||||
args: options.args.clone(),
|
||||
noise_level,
|
||||
vars: Default::default(),
|
||||
};
|
||||
write_options(cli_options, &bundle_identifier, MobileTarget::Ios)?;
|
||||
|
||||
@ -3,10 +3,13 @@ use crate::Result;
|
||||
use cargo_mobile::os;
|
||||
|
||||
pub fn command() -> Result<()> {
|
||||
with_config(Some(Default::default()), |_, config, _metadata| {
|
||||
ensure_init(config.project_dir(), MobileTarget::Ios)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
os::open_file_with("Xcode", config.project_dir()).map_err(Error::OpenFailed)
|
||||
})
|
||||
with_config(
|
||||
Some(Default::default()),
|
||||
|_root_conf, config, _metadata, _cli_options| {
|
||||
ensure_init(config.project_dir(), MobileTarget::Ios)
|
||||
.map_err(|e| Error::ProjectNotInitialized(e.to_string()))?;
|
||||
os::open_file_with("Xcode", config.project_dir()).map_err(Error::OpenFailed)
|
||||
},
|
||||
)
|
||||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
@ -2,11 +2,7 @@ use super::{env, init_dot_cargo, with_config, Error};
|
||||
use crate::Result;
|
||||
use clap::Parser;
|
||||
|
||||
use cargo_mobile::{
|
||||
apple::target::Target,
|
||||
opts::{NoiseLevel, Profile},
|
||||
util,
|
||||
};
|
||||
use cargo_mobile::{apple::target::Target, opts::Profile, util};
|
||||
|
||||
use std::{collections::HashMap, ffi::OsStr, path::PathBuf};
|
||||
|
||||
@ -44,9 +40,8 @@ pub fn command(options: Options) -> Result<()> {
|
||||
|
||||
let profile = profile_from_configuration(&options.configuration);
|
||||
let macos = macos_from_platform(&options.platform);
|
||||
let noise_level = NoiseLevel::LoudAndProud;
|
||||
|
||||
with_config(None, |root_conf, config, metadata| {
|
||||
with_config(None, |root_conf, config, metadata, cli_options| {
|
||||
let env = env()?;
|
||||
init_dot_cargo(root_conf, None).map_err(Error::InitDotCargo)?;
|
||||
// The `PATH` env var Xcode gives us is missing any additions
|
||||
@ -127,7 +122,7 @@ pub fn command(options: Options) -> Result<()> {
|
||||
.compile_lib(
|
||||
config,
|
||||
metadata,
|
||||
noise_level,
|
||||
cli_options.noise_level,
|
||||
true,
|
||||
profile,
|
||||
&env,
|
||||
|
||||
@ -108,6 +108,7 @@ impl Target {
|
||||
pub struct CliOptions {
|
||||
pub features: Option<Vec<String>>,
|
||||
pub args: Vec<String>,
|
||||
pub noise_level: NoiseLevel,
|
||||
pub vars: HashMap<String, OsString>,
|
||||
}
|
||||
|
||||
@ -189,7 +190,7 @@ fn read_options(config: &TauriConfig, target: Target) -> CliOptions {
|
||||
options
|
||||
}
|
||||
|
||||
fn get_config(config: &TauriConfig, cli_options: CliOptions) -> (Config, Metadata) {
|
||||
fn get_config(config: &TauriConfig, cli_options: &CliOptions) -> (Config, Metadata) {
|
||||
let mut s = config.tauri.bundle.identifier.rsplit('.');
|
||||
let app_name = s.next().unwrap_or("app").to_string();
|
||||
let mut domain = String::new();
|
||||
@ -226,7 +227,7 @@ fn get_config(config: &TauriConfig, cli_options: CliOptions) -> (Config, Metadat
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
let ios_options = cli_options.clone();
|
||||
let android_options = cli_options;
|
||||
let android_options = cli_options.clone();
|
||||
|
||||
let raw = Raw {
|
||||
app: RawAppConfig {
|
||||
@ -347,12 +348,3 @@ 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!(),
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user