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

Add feature flag to disable the TUI #432

Merged
merged 1 commit into from
Dec 21, 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: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,16 @@ winnow = "0.6.16"
anyhow = {workspace = true, features = ["backtrace"]}
slumber_cli = {workspace = true}
slumber_core = {workspace = true}
slumber_tui = {workspace = true}
slumber_tui = {workspace = true, optional = true}
tokio = {workspace = true, features = ["macros", "rt-multi-thread"]}
tracing = {workspace = true}
tracing-subscriber = {version = "0.3.17", default-features = false, features = ["ansi", "fmt", "registry"]}

[features]
default = ["tui"]
# TUI can be disabled in dev to speed compilation while testing CLI
tui = ["dep:slumber_tui"]

# The profile that 'cargo dist' will build with
[profile.dist]
inherits = "release"
Expand Down
12 changes: 4 additions & 8 deletions crates/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@ use std::{path::PathBuf, process::ExitCode};

const COMMAND_NAME: &str = "slumber";

/// Configurable HTTP client with both TUI and CLI interfaces
///
/// If subcommand is omitted, start the TUI.
#[derive(Debug, Parser)]
#[clap(
author,
version,
about,
name = COMMAND_NAME,
long_about = "Configurable HTTP client with both TUI and CLI interfaces"
)]
#[clap(author, version, about, name = COMMAND_NAME)]
pub struct Args {
#[command(flatten)]
pub global: GlobalArgs,
/// Subcommand to execute. If omitted, run the TUI
#[command(subcommand)]
pub subcommand: Option<CliCommand>,
}
Expand Down
11 changes: 7 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
use anyhow::Context;
use slumber_cli::Args;
use slumber_core::util::{paths, ResultTraced};
use slumber_tui::Tui;
use std::{
fs::{self, File, OpenOptions},
io,
Expand All @@ -23,12 +22,16 @@ async fn main() -> anyhow::Result<ExitCode> {

// Select mode based on whether request ID(s) were given
match args.subcommand {
// Run the TUI
// Run the TUI. TUI can be disabled so we don't have to compile it while
// testing the CLI
#[cfg(feature = "tui")]
None => {
// This should return the error so we get a full stack trac
Tui::start(args.global.file).await?;
// This should return the error so we get a full stack trace
slumber_tui::Tui::start(args.global.file).await?;
Ok(ExitCode::SUCCESS)
}
#[cfg(not(feature = "tui"))]
None => Err(anyhow::anyhow!("TUI feature is disabled")),

// Execute one request without a TUI
Some(subcommand) => Ok(subcommand
Expand Down
Loading