feat(cmds): add subcommands init, pack, publish

master
Ashley Williams 7 years ago
parent 7cc7befd6c
commit 9f78b809e1
  1. 34
      src/main.rs

@ -11,15 +11,26 @@ use std::io::prelude::*;
/// 📦 ✨ pack and publish your wasm! /// 📦 ✨ pack and publish your wasm!
#[derive(Debug, StructOpt)] #[derive(Debug, StructOpt)]
struct Cli { struct Cli {
/// ☔ init and pack, but don't publish #[structopt(subcommand)] // Note that we mark a field as a subcommand
#[structopt(long = "dry-run", short = "d")] cmd: Command,
dry_run: bool,
/// 📝 log all the things! /// 📝 log all the things!
#[structopt(long = "verbose", short = "v", parse(from_occurrences))] #[structopt(long = "verbose", short = "v", parse(from_occurrences))]
verbosity: u8, verbosity: u8,
} }
#[derive(Debug, StructOpt)]
enum Command {
#[structopt(name = "init")]
/// 🐣 initialize a package.json based on your compiled wasm
Init {},
#[structopt(name = "pack")]
/// 🍱 create a tar of your npm package but don't publish!
Pack {},
#[structopt(name = "publish")]
/// 🎆 pack up your npm package and publish!
Publish {},
}
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct CargoManifest { pub struct CargoManifest {
package: CargoPackage, package: CargoPackage,
@ -66,10 +77,15 @@ fn write_package_json() -> Result<()> {
Ok(()) Ok(())
} }
main!(|args: Cli, log_level: verbosity| { main!(|args: Cli, log_level: verbosity| match args.cmd {
write_package_json()?; Command::Init { .. } => {
println!("✍ wrote package.json"); write_package_json()?;
if !args.dry_run { println!("✍ wrote a package.json!");
println!("⬆ published pkg to npm"); }
Command::Pack { .. } => {
println!("🎒 packed up your pacakge!");
}
Command::Publish { .. } => {
println!("💥 published your package!");
} }
}); });

Loading…
Cancel
Save