-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(publish): add --access flag to publish command
- Loading branch information
1 parent
2ef929d
commit b57c947
Showing
5 changed files
with
77 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
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, | ||
} | ||
|
||
impl FromStr for Access { | ||
type Err = Error; | ||
|
||
fn from_str(s: &str) -> Result<Self, Error> { | ||
match s { | ||
"public" => Ok(Access::Public), | ||
"restricted" => Ok(Access::Restricted), | ||
"private" => Ok(Access::Restricted), | ||
_ => Err(Error::Unsupported { message: format!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s)}), | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Access { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
let printable = match *self { | ||
Access::Public => "--access=public", | ||
Access::Restricted => "--access=restricted", | ||
}; | ||
write!(f, "{}", printable) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters