mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-08 13:48:26 +00:00
Delete PackageSpecifier in favour of SplitVersion
This commit is contained in:
@@ -13,7 +13,7 @@ use crate::commands::Wast;
|
||||
use crate::commands::{Add, Cache, Config, Inspect, List, Login, Run, SelfUpdate, Validate};
|
||||
use crate::error::PrettyError;
|
||||
use clap::{CommandFactory, ErrorKind, Parser};
|
||||
use std::fmt;
|
||||
use std::{fmt, str::FromStr};
|
||||
|
||||
#[derive(Parser, Debug)]
|
||||
#[cfg_attr(
|
||||
@@ -282,7 +282,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()),
|
||||
@@ -292,7 +292,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()),
|
||||
@@ -302,7 +302,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,
|
||||
@@ -312,7 +312,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,
|
||||
@@ -322,7 +322,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,
|
||||
@@ -332,7 +332,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()),
|
||||
@@ -342,13 +342,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());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user