mirror of
https://github.com/tauri-apps/tauri.git
synced 2024-11-28 20:48:52 +03:00
chore(deps) Update Rust crate clap to v3.0.0-rc.0 (#3046)
Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
parent
a3537078dd
commit
639fcad307
@ -100,6 +100,8 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
#root::PackageInfo {
|
||||
name: #package_name,
|
||||
version: #package_version,
|
||||
authors: env!("CARGO_PKG_AUTHORS"),
|
||||
description: env!("CARGO_PKG_DESCRIPTION"),
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -119,7 +119,7 @@ impl EmbeddedAssets {
|
||||
Ok(Self(
|
||||
paths
|
||||
.iter()
|
||||
.map(|path| {
|
||||
.flat_map(|path| {
|
||||
let is_file = path.is_file();
|
||||
WalkDir::new(&path)
|
||||
.follow_links(true)
|
||||
@ -150,7 +150,6 @@ impl EmbeddedAssets {
|
||||
.collect::<Result<Vec<Asset>, _>>()
|
||||
})
|
||||
.flatten()
|
||||
.flatten()
|
||||
.collect::<_>(),
|
||||
))
|
||||
}
|
||||
|
@ -17,6 +17,10 @@ pub struct PackageInfo {
|
||||
pub name: String,
|
||||
/// App version
|
||||
pub version: String,
|
||||
/// The crate authors.
|
||||
pub authors: &'static str,
|
||||
/// The crate description.
|
||||
pub description: &'static str,
|
||||
}
|
||||
|
||||
impl PackageInfo {
|
||||
|
@ -59,7 +59,7 @@ bincode = "1.3"
|
||||
dirs-next = "2.0"
|
||||
percent-encoding = "2.1"
|
||||
base64 = { version = "0.13", optional = true }
|
||||
clap = { version = "=3.0.0-beta.5", optional = true }
|
||||
clap = { version = "=3.0.0-rc.0", optional = true }
|
||||
notify-rust = { version = "4.5", optional = true }
|
||||
reqwest = { version = "0.11", features = [ "json", "multipart" ], optional = true }
|
||||
bytes = { version = "1", features = [ "serde" ], optional = true }
|
||||
|
@ -4,11 +4,12 @@
|
||||
|
||||
//! Types and functions related to CLI arguments.
|
||||
|
||||
use crate::utils::config::{CliArg, CliConfig};
|
||||
|
||||
use clap::{
|
||||
crate_authors, crate_description, crate_name, crate_version, App, Arg, ArgMatches, ErrorKind,
|
||||
use crate::{
|
||||
utils::config::{CliArg, CliConfig},
|
||||
PackageInfo,
|
||||
};
|
||||
|
||||
use clap::{App, Arg, ArgMatches, ErrorKind};
|
||||
use serde::Serialize;
|
||||
use serde_json::Value;
|
||||
use std::collections::HashMap;
|
||||
@ -63,12 +64,12 @@ impl Matches {
|
||||
}
|
||||
|
||||
/// Gets the argument matches of the CLI definition.
|
||||
pub fn get_matches(cli: &CliConfig) -> crate::api::Result<Matches> {
|
||||
pub fn get_matches(cli: &CliConfig, package_info: &PackageInfo) -> crate::api::Result<Matches> {
|
||||
let about = cli
|
||||
.description()
|
||||
.unwrap_or(&crate_description!().to_string())
|
||||
.unwrap_or(&package_info.description.to_string())
|
||||
.to_string();
|
||||
let app = get_app(crate_name!(), Some(&about), cli);
|
||||
let app = get_app(package_info, &package_info.name, Some(&about), cli);
|
||||
match app.try_get_matches() {
|
||||
Ok(matches) => Ok(get_matches_internal(cli, &matches)),
|
||||
Err(e) => match e.kind {
|
||||
@ -142,10 +143,15 @@ fn map_matches(config: &CliConfig, matches: &ArgMatches, cli_matches: &mut Match
|
||||
}
|
||||
}
|
||||
|
||||
fn get_app<'a>(name: &str, about: Option<&'a String>, config: &'a CliConfig) -> App<'a> {
|
||||
let mut app = App::new(name)
|
||||
.author(crate_authors!())
|
||||
.version(crate_version!());
|
||||
fn get_app<'a>(
|
||||
package_info: &'a PackageInfo,
|
||||
command_name: &'a str,
|
||||
about: Option<&'a String>,
|
||||
config: &'a CliConfig,
|
||||
) -> App<'a> {
|
||||
let mut app = App::new(command_name)
|
||||
.author(package_info.authors)
|
||||
.version(&*package_info.version);
|
||||
|
||||
if let Some(about) = about {
|
||||
app = app.about(&**about);
|
||||
@ -169,7 +175,12 @@ fn get_app<'a>(name: &str, about: Option<&'a String>, config: &'a CliConfig) ->
|
||||
|
||||
if let Some(subcommands) = config.subcommands() {
|
||||
for (subcommand_name, subcommand) in subcommands {
|
||||
let clap_subcommand = get_app(subcommand_name, subcommand.description(), subcommand);
|
||||
let clap_subcommand = get_app(
|
||||
package_info,
|
||||
subcommand_name,
|
||||
subcommand.description(),
|
||||
subcommand,
|
||||
);
|
||||
app = app.subcommand(clap_subcommand);
|
||||
}
|
||||
}
|
||||
@ -187,8 +198,8 @@ fn get_arg<'a>(arg_name: &'a str, arg: &'a CliArg) -> Arg<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
clap_arg = bind_string_arg!(arg, clap_arg, description, about);
|
||||
clap_arg = bind_string_arg!(arg, clap_arg, long_description, long_about);
|
||||
clap_arg = bind_string_arg!(arg, clap_arg, description, help);
|
||||
clap_arg = bind_string_arg!(arg, clap_arg, long_description, long_help);
|
||||
clap_arg = bind_value_arg!(arg, clap_arg, takes_value);
|
||||
if let Some(value) = arg.multiple {
|
||||
clap_arg = clap_arg.multiple_values(value);
|
||||
|
@ -80,6 +80,8 @@ pub enum BaseDirectory {
|
||||
/// &PackageInfo {
|
||||
/// name: "app".into(),
|
||||
/// version: "1.0.0".into(),
|
||||
/// authors: "tauri",
|
||||
/// description: "a tauri test",
|
||||
/// },
|
||||
/// "path/to/something",
|
||||
/// Some(BaseDirectory::Config)
|
||||
|
@ -120,7 +120,7 @@ impl Module {
|
||||
if let Some(cli_config) = config.tauri.cli.clone() {
|
||||
resolver.respond_async(async move {
|
||||
cmd
|
||||
.run(&cli_config)
|
||||
.run(&cli_config, &package_info)
|
||||
.and_then(|r| r.json)
|
||||
.map_err(InvokeError::from)
|
||||
})
|
||||
|
@ -3,7 +3,7 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
use super::InvokeResponse;
|
||||
use crate::utils::config::CliConfig;
|
||||
use crate::{utils::config::CliConfig, PackageInfo};
|
||||
use serde::Deserialize;
|
||||
|
||||
/// The API descriptor.
|
||||
@ -16,12 +16,16 @@ pub enum Cmd {
|
||||
|
||||
impl Cmd {
|
||||
#[allow(unused_variables)]
|
||||
pub fn run(self, cli_config: &CliConfig) -> crate::Result<InvokeResponse> {
|
||||
pub fn run(
|
||||
self,
|
||||
cli_config: &CliConfig,
|
||||
package_info: &PackageInfo,
|
||||
) -> crate::Result<InvokeResponse> {
|
||||
match self {
|
||||
#[allow(unused_variables)]
|
||||
Self::CliMatches => {
|
||||
#[cfg(cli)]
|
||||
return crate::api::cli::get_matches(cli_config)
|
||||
return crate::api::cli::get_matches(cli_config, package_info)
|
||||
.map_err(Into::into)
|
||||
.map(Into::into);
|
||||
#[cfg(not(cli))]
|
||||
|
@ -155,7 +155,7 @@ pub struct Context<A: Assets> {
|
||||
pub(crate) assets: Arc<A>,
|
||||
pub(crate) default_window_icon: Option<Vec<u8>>,
|
||||
pub(crate) system_tray_icon: Option<Icon>,
|
||||
pub(crate) package_info: crate::PackageInfo,
|
||||
pub(crate) package_info: PackageInfo,
|
||||
pub(crate) _info_plist: (),
|
||||
}
|
||||
|
||||
@ -221,13 +221,13 @@ impl<A: Assets> Context<A> {
|
||||
|
||||
/// Package information.
|
||||
#[inline(always)]
|
||||
pub fn package_info(&self) -> &crate::PackageInfo {
|
||||
pub fn package_info(&self) -> &PackageInfo {
|
||||
&self.package_info
|
||||
}
|
||||
|
||||
/// A mutable reference to the package information.
|
||||
#[inline(always)]
|
||||
pub fn package_info_mut(&mut self) -> &mut crate::PackageInfo {
|
||||
pub fn package_info_mut(&mut self) -> &mut PackageInfo {
|
||||
&mut self.package_info
|
||||
}
|
||||
|
||||
@ -238,7 +238,7 @@ impl<A: Assets> Context<A> {
|
||||
assets: Arc<A>,
|
||||
default_window_icon: Option<Vec<u8>>,
|
||||
system_tray_icon: Option<Icon>,
|
||||
package_info: crate::PackageInfo,
|
||||
package_info: PackageInfo,
|
||||
info_plist: (),
|
||||
) -> Self {
|
||||
Self {
|
||||
|
@ -103,7 +103,6 @@ impl Dev {
|
||||
set_current_dir(&tauri_path).with_context(|| "failed to change current working directory")?;
|
||||
let merge_config = self.config.clone();
|
||||
let config = get_config(merge_config.as_deref())?;
|
||||
let mut process: Arc<SharedChild>;
|
||||
|
||||
let (settings, out_dir) = {
|
||||
let config_guard = config.lock().unwrap();
|
||||
@ -199,7 +198,7 @@ impl Dev {
|
||||
let (child_wait_tx, child_wait_rx) = channel();
|
||||
let child_wait_rx = Arc::new(Mutex::new(child_wait_rx));
|
||||
|
||||
process = self.start_app(&runner, &cargo_features, child_wait_rx.clone());
|
||||
let mut process = self.start_app(&runner, &cargo_features, child_wait_rx.clone());
|
||||
|
||||
let (tx, rx) = channel();
|
||||
|
||||
|
@ -71,7 +71,7 @@ fn get_internal(merge_config: Option<&str>, reload: bool) -> crate::Result<Confi
|
||||
.chars()
|
||||
.skip(1)
|
||||
.collect::<String>()
|
||||
.replace("/", " > "),
|
||||
.replace('/', " > "),
|
||||
error.get_detail().unwrap_or_else(|| error.get_title()),
|
||||
);
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ pub fn rewrite_manifest(config: ConfigHandle) -> crate::Result<Manifest> {
|
||||
let mut def = InlineTable::default();
|
||||
def.get_or_insert(
|
||||
"version",
|
||||
version.to_string().replace("\"", "").replace(" ", ""),
|
||||
version.to_string().replace('\"', "").replace(' ', ""),
|
||||
);
|
||||
def.get_or_insert("features", Value::Array(toml_array(&features)));
|
||||
*tauri = Value::InlineTable(def);
|
||||
|
@ -133,7 +133,7 @@ fn npm_latest_version(pm: &PackageManager, name: &str) -> crate::Result<Option<S
|
||||
let output = cmd.arg("show").arg(name).arg("version").output()?;
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
Ok(Some(stdout.replace("\n", "")))
|
||||
Ok(Some(stdout.replace('\n', "")))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
@ -153,7 +153,7 @@ fn npm_latest_version(pm: &PackageManager, name: &str) -> crate::Result<Option<S
|
||||
let output = cmd.arg("info").arg(name).arg("version").output()?;
|
||||
if output.status.success() {
|
||||
let stdout = String::from_utf8_lossy(&output.stdout);
|
||||
Ok(Some(stdout.replace("\n", "")))
|
||||
Ok(Some(stdout.replace('\n', "")))
|
||||
} else {
|
||||
Ok(None)
|
||||
}
|
||||
@ -257,8 +257,8 @@ fn get_version(command: &str, args: &[&str]) -> crate::Result<Option<String>> {
|
||||
let version = if output.status.success() {
|
||||
Some(
|
||||
String::from_utf8_lossy(&output.stdout)
|
||||
.replace("\n", "")
|
||||
.replace("\r", ""),
|
||||
.replace('\n', "")
|
||||
.replace('\r', ""),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
|
Loading…
Reference in New Issue
Block a user