From 61080b749b5da297c5b048f10d7c460f55a837bc Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Fri, 14 Sep 2018 13:03:04 -0400 Subject: [PATCH] ok, this should be good --- src/command/mod.rs | 1 + src/command/publish/access.rs | 11 +++-------- src/command/publish/mod.rs | 1 + src/npm.rs | 26 +++++++++++++++++++------- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/command/mod.rs b/src/command/mod.rs index fc92bd04f..205b8cd26 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -3,6 +3,7 @@ mod build; mod login; mod pack; +/// Data structures and functions for publishing a package. pub mod publish; pub mod utils; diff --git a/src/command/publish/access.rs b/src/command/publish/access.rs index c263550d1..980a9e02a 100644 --- a/src/command/publish/access.rs +++ b/src/command/publish/access.rs @@ -2,11 +2,13 @@ use error::Error; use std::fmt; use std::str::FromStr; +/// Represents access level for the to-be publish package. Passed to `wasm-pack publish` as a flag, e.g. `--access=public`. #[derive(Debug)] pub enum Access { + /// Access is granted to all. All unscoped packages *must* be public. Public, + /// Access is restricted, granted via npm permissions. Must be a scoped package. Restricted, - Default, } impl FromStr for Access { @@ -27,14 +29,7 @@ impl fmt::Display for Access { let printable = match *self { Access::Public => "--access=public", Access::Restricted => "--access=restricted", - Access::Default => "", }; write!(f, "{}", printable) } } - -impl Default for Access { - fn default() -> Access { - Access::Default - } -} diff --git a/src/command/publish/mod.rs b/src/command/publish/mod.rs index f60d2ba27..93453549c 100644 --- a/src/command/publish/mod.rs +++ b/src/command/publish/mod.rs @@ -1,3 +1,4 @@ +/// Data structure to represent published package access level. pub mod access; use self::access::Access; diff --git a/src/npm.rs b/src/npm.rs index 1d25d40fc..5e7ccfd5d 100644 --- a/src/npm.rs +++ b/src/npm.rs @@ -20,13 +20,25 @@ pub fn npm_pack(path: &str) -> Result<(), Error> { /// Run the `npm publish` command. pub fn npm_publish(path: &str, access: Option) -> Result<(), Error> { - let output = Command::new("npm") - .current_dir(path) - .arg("publish") - .arg(&format!("{}", access.unwrap_or_default().to_string())) - .stdin(Stdio::inherit()) - .stdout(Stdio::inherit()) - .output()?; + let output = match access { + Some(a) => { + Command::new("npm") + .current_dir(path) + .arg("publish") + .arg(&format!("{}", a.to_string())) + .stdin(Stdio::inherit()) + .stdout(Stdio::inherit()) + .output()? + }, + None => { + Command::new("npm") + .current_dir(path) + .arg("publish") + .stdin(Stdio::inherit()) + .stdout(Stdio::inherit()) + .output()? + }, + }; if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr);