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 clap::ArgMatches;
|
||||
use espanso_package::{PackageSpecifier, SaveOptions};
|
||||
use espanso_package::{PackageSpecifier, ProviderOptions, SaveOptions};
|
||||
use espanso_path::Paths;
|
||||
|
||||
use crate::info_println;
|
||||
|
@ -30,6 +30,7 @@ pub fn install_package(paths: &Paths, matches: &ArgMatches) -> Result<()> {
|
|||
.ok_or_else(|| anyhow!("missing package name"))?;
|
||||
let version = matches.value_of("version");
|
||||
let force = matches.is_present("force");
|
||||
let refresh_index = matches.is_present("refresh-index");
|
||||
|
||||
info_println!(
|
||||
"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)
|
||||
|
||||
let package_provider = espanso_package::get_provider(&package_specifier)
|
||||
.context("unable to obtain compatible package provider")?;
|
||||
let package_provider = espanso_package::get_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());
|
||||
|
||||
|
@ -76,9 +83,15 @@ pub fn install_package(paths: &Paths, matches: &ArgMatches) -> Result<()> {
|
|||
let archiver =
|
||||
espanso_package::get_archiver(&paths.packages).context("unable to get package archiver")?;
|
||||
|
||||
archiver.save(&*package, &package_specifier, &SaveOptions {
|
||||
overwrite_existing: force,
|
||||
}).context("unable to save package")?;
|
||||
archiver
|
||||
.save(
|
||||
&*package,
|
||||
&package_specifier,
|
||||
&SaveOptions {
|
||||
overwrite_existing: force,
|
||||
},
|
||||
)
|
||||
.context("unable to save package")?;
|
||||
|
||||
info_println!("package installed!");
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use clap::ArgMatches;
|
||||
use espanso_package::{Archiver, PackageSpecifier, SaveOptions, StoredPackage};
|
||||
use espanso_package::{Archiver, PackageSpecifier, ProviderOptions, SaveOptions, StoredPackage};
|
||||
use espanso_path::Paths;
|
||||
|
||||
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();
|
||||
|
||||
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);
|
||||
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);
|
||||
|
||||
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)),
|
||||
};
|
||||
|
||||
let package_provider = espanso_package::get_provider(&package_specifier)
|
||||
.context("unable to obtain compatible package provider")?;
|
||||
let package_provider = espanso_package::get_provider(
|
||||
&package_specifier,
|
||||
&paths.runtime,
|
||||
&ProviderOptions::default(),
|
||||
)
|
||||
.context("unable to obtain compatible package provider")?;
|
||||
|
||||
info_println!("using package provider: {}", package_provider.name());
|
||||
|
||||
|
|
|
@ -133,6 +133,13 @@ fn main() {
|
|||
.takes_value(false)
|
||||
.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::with_name("use-native-git")
|
||||
.long("use-native-git")
|
||||
|
|
Loading…
Reference in New Issue
Block a user