Skip to content

Commit

Permalink
Add feature flag to disable the TUI
Browse files Browse the repository at this point in the history
I don't think any users would ever want to do this, but it's helpful in dev when iterating and only the CLI is needed. Should speed up compilation a bit.
  • Loading branch information
LucasPickering committed Dec 21, 2024
1 parent 38c604b commit b7e68a7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
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

0 comments on commit b7e68a7

Please sign in to comment.