Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename --reactor to --lib for new subcommand. #211

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,12 @@ support in `cargo component` for adapting a _preview1_ module will be removed.

## Getting Started

Use `cargo component new --reactor <name>` to create a new reactor component.
Use `cargo component new --lib <name>` to create a new library (reactor)
component.

A reactor component doesn't have a `run` (i.e. `main` in Rust) function
A library component doesn't have a `run` (i.e. `main` in Rust) function
exported and is meant to be used as a library rather than a command that runs
and exits. Without the `--reactor` flag, `cargo component` defaults to creating
and exits. Without the `--lib` flag, `cargo component` defaults to creating
a command component.

This will create a `wit/world.wit` file describing the world that the
Expand Down
19 changes: 7 additions & 12 deletions src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ pub struct NewCommand {
#[clap(long = "vcs", value_name = "VCS", value_parser = ["git", "hg", "pijul", "fossil", "none"])]
pub vcs: Option<String>,

/// Create a command component [default]
#[clap(long = "command", conflicts_with("reactor"))]
/// Create a CLI command component [default]
#[clap(long = "command", conflicts_with("lib"))]
pub command: bool,

/// Create a reactor component
#[clap(long = "reactor")]
pub reactor: bool,
/// Create a library (reactor) component
#[clap(long = "lib", alias = "reactor")]
pub lib: bool,

/// Edition to set for the generated crate
#[clap(long = "edition", value_name = "YEAR", value_parser = ["2015", "2018", "2021"])]
Expand All @@ -76,12 +76,7 @@ pub struct NewCommand {
pub editor: Option<String>,

/// Use the specified target world from a WIT package.
#[clap(
long = "target",
short = 't',
value_name = "TARGET",
requires = "reactor"
)]
#[clap(long = "target", short = 't', value_name = "TARGET", requires = "lib")]
pub target: Option<String>,

/// Use the specified default registry when generating the package.
Expand Down Expand Up @@ -307,7 +302,7 @@ impl NewCommand {
}

fn is_command(&self) -> bool {
self.command || !self.reactor
self.command || !self.lib
}

fn generate_source(
Expand Down
4 changes: 2 additions & 2 deletions tests/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ edition = "2021"
project.file("baz/src/lib.rs", "")?;

project
.cargo_component("new --reactor foo")
.cargo_component("new --lib foo")
.assert()
.stderr(contains("Updated manifest of package `foo`"))
.success();
Expand All @@ -95,7 +95,7 @@ edition = "2021"
})?;

project
.cargo_component("new --reactor bar")
.cargo_component("new --lib bar")
.assert()
.stderr(contains("Updated manifest of package `bar`"))
.success();
Expand Down
4 changes: 2 additions & 2 deletions tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ edition = "2021"
project.file("baz/src/lib.rs", "")?;

project
.cargo_component("new --reactor foo")
.cargo_component("new --lib foo")
.assert()
.stderr(contains("Updated manifest of package `foo`"))
.success();
Expand All @@ -90,7 +90,7 @@ edition = "2021"
})?;

project
.cargo_component("new --reactor bar")
.cargo_component("new --lib bar")
.assert()
.stderr(contains("Updated manifest of package `bar`"))
.success();
Expand Down
4 changes: 2 additions & 2 deletions tests/clippy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ edition = "2021"
project.file("baz/src/lib.rs", "")?;

project
.cargo_component("new --reactor foo")
.cargo_component("new --lib foo")
.assert()
.stderr(contains("Updated manifest of package `foo`"))
.success();
Expand All @@ -115,7 +115,7 @@ edition = "2021"
})?;

project
.cargo_component("new --reactor bar")
.cargo_component("new --lib bar")
.assert()
.stderr(contains("Updated manifest of package `bar`"))
.success();
Expand Down
4 changes: 2 additions & 2 deletions tests/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ edition = "2021"
project.file("baz/src/lib.rs", "")?;

project
.cargo_component("new --reactor foo")
.cargo_component("new --lib foo")
.assert()
.stderr(contains("Updated manifest of package `foo`"))
.success();
Expand All @@ -84,7 +84,7 @@ edition = "2021"
})?;

project
.cargo_component("new --reactor bar")
.cargo_component("new --lib bar")
.assert()
.stderr(contains("Updated manifest of package `bar`"))
.success();
Expand Down
22 changes: 17 additions & 5 deletions tests/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn it_creates_the_expected_files_for_bin() -> Result<()> {
fn it_creates_the_expected_files() -> Result<()> {
let dir = TempDir::new()?;

cargo_component("new --reactor foo")
cargo_component("new --lib foo")
.current_dir(dir.path())
.assert()
.stderr(contains("Updated manifest of package `foo`"))
Expand All @@ -65,7 +65,7 @@ fn it_creates_the_expected_files() -> Result<()> {
fn it_supports_editor_option() -> Result<()> {
let dir = TempDir::new()?;

cargo_component("new --reactor foo --editor none")
cargo_component("new --lib foo --editor none")
.current_dir(dir.path())
.assert()
.stderr(contains("Updated manifest of package `foo"))
Expand All @@ -85,7 +85,7 @@ fn it_supports_editor_option() -> Result<()> {
fn it_supports_edition_option() -> Result<()> {
let dir = TempDir::new()?;

cargo_component("new --reactor foo --edition 2018")
cargo_component("new --lib foo --edition 2018")
.current_dir(dir.path())
.assert()
.stderr(contains("Updated manifest of package `foo"))
Expand All @@ -102,7 +102,7 @@ fn it_supports_edition_option() -> Result<()> {
fn it_supports_name_option() -> Result<()> {
let dir = TempDir::new()?;

cargo_component("new --reactor foo --name bar")
cargo_component("new --lib foo --name bar")
.current_dir(dir.path())
.assert()
.stderr(contains("Updated manifest of package `bar`"))
Expand All @@ -119,7 +119,7 @@ fn it_supports_name_option() -> Result<()> {
fn it_rejects_rust_keywords() -> Result<()> {
let dir = TempDir::new()?;

cargo_component("new --reactor foo --name fn")
cargo_component("new --lib foo --name fn")
.current_dir(dir.path())
.assert()
.stderr(contains(
Expand Down Expand Up @@ -182,3 +182,15 @@ async fn it_errors_if_target_does_not_exist() -> Result<()> {

Ok(())
}

#[test]
fn it_supports_the_reactor_option() -> Result<()> {
let dir = TempDir::new()?;

cargo_component("new --reactor foo")
.current_dir(dir.path())
.assert()
.try_success()?;

Ok(())
}
4 changes: 2 additions & 2 deletions tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ impl Project {
pub fn new(name: &str) -> Result<Self> {
let dir = TempDir::new()?;

cargo_component(&format!("new --reactor {name}"))
cargo_component(&format!("new --lib {name}"))
.current_dir(dir.path())
.assert()
.try_success()?;
Expand Down Expand Up @@ -244,7 +244,7 @@ impl Project {
}

pub fn with_dir(dir: Rc<TempDir>, name: &str, args: &str) -> Result<Self> {
cargo_component(&format!("new --reactor {name} {args}"))
cargo_component(&format!("new --lib {name} {args}"))
.current_dir(dir.path())
.assert()
.try_success()?;
Expand Down
Loading