Skip to content

Commit

Permalink
Make ui be the default subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
davidlattimore committed Sep 20, 2023
1 parent e8dbc0c commit 6a5a327
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ sudo apt install bubblewrap
From the root of your project (the directory containing `Cargo.toml`), run:

```sh
cackle ui
cackle
```

This will interactively guide you through creating an initial `cackle.toml`. Some manual editing of
Expand Down
15 changes: 10 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ struct Args {
#[clap(long, hide = true)]
tmpdir: Option<PathBuf>,

/// What kind of user interface to use.
#[clap(long, default_value = "full")]
ui: ui::Kind,

#[command(subcommand)]
command: Command,
command: Option<Command>,
}

#[derive(Subcommand, Debug, Clone, Default)]
Expand All @@ -140,7 +144,7 @@ enum Command {

/// Interactive check of configuration.
#[cfg(feature = "ui")]
Ui(ui::UiArgs),
Ui,

/// Print summary of permissions used.
Summary(SummaryOptions),
Expand Down Expand Up @@ -253,7 +257,7 @@ impl Cackle {
/// Runs, reports any error and returns the exit code. Takes self by value so that it's dropped
/// before we return. That way the user interface will be cleaned up before we exit.
fn run_and_report_errors(mut self, abort_recv: Receiver<()>) -> ExitCode {
if let Command::Summary(options) = &self.args.command {
if let Some(Command::Summary(options)) = &self.args.command {
return self.print_summary(options);
}
let mut error = None;
Expand Down Expand Up @@ -284,7 +288,7 @@ impl Cackle {
}
if exit_code == outcome::SUCCESS
&& !self.args.quiet
&& !matches!(self.args.command, Command::Cargo(..))
&& !matches!(self.args.command, Some(Command::Cargo(..)))
{
println!(
"Completed successfully for configuration {}",
Expand Down Expand Up @@ -316,7 +320,8 @@ impl Cackle {
let checker = &mut self.checker.lock().unwrap();
checker.load_config()?;

if !self.args.replay_requests && !matches!(self.args.command, Command::Cargo(..)) {
if !self.args.replay_requests && !matches!(self.args.command, Some(Command::Cargo(..)))
{
proxy::clean(&self.root_path, &self.args, &checker.config.raw.common)?;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/proxy/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub(crate) fn command(
command.arg("--color=always");
}
let extra_args;
if let crate::Command::Cargo(cargo_options) = &args.command {
if let Some(crate::Command::Cargo(cargo_options)) = &args.command {
command.arg(&cargo_options.subcommand);
extra_args = cargo_options.remaining.as_slice();
} else {
Expand Down
25 changes: 10 additions & 15 deletions src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::problem_store::ProblemStoreRef;
use crate::Args;
use crate::Command;
use anyhow::Result;
use clap::Parser;
use clap::ValueEnum;
use log::info;
use std::path::Path;
Expand All @@ -24,15 +23,9 @@ mod basic_term;
mod full_term;
mod null_ui;

#[derive(Parser, Debug, Clone)]
pub(crate) struct UiArgs {
/// What kind of user interface to use.
#[clap(long, default_value = "full")]
ui: Kind,
}

#[derive(ValueEnum, Debug, Clone, Copy)]
enum Kind {
#[derive(ValueEnum, Debug, Clone, Copy, Default)]
pub(crate) enum Kind {
#[default]
None,
#[cfg(feature = "ui")]
Basic,
Expand Down Expand Up @@ -93,12 +86,14 @@ impl Args {

fn ui_kind(&self) -> Kind {
match &self.command {
Command::Check => Kind::None,
#[cfg(not(feature = "ui"))]
None => Kind::None,
Some(Command::Check) => Kind::None,
#[cfg(feature = "ui")]
Command::Ui(ui_args) => ui_args.ui,
Command::Summary(..) => Kind::None,
Command::Cargo(..) => Kind::None,
Command::ProxyBin(..) => Kind::None,
None | Some(Command::Ui) => self.ui,
Some(Command::Summary(..)) => Kind::None,
Some(Command::Cargo(..)) => Kind::None,
Some(Command::ProxyBin(..)) => Kind::None,
}
}
}
2 changes: 1 addition & 1 deletion src/ui/null_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl super::UserInterface for NullUi {
let mut has_errors = false;
for (_, problem) in pstore.deduplicated_into_iter() {
let mut severity = problem.severity();
if matches!(self.args.command, crate::Command::Cargo(..))
if matches!(self.args.command, Some(crate::Command::Cargo(..)))
&& severity == Severity::Warning
{
// When running `cackle cargo x`, not everything will be analysed, so
Expand Down

0 comments on commit 6a5a327

Please sign in to comment.