Merge branch 'master' into whoami

This commit is contained in:
Felix Schütt
2022-11-18 12:05:47 +01:00
committed by GitHub
34 changed files with 1804 additions and 1266 deletions

View File

@@ -10,10 +10,10 @@ use crate::commands::CreateExe;
use crate::commands::CreateObj;
#[cfg(feature = "wast")]
use crate::commands::Wast;
use crate::commands::{Cache, Config, Inspect, List, Login, Run, SelfUpdate, Validate, Whoami};
use crate::commands::{Add, Cache, Config, Inspect, List, Login, Run, SelfUpdate, Validate, Whoami};
use crate::error::PrettyError;
use clap::{CommandFactory, ErrorKind, Parser};
use std::fmt;
use std::{fmt, str::FromStr};
#[derive(Parser, Debug)]
#[cfg_attr(
@@ -154,6 +154,9 @@ enum WasmerCLIOptions {
/// Shows the current logged in user for the current active registry
#[clap(name = "whoami")]
Whoami(Whoami),
/// Add a WAPM package's bindings to your application.
Add(Add),
}
impl WasmerCLIOptions {
@@ -178,6 +181,7 @@ impl WasmerCLIOptions {
#[cfg(target_os = "linux")]
Self::Binfmt(binfmt) => binfmt.execute(),
Self::Whoami(whoami) => whoami.execute(),
Self::Add(install) => install.execute(),
}
}
}
@@ -229,7 +233,7 @@ fn wasmer_main_inner() -> Result<(), anyhow::Error> {
WasmerCLIOptions::Run(Run::from_binfmt_args())
} else {
match command.unwrap_or(&"".to_string()).as_ref() {
"cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "run"
"add" | "cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "run"
| "self-update" | "validate" | "wast" | "binfmt" | "list" | "login" => {
WasmerCLIOptions::parse()
}
@@ -283,7 +287,7 @@ impl fmt::Display for SplitVersion {
#[test]
fn test_split_version() {
assert_eq!(
SplitVersion::new("registry.wapm.io/graphql/python/python").unwrap(),
SplitVersion::parse("registry.wapm.io/graphql/python/python").unwrap(),
SplitVersion {
original: "registry.wapm.io/graphql/python/python".to_string(),
registry: Some("https://registry.wapm.io/graphql".to_string()),
@@ -293,7 +297,7 @@ fn test_split_version() {
}
);
assert_eq!(
SplitVersion::new("registry.wapm.io/python/python").unwrap(),
SplitVersion::parse("registry.wapm.io/python/python").unwrap(),
SplitVersion {
original: "registry.wapm.io/python/python".to_string(),
registry: Some("https://registry.wapm.io/graphql".to_string()),
@@ -303,7 +307,7 @@ fn test_split_version() {
}
);
assert_eq!(
SplitVersion::new("namespace/name@version:command").unwrap(),
SplitVersion::parse("namespace/name@version:command").unwrap(),
SplitVersion {
original: "namespace/name@version:command".to_string(),
registry: None,
@@ -313,7 +317,7 @@ fn test_split_version() {
}
);
assert_eq!(
SplitVersion::new("namespace/name@version").unwrap(),
SplitVersion::parse("namespace/name@version").unwrap(),
SplitVersion {
original: "namespace/name@version".to_string(),
registry: None,
@@ -323,7 +327,7 @@ fn test_split_version() {
}
);
assert_eq!(
SplitVersion::new("namespace/name").unwrap(),
SplitVersion::parse("namespace/name").unwrap(),
SplitVersion {
original: "namespace/name".to_string(),
registry: None,
@@ -333,7 +337,7 @@ fn test_split_version() {
}
);
assert_eq!(
SplitVersion::new("registry.wapm.io/namespace/name").unwrap(),
SplitVersion::parse("registry.wapm.io/namespace/name").unwrap(),
SplitVersion {
original: "registry.wapm.io/namespace/name".to_string(),
registry: Some("https://registry.wapm.io/graphql".to_string()),
@@ -343,13 +347,21 @@ fn test_split_version() {
}
);
assert_eq!(
format!("{}", SplitVersion::new("namespace").unwrap_err()),
format!("{}", SplitVersion::parse("namespace").unwrap_err()),
"Invalid package version: \"namespace\"".to_string(),
);
}
impl SplitVersion {
pub fn new(s: &str) -> Result<SplitVersion, anyhow::Error> {
pub fn parse(s: &str) -> Result<SplitVersion, anyhow::Error> {
s.parse()
}
}
impl FromStr for SplitVersion {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let command = WasmerCLIOptions::command();
let mut prohibited_package_names = command.get_subcommands().map(|s| s.get_name());