Skip to content

Commit

Permalink
buck2: remove some code duplication
Browse files Browse the repository at this point in the history
Summary: Makes the next diff easier.

Reviewed By: IanChilds

Differential Revision: D39810491

fbshipit-source-id: 53cbf4352402cdfeae672427756c12a221b68d62
  • Loading branch information
krallin authored and facebook-github-bot committed Sep 26, 2022
1 parent 34a238c commit f72ed01
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 42 deletions.
7 changes: 1 addition & 6 deletions buck2_client/src/commands/debug/allocator_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::commands::streaming::StreamingCommand;
use crate::common::CommonBuildConfigurationOptions;
use crate::common::CommonConsoleOptions;
use crate::common::CommonDaemonCommandOptions;
use crate::common::ConsoleType;
use crate::daemon::client::connect::BuckdConnectOptions;
use crate::daemon::client::BuckdClientConnector;
use crate::exit_result::ExitResult;
Expand Down Expand Up @@ -59,11 +58,7 @@ impl StreamingCommand for AllocatorStatsCommand {
}

fn console_opts(&self) -> &CommonConsoleOptions {
static OPTS: CommonConsoleOptions = CommonConsoleOptions {
console_type: ConsoleType::None,
ui: vec![],
};
&OPTS
CommonConsoleOptions::none_ref()
}

fn event_log_opts(&self) -> &CommonDaemonCommandOptions {
Expand Down
7 changes: 1 addition & 6 deletions buck2_client/src/commands/debug/crash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::commands::streaming::StreamingCommand;
use crate::common::CommonBuildConfigurationOptions;
use crate::common::CommonConsoleOptions;
use crate::common::CommonDaemonCommandOptions;
use crate::common::ConsoleType;
use crate::daemon::client::connect::BuckdConnectOptions;
use crate::daemon::client::BuckdClientConnector;
use crate::exit_result::ExitResult;
Expand Down Expand Up @@ -48,11 +47,7 @@ impl StreamingCommand for CrashCommand {
}

fn console_opts(&self) -> &CommonConsoleOptions {
static OPTS: CommonConsoleOptions = CommonConsoleOptions {
console_type: ConsoleType::Simple,
ui: vec![],
};
&OPTS
CommonConsoleOptions::simple_ref()
}

fn event_log_opts(&self) -> &CommonDaemonCommandOptions {
Expand Down
7 changes: 1 addition & 6 deletions buck2_client/src/commands/debug/dice_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use crate::commands::streaming::StreamingCommand;
use crate::common::CommonBuildConfigurationOptions;
use crate::common::CommonConsoleOptions;
use crate::common::CommonDaemonCommandOptions;
use crate::common::ConsoleType;
use crate::daemon::client::connect::BuckdConnectOptions;
use crate::daemon::client::BuckdClientConnector;
use crate::exit_result::ExitResult;
Expand Down Expand Up @@ -63,11 +62,7 @@ impl StreamingCommand for DiceDumpCommand {
}

fn console_opts(&self) -> &CommonConsoleOptions {
static OPTS: CommonConsoleOptions = CommonConsoleOptions {
console_type: ConsoleType::None,
ui: vec![],
};
&OPTS
CommonConsoleOptions::none_ref()
}

fn event_log_opts(&self) -> &CommonDaemonCommandOptions {
Expand Down
7 changes: 1 addition & 6 deletions buck2_client/src/commands/debug/flush_dep_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::commands::streaming::StreamingCommand;
use crate::common::CommonBuildConfigurationOptions;
use crate::common::CommonConsoleOptions;
use crate::common::CommonDaemonCommandOptions;
use crate::common::ConsoleType;
use crate::daemon::client::connect::BuckdConnectOptions;
use crate::daemon::client::BuckdClientConnector;
use crate::exit_result::ExitResult;
Expand Down Expand Up @@ -48,11 +47,7 @@ impl StreamingCommand for FlushDepFilesCommand {
}

fn console_opts(&self) -> &CommonConsoleOptions {
static OPTS: CommonConsoleOptions = CommonConsoleOptions {
console_type: ConsoleType::Simple,
ui: vec![],
};
&OPTS
CommonConsoleOptions::simple_ref()
}

fn event_log_opts(&self) -> &CommonDaemonCommandOptions {
Expand Down
7 changes: 1 addition & 6 deletions buck2_client/src/commands/debug/heap_dump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::commands::streaming::StreamingCommand;
use crate::common::CommonBuildConfigurationOptions;
use crate::common::CommonConsoleOptions;
use crate::common::CommonDaemonCommandOptions;
use crate::common::ConsoleType;
use crate::daemon::client::connect::BuckdConnectOptions;
use crate::daemon::client::BuckdClientConnector;
use crate::exit_result::ExitResult;
Expand Down Expand Up @@ -54,11 +53,7 @@ impl StreamingCommand for HeapDumpCommand {
}

fn console_opts(&self) -> &CommonConsoleOptions {
static OPTS: CommonConsoleOptions = CommonConsoleOptions {
console_type: ConsoleType::None,
ui: vec![],
};
&OPTS
CommonConsoleOptions::none_ref()
}

fn event_log_opts(&self) -> &CommonDaemonCommandOptions {
Expand Down
7 changes: 1 addition & 6 deletions buck2_client/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ use crate::commands::streaming::StreamingCommand;
use crate::common::CommonBuildConfigurationOptions;
use crate::common::CommonConsoleOptions;
use crate::common::CommonDaemonCommandOptions;
use crate::common::ConsoleType;
use crate::daemon::client::connect::BuckdConnectOptions;
use crate::daemon::client::BuckdClientConnector;
use crate::exit_result::ExitResult;
Expand Down Expand Up @@ -168,11 +167,7 @@ impl StreamingCommand for RageCommand {
}

fn console_opts(&self) -> &CommonConsoleOptions {
static OPTS: CommonConsoleOptions = CommonConsoleOptions {
console_type: ConsoleType::Simple,
ui: vec![],
};
&OPTS
CommonConsoleOptions::simple_ref()
}

fn event_log_opts(&self) -> &CommonDaemonCommandOptions {
Expand Down
7 changes: 1 addition & 6 deletions buck2_client/src/commands/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use crate::commands::streaming::StreamingCommand;
use crate::common::CommonBuildConfigurationOptions;
use crate::common::CommonConsoleOptions;
use crate::common::CommonDaemonCommandOptions;
use crate::common::ConsoleType;
use crate::daemon::client::BuckdClientConnector;
use crate::exit_result::ExitResult;

Expand All @@ -39,11 +38,7 @@ impl StreamingCommand for ServerCommand {
}

fn console_opts(&self) -> &CommonConsoleOptions {
static OPTS: CommonConsoleOptions = CommonConsoleOptions {
console_type: ConsoleType::Simple,
ui: vec![],
};
&OPTS
CommonConsoleOptions::simple_ref()
}

fn event_log_opts(&self) -> &CommonDaemonCommandOptions {
Expand Down
17 changes: 17 additions & 0 deletions buck2_client/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,23 @@ impl CommonConsoleOptions {
};
&OPTS
}

pub fn simple_ref() -> &'static Self {
static OPTS: CommonConsoleOptions = CommonConsoleOptions {
console_type: ConsoleType::Simple,
ui: vec![],
};
&OPTS
}

pub fn none_ref() -> &'static Self {
static OPTS: CommonConsoleOptions = CommonConsoleOptions {
console_type: ConsoleType::None,
ui: vec![],
};
&OPTS
}

pub fn final_console(&self) -> FinalConsole {
let is_tty = match self.console_type {
ConsoleType::Auto | ConsoleType::Simple => std::io::stderr().is_tty(),
Expand Down

0 comments on commit f72ed01

Please sign in to comment.