diff --git a/.github/workflows/crossterm.yml b/.github/workflows/crossterm.yml index 52ac016..4636f87 100644 --- a/.github/workflows/crossterm.yml +++ b/.github/workflows/crossterm.yml @@ -65,14 +65,14 @@ jobs: # build / doc / test - name: build_all - run: cargo build --verbose --workspace --no-default-features --features=crossterm + run: cargo build --verbose --workspace --no-default-features --features=crossterm,macros # doesn't use --include-ignored as it was unstable in 1.47 - name: test_regular - run: cargo test --workspace --verbose --no-default-features --features=crossterm + run: cargo test --workspace --verbose --no-default-features --features=crossterm,macros - name: test_ignored - run: cargo test --workspace --verbose --no-default-features --features=crossterm -- --ignored + run: cargo test --workspace --verbose --no-default-features --features=crossterm,macros -- --ignored clippy: name: clippy @@ -92,4 +92,4 @@ jobs: uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --no-default-features --features=crossterm --workspace --bins --examples + args: --no-default-features --features=crossterm,macros --workspace --bins --examples diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index 4a7eab6..bdf5f54 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -67,13 +67,10 @@ jobs: - name: build_all run: cargo build --verbose --workspace - # doesn't use --include-ignored as it was unstable in 1.47 + # Don't test ignored as they require `macros` feature - name: test_regular run: cargo test --workspace --verbose - - name: test_ignored - run: cargo test --workspace --verbose -- --ignored - rustfmt: name: rustfmt runs-on: ubuntu-18.04 diff --git a/.github/workflows/termion.yml b/.github/workflows/termion.yml index 70a9f72..1326774 100644 --- a/.github/workflows/termion.yml +++ b/.github/workflows/termion.yml @@ -54,14 +54,14 @@ jobs: # build / doc / test - name: build_all - run: cargo build --verbose --workspace --no-default-features --features=termion + run: cargo build --verbose --workspace --no-default-features --features=termion,macros # doesn't use --include-ignored as it was unstable in 1.47 - name: test_regular - run: cargo test --workspace --verbose --no-default-features --features=termion + run: cargo test --workspace --verbose --no-default-features --features=termion,macros - name: test_ignored - run: cargo test --workspace --verbose --no-default-features --features=termion -- --ignored + run: cargo test --workspace --verbose --no-default-features --features=termion,macros -- --ignored clippy: name: clippy @@ -81,4 +81,4 @@ jobs: uses: actions-rs/clippy-check@v1 with: token: ${{ secrets.GITHUB_TOKEN }} - args: --no-default-features --features=termion --workspace --bins --examples + args: --no-default-features --features=termion,macros --workspace --bins --examples diff --git a/Cargo.toml b/Cargo.toml index 13dac91..2bed7db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,7 @@ members = [ [dependencies] tempfile = "3" ui = { package = "requestty-ui", path = "./requestty-ui" } -macros = { package = "requestty-macros", path = "./requestty-macros" } +macros = { package = "requestty-macros", path = "./requestty-macros", optional = true } smallvec = { version = "1.6", optional = true } @@ -36,3 +36,11 @@ termion = ["ui/termion"] [package.metadata.docs.rs] all-features = true rustc-args = ["--cfg", "docsrs"] + +[[example]] +name = "macros" +required-features = ["macros"] + +[[test]] +name = "macros" +required-features = ["macros"] diff --git a/src/lib.rs b/src/lib.rs index 7518c7f..d645fc8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,11 +25,12 @@ //! //! See [`Question`] for more information on the builders. //! -//! ### Using macros +//! ### Using macros (only with `macros` feature) //! //! Unlike the builder api, the macros can only be used to create a list of questions. //! -//! ``` +#![cfg_attr(feature = "macros", doc = "```")] +#![cfg_attr(not(feature = "macros"), doc = "```ignore")] //! use requestty::{questions, Answers}; //! //! let questions = questions! [ @@ -101,6 +102,9 @@ //! //! # Optional features //! +//! - `macros`: Enabling this feature will allow you to use the [`questions`] and +//! [`prompt_module`](prompt_module!) macros. +//! //! - `smallvec` (default): Enabling this feature will use [`SmallVec`] instead of [`Vec`] for [auto //! completions]. This allows inlining single completions. //! @@ -208,6 +212,8 @@ use ui::{backend::Backend, events::EventIterator}; /// Note that inlining only works for rust version 1.51 onwards. Pre 1.51, a [`Vec`] is still used. /// /// See also [`prompt_module`](prompt_module!). +#[cfg(feature = "macros")] +#[cfg_attr(docsrs, doc(cfg(feature = "macros")))] pub use macros::questions; pub use answer::{Answer, Answers, ExpandItem, ListItem}; diff --git a/src/prompt_module.rs b/src/prompt_module.rs index 255c86d..662505c 100644 --- a/src/prompt_module.rs +++ b/src/prompt_module.rs @@ -168,6 +168,8 @@ where /// See also [`questions`]. /// /// [`questions`]: crate::questions +#[cfg(feature = "macros")] +#[cfg_attr(docsrs, doc(cfg(feature = "macros")))] #[macro_export] macro_rules! prompt_module { ($($tt:tt)*) => {