wasm_pack/command/publish/
access.rs

1use anyhow::{bail, Error, Result};
2use std::fmt;
3use std::str::FromStr;
4
5/// Represents access level for the to-be publish package. Passed to `wasm-pack publish` as a flag, e.g. `--access=public`.
6#[derive(Clone, Debug)]
7pub enum Access {
8    /// Access is granted to all. All unscoped packages *must* be public.
9    Public,
10    /// Access is restricted, granted via npm permissions. Must be a scoped package.
11    Restricted,
12}
13
14impl FromStr for Access {
15    type Err = Error;
16
17    fn from_str(s: &str) -> Result<Self> {
18        match s {
19      "public" => Ok(Access::Public),
20      "restricted" => Ok(Access::Restricted),
21      "private" => Ok(Access::Restricted),
22      _ => bail!("{} is not a supported access level. See https://docs.npmjs.com/cli/access for more information on npm package access levels.", s),
23    }
24    }
25}
26
27impl fmt::Display for Access {
28    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
29        let printable = match *self {
30            Access::Public => "--access=public",
31            Access::Restricted => "--access=restricted",
32        };
33        write!(f, "{}", printable)
34    }
35}