PartialWapmConfig -> WasmerConfig

This commit is contained in:
Felix Schütt
2022-12-22 11:29:39 +01:00
parent 45f4b8da4e
commit ec18ec71e7
11 changed files with 33 additions and 33 deletions

View File

@@ -77,8 +77,8 @@ impl Add {
Some(r) => Ok(r.clone()),
None => {
let wasmer_dir =
PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?;
let cfg = PartialWapmConfig::from_file(&wasmer_dir)
WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?;
let cfg = WasmerConfig::from_file(&wasmer_dir)
.map_err(Error::msg)
.context("Unable to load WAPM's config file")?;
Ok(cfg.registry.get_current_registry())

View File

@@ -4,7 +4,7 @@ use clap::Parser;
use std::collections::HashMap;
use std::path::Path;
use std::path::PathBuf;
use wasmer_registry::PartialWapmConfig;
use wasmer_registry::WasmerConfig;
static NOTE: &str =
"# See more keys and definitions at https://docs.wasmer.io/ecosystem/wapm/manifest";
@@ -365,7 +365,7 @@ fn construct_manifest(
.map(|p| &p.name)
.unwrap_or(fallback_package_name)
});
let wasmer_dir = PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?;
let wasmer_dir = WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?;
let namespace = namespace.or_else(|| {
wasmer_registry::whoami(&wasmer_dir, None, None)
.ok()

View File

@@ -1,5 +1,5 @@
use clap::Parser;
use wasmer_registry::PartialWapmConfig;
use wasmer_registry::WasmerConfig;
/// Subcommand for listing packages
#[derive(Debug, Copy, Clone, Parser)]
@@ -9,7 +9,7 @@ impl List {
/// execute [List]
pub fn execute(&self) -> Result<(), anyhow::Error> {
use prettytable::{format, row, Table};
let wasmer_dir = PartialWapmConfig::get_wasmer_dir()
let wasmer_dir = WasmerConfig::get_wasmer_dir()
.map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let rows = wasmer_registry::get_all_local_packages(&wasmer_dir)
.into_iter()

View File

@@ -1,7 +1,7 @@
use clap::Parser;
#[cfg(not(test))]
use dialoguer::Input;
use wasmer_registry::PartialWapmConfig;
use wasmer_registry::WasmerConfig;
/// Subcommand for listing packages
#[derive(Debug, Clone, Parser)]
@@ -52,7 +52,7 @@ impl Login {
/// execute [List]
pub fn execute(&self) -> Result<(), anyhow::Error> {
let token = self.get_token_or_ask_user()?;
let wasmer_dir = PartialWapmConfig::get_wasmer_dir()
let wasmer_dir = WasmerConfig::get_wasmer_dir()
.map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
match wasmer_registry::login::login_and_save_token(&wasmer_dir, &self.registry, &token)? {
Some(s) => println!("Login for WAPM user {:?} saved", s),

View File

@@ -9,7 +9,7 @@ use tar::Builder;
use thiserror::Error;
use time::{self, OffsetDateTime};
use wasmer_registry::publish::SignArchiveResult;
use wasmer_registry::{PartialWapmConfig, PACKAGE_TOML_FALLBACK_NAME};
use wasmer_registry::{WasmerConfig, PACKAGE_TOML_FALLBACK_NAME};
const MIGRATIONS: &[(i32, &str)] = &[
(0, include_str!("../../sql/migrations/0000.sql")),
@@ -94,9 +94,9 @@ impl Publish {
let registry = match self.registry.as_deref() {
Some(s) => wasmer_registry::format_graphql(s),
None => {
let wasmer_dir = PartialWapmConfig::get_wasmer_dir()
let wasmer_dir = WasmerConfig::get_wasmer_dir()
.map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let config = PartialWapmConfig::from_file(&wasmer_dir)
let config = WasmerConfig::from_file(&wasmer_dir)
.map_err(|e| anyhow::anyhow!("could not load config {e}"))?;
config.registry.get_current_registry()
}
@@ -325,8 +325,8 @@ pub fn sign_compressed_archive(
/// Opens an exclusive read/write connection to the database, creating it if it does not exist
pub fn open_db() -> anyhow::Result<Connection> {
let wasmer_dir =
PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let db_path = PartialWapmConfig::get_database_file_path(&wasmer_dir);
WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let db_path = WasmerConfig::get_database_file_path(&wasmer_dir);
let mut conn = Connection::open_with_flags(
db_path,
OpenFlags::SQLITE_OPEN_CREATE

View File

@@ -1,5 +1,5 @@
use clap::Parser;
use wasmer_registry::PartialWapmConfig;
use wasmer_registry::WasmerConfig;
#[derive(Debug, Parser)]
/// The options for the `wasmer whoami` subcommand
@@ -12,7 +12,7 @@ pub struct Whoami {
impl Whoami {
/// Execute `wasmer whoami`
pub fn execute(&self) -> Result<(), anyhow::Error> {
let wasmer_dir = PartialWapmConfig::get_wasmer_dir()
let wasmer_dir = WasmerConfig::get_wasmer_dir()
.map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let (registry, username) =
wasmer_registry::whoami(&wasmer_dir, self.registry.as_deref(), None)?;

View File

@@ -4,7 +4,7 @@ use anyhow::Context;
use std::path::{Path, PathBuf};
use std::str::FromStr;
use url::Url;
use wasmer_registry::PartialWapmConfig;
use wasmer_registry::WasmerConfig;
/// Source of a package
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
@@ -62,7 +62,7 @@ impl PackageSource {
};
}
Self::Url(u) => {
let wasmer_dir = PartialWapmConfig::get_wasmer_dir()
let wasmer_dir = WasmerConfig::get_wasmer_dir()
.map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
if let Some(path) =
wasmer_registry::Package::is_url_already_installed(u, &wasmer_dir)
@@ -73,7 +73,7 @@ impl PackageSource {
}
}
Self::Package(p) => {
let wasmer_dir = PartialWapmConfig::get_wasmer_dir()
let wasmer_dir = WasmerConfig::get_wasmer_dir()
.map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let package_path = Path::new(&p.file()).to_path_buf();
if package_path.exists() {
@@ -81,7 +81,7 @@ impl PackageSource {
} else if let Some(path) = p.already_installed(&wasmer_dir) {
return Ok(path);
} else {
let config = PartialWapmConfig::from_file(&wasmer_dir)
let config = WasmerConfig::from_file(&wasmer_dir)
.map_err(|e| anyhow::anyhow!("error loading wasmer config file: {e}"))?;
p.url(&config.registry.get_current_registry())?
}
@@ -94,7 +94,7 @@ impl PackageSource {
String::new()
};
let wasmer_dir = PartialWapmConfig::get_wasmer_dir()
let wasmer_dir = WasmerConfig::get_wasmer_dir()
.map_err(|e| anyhow::anyhow!("no wasmer dir: {e}"))?;
let mut sp = start_spinner(format!("Installing package {url} ..."));
let opt_path = wasmer_registry::install_package(&wasmer_dir, &url);

View File

@@ -576,7 +576,7 @@ pub fn whoami(
use crate::queries::{who_am_i_query, WhoAmIQuery};
use graphql_client::GraphQLQuery;
let config = PartialWapmConfig::from_file(wasmer_dir);
let config = WasmerConfig::from_file(wasmer_dir);
let config = config
.map_err(|e| anyhow::anyhow!("{e}"))
@@ -626,7 +626,7 @@ pub fn test_if_registry_present(registry: &str) -> Result<bool, String> {
pub fn get_all_available_registries(wasmer_dir: &Path) -> Result<Vec<String>, String> {
let config = PartialWapmConfig::from_file(wasmer_dir)?;
let config = WasmerConfig::from_file(wasmer_dir)?;
let mut registries = Vec::new();
for login in config.registry.tokens {
registries.push(format_graphql(&login.registry));

View File

@@ -1,5 +1,5 @@
use crate::config::{format_graphql, UpdateRegistry};
use crate::PartialWapmConfig;
use crate::WasmerConfig;
use std::path::Path;
@@ -12,7 +12,7 @@ pub fn login_and_save_token(
token: &str,
) -> Result<Option<String>, anyhow::Error> {
let registry = format_graphql(registry);
let mut config = PartialWapmConfig::from_file(wasmer_dir)
let mut config = WasmerConfig::from_file(wasmer_dir)
.map_err(|e| anyhow::anyhow!("config from file: {e}"))?;
config.registry.set_current_registry(&registry);
config.registry.set_login_token_for_registry(
@@ -20,7 +20,7 @@ pub fn login_and_save_token(
token,
UpdateRegistry::Update,
);
let path = PartialWapmConfig::get_file_location(wasmer_dir);
let path = WasmerConfig::get_file_location(wasmer_dir);
config.save(&path)?;
crate::utils::get_username_registry_token(&registry, token)
}

View File

@@ -1,4 +1,4 @@
use crate::PartialWapmConfig;
use crate::WasmerConfig;
use regex::Regex;
use std::path::{Path, PathBuf};
use std::{fmt, str::FromStr};
@@ -28,7 +28,7 @@ impl Package {
/// Checks whether the package is already installed, if yes, returns the path to the root dir
pub fn already_installed(&self, wasmer_dir: &Path) -> Option<PathBuf> {
let checkouts_dir = crate::get_checkouts_dir(wasmer_dir);
let config = PartialWapmConfig::from_file(wasmer_dir).ok()?;
let config = WasmerConfig::from_file(wasmer_dir).ok()?;
let current_registry = config.registry.get_current_registry();
let hash = self.get_hash(&current_registry);
@@ -134,7 +134,7 @@ impl Package {
/// Does not check whether the installation directory already exists.
pub fn get_path(&self, wasmer_dir: &Path) -> Result<PathBuf, anyhow::Error> {
let checkouts_dir = crate::get_checkouts_dir(wasmer_dir);
let config = PartialWapmConfig::from_file(wasmer_dir)
let config = WasmerConfig::from_file(wasmer_dir)
.map_err(|e| anyhow::anyhow!("could not load config {e}"))?;
let hash = self.get_hash(&config.registry.get_current_registry());

View File

@@ -1,6 +1,6 @@
use crate::graphql::{execute_query_modifier_inner, get_signed_url, GetSignedUrl};
use crate::graphql::{publish_package_mutation_chunked, PublishPackageMutationChunked};
use crate::{format_graphql, PartialWapmConfig};
use crate::{format_graphql, WasmerConfig};
use console::{style, Emoji};
use graphql_client::GraphQLQuery;
use indicatif::{ProgressBar, ProgressState, ProgressStyle};
@@ -40,9 +40,9 @@ pub fn try_chunked_uploading(
Some(s) => format_graphql(s),
None => {
let wasmer_dir =
PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?;
WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?;
let config = PartialWapmConfig::from_file(&wasmer_dir);
let config = WasmerConfig::from_file(&wasmer_dir);
config
.map_err(|e| anyhow::anyhow!("{e}"))?
@@ -55,9 +55,9 @@ pub fn try_chunked_uploading(
Some(s) => s.to_string(),
None => {
let wasmer_dir =
PartialWapmConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?;
WasmerConfig::get_wasmer_dir().map_err(|e| anyhow::anyhow!("{e}"))?;
let config = PartialWapmConfig::from_file(&wasmer_dir);
let config = WasmerConfig::from_file(&wasmer_dir);
config
.map_err(|e| anyhow::anyhow!("{e}"))?