feat(core): wire up espanso hub package index caching flags
This commit is contained in:
parent
bfb5a8ac4c
commit
36ff784684
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use espanso_package::{PackageSpecifier, SaveOptions};
|
use espanso_package::{PackageSpecifier, ProviderOptions, SaveOptions};
|
||||||
use espanso_path::Paths;
|
use espanso_path::Paths;
|
||||||
|
|
||||||
use crate::info_println;
|
use crate::info_println;
|
||||||
|
@ -30,6 +30,7 @@ pub fn install_package(paths: &Paths, matches: &ArgMatches) -> Result<()> {
|
||||||
.ok_or_else(|| anyhow!("missing package name"))?;
|
.ok_or_else(|| anyhow!("missing package name"))?;
|
||||||
let version = matches.value_of("version");
|
let version = matches.value_of("version");
|
||||||
let force = matches.is_present("force");
|
let force = matches.is_present("force");
|
||||||
|
let refresh_index = matches.is_present("refresh-index");
|
||||||
|
|
||||||
info_println!(
|
info_println!(
|
||||||
"installing package: {} - version: {}",
|
"installing package: {} - version: {}",
|
||||||
|
@ -60,8 +61,14 @@ pub fn install_package(paths: &Paths, matches: &ArgMatches) -> Result<()> {
|
||||||
|
|
||||||
// TODO: if git is specified, make sure external is as well (or warn otherwise)
|
// TODO: if git is specified, make sure external is as well (or warn otherwise)
|
||||||
|
|
||||||
let package_provider = espanso_package::get_provider(&package_specifier)
|
let package_provider = espanso_package::get_provider(
|
||||||
.context("unable to obtain compatible package provider")?;
|
&package_specifier,
|
||||||
|
&paths.runtime,
|
||||||
|
&ProviderOptions {
|
||||||
|
force_index_update: refresh_index,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.context("unable to obtain compatible package provider")?;
|
||||||
|
|
||||||
info_println!("using package provider: {}", package_provider.name());
|
info_println!("using package provider: {}", package_provider.name());
|
||||||
|
|
||||||
|
@ -76,9 +83,15 @@ pub fn install_package(paths: &Paths, matches: &ArgMatches) -> Result<()> {
|
||||||
let archiver =
|
let archiver =
|
||||||
espanso_package::get_archiver(&paths.packages).context("unable to get package archiver")?;
|
espanso_package::get_archiver(&paths.packages).context("unable to get package archiver")?;
|
||||||
|
|
||||||
archiver.save(&*package, &package_specifier, &SaveOptions {
|
archiver
|
||||||
overwrite_existing: force,
|
.save(
|
||||||
}).context("unable to save package")?;
|
&*package,
|
||||||
|
&package_specifier,
|
||||||
|
&SaveOptions {
|
||||||
|
overwrite_existing: force,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.context("unable to save package")?;
|
||||||
|
|
||||||
info_println!("package installed!");
|
info_println!("package installed!");
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use clap::ArgMatches;
|
use clap::ArgMatches;
|
||||||
use espanso_package::{Archiver, PackageSpecifier, SaveOptions, StoredPackage};
|
use espanso_package::{Archiver, PackageSpecifier, ProviderOptions, SaveOptions, StoredPackage};
|
||||||
use espanso_path::Paths;
|
use espanso_path::Paths;
|
||||||
|
|
||||||
use crate::{error_eprintln, info_println, warn_eprintln};
|
use crate::{error_eprintln, info_println, warn_eprintln};
|
||||||
|
@ -55,7 +55,7 @@ pub fn update_package(paths: &Paths, matches: &ArgMatches) -> Result<UpdateResul
|
||||||
let mut update_errors = Vec::new();
|
let mut update_errors = Vec::new();
|
||||||
|
|
||||||
for package_name in &packages_to_update {
|
for package_name in &packages_to_update {
|
||||||
if let Err(err) = perform_package_update(&*archiver, &package_name) {
|
if let Err(err) = perform_package_update(paths, &*archiver, &package_name) {
|
||||||
error_eprintln!("error updating package '{}': {:?}", package_name, err);
|
error_eprintln!("error updating package '{}': {:?}", package_name, err);
|
||||||
update_errors.push(err);
|
update_errors.push(err);
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,11 @@ pub fn update_package(paths: &Paths, matches: &ArgMatches) -> Result<UpdateResul
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn perform_package_update(archiver: &dyn Archiver, package_name: &str) -> Result<()> {
|
fn perform_package_update(
|
||||||
|
paths: &Paths,
|
||||||
|
archiver: &dyn Archiver,
|
||||||
|
package_name: &str,
|
||||||
|
) -> Result<()> {
|
||||||
info_println!("updating package: {}", package_name);
|
info_println!("updating package: {}", package_name);
|
||||||
|
|
||||||
let package = archiver.get(package_name)?;
|
let package = archiver.get(package_name)?;
|
||||||
|
@ -92,8 +96,12 @@ fn perform_package_update(archiver: &dyn Archiver, package_name: &str) -> Result
|
||||||
StoredPackage::Modern(modern) => ((&modern).into(), Some(modern.manifest.version)),
|
StoredPackage::Modern(modern) => ((&modern).into(), Some(modern.manifest.version)),
|
||||||
};
|
};
|
||||||
|
|
||||||
let package_provider = espanso_package::get_provider(&package_specifier)
|
let package_provider = espanso_package::get_provider(
|
||||||
.context("unable to obtain compatible package provider")?;
|
&package_specifier,
|
||||||
|
&paths.runtime,
|
||||||
|
&ProviderOptions::default(),
|
||||||
|
)
|
||||||
|
.context("unable to obtain compatible package provider")?;
|
||||||
|
|
||||||
info_println!("using package provider: {}", package_provider.name());
|
info_println!("using package provider: {}", package_provider.name());
|
||||||
|
|
||||||
|
|
|
@ -133,6 +133,13 @@ fn main() {
|
||||||
.takes_value(false)
|
.takes_value(false)
|
||||||
.help("Overwrite the package if already installed"),
|
.help("Overwrite the package if already installed"),
|
||||||
)
|
)
|
||||||
|
.arg(
|
||||||
|
Arg::with_name("refresh-index")
|
||||||
|
.long("refresh-index")
|
||||||
|
.required(false)
|
||||||
|
.takes_value(false)
|
||||||
|
.help("Request a fresh copy of the Espanso Hub package index instead of using the cached version.")
|
||||||
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::with_name("use-native-git")
|
Arg::with_name("use-native-git")
|
||||||
.long("use-native-git")
|
.long("use-native-git")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user