pub fn parse_install_spec(s: &str) -> Result<InstallSpec, String>Expand description
Parse an install spec string into InstallSpec.
Accepted forms:
path:<directory>crate:<name>@<version>gh:<owner>/<repo>@<tagOrLatest>
§Errors
Returns an error if the prefix is unknown or required components are missing.
§Examples
use cotis_cli::install::{parse_install_spec, InstallSpec};
use std::path::PathBuf;
match parse_install_spec("path:./my-routine").unwrap() {
InstallSpec::LocalPath(p) => assert_eq!(p, PathBuf::from("./my-routine")),
_ => panic!("expected LocalPath"),
}
match parse_install_spec("crate:my-routine@0.2.0").unwrap() {
InstallSpec::Crate { name, version } => {
assert_eq!(name, "my-routine");
assert_eq!(version, "0.2.0");
}
_ => panic!("expected Crate"),
}
match parse_install_spec("gh:org/repo@latest").unwrap() {
InstallSpec::Github { owner, repo, tag } => {
assert_eq!(owner, "org");
assert_eq!(repo, "repo");
assert_eq!(tag, "latest");
}
_ => panic!("expected Github"),
}
assert!(parse_install_spec("invalid").is_err());