mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 18:18:55 +00:00
refactor(windows): move debug subcommands closer to their code and further from production subcommands (#3307)
This commit is contained in:
@@ -40,8 +40,8 @@ From this dir:
|
||||
RUST_LOG=info,firezone_windows_client=debug cargo tauri dev
|
||||
|
||||
# You can call debug subcommands on the exe from this directory too
|
||||
# e.g. this is equivalent to `cargo run -- debug`
|
||||
cargo tauri dev -- -- debug
|
||||
# e.g. this is equivalent to `cargo run -- debug hostname`
|
||||
cargo tauri dev -- -- debug hostname
|
||||
|
||||
# The exe is up in the workspace
|
||||
stat ../target/debug/firezone-windows-client.exe
|
||||
|
||||
@@ -110,14 +110,7 @@ pub(crate) fn run() -> Result<()> {
|
||||
}
|
||||
}
|
||||
Some(Cmd::CrashHandlerServer) => crash_handling::server(),
|
||||
Some(Cmd::Debug) => {
|
||||
println!("debug");
|
||||
Ok(())
|
||||
}
|
||||
Some(Cmd::DebugCrash) => debug_commands::crash(),
|
||||
Some(Cmd::DebugHostname) => debug_commands::hostname(),
|
||||
Some(Cmd::DebugNetworkChanges) => network_changes::run_debug(),
|
||||
Some(Cmd::DebugWintun) => debug_commands::wintun(cli),
|
||||
Some(Cmd::Debug { command }) => debug_commands::run(command),
|
||||
// If we already tried to elevate ourselves, don't try again
|
||||
Some(Cmd::Elevated) => gui::run(GuiParams {
|
||||
crash_on_purpose: cli.crash_on_purpose,
|
||||
@@ -134,23 +127,22 @@ pub(crate) fn run() -> Result<()> {
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
pub struct Cli {
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Option<Cmd>,
|
||||
command: Option<Cmd>,
|
||||
#[arg(long, hide = true)]
|
||||
pub crash_on_purpose: bool,
|
||||
crash_on_purpose: bool,
|
||||
#[arg(long, hide = true)]
|
||||
pub inject_faults: bool,
|
||||
inject_faults: bool,
|
||||
}
|
||||
|
||||
#[derive(clap::Subcommand)]
|
||||
pub enum Cmd {
|
||||
CrashHandlerServer,
|
||||
Debug,
|
||||
DebugCrash,
|
||||
DebugHostname,
|
||||
DebugNetworkChanges,
|
||||
DebugWintun,
|
||||
Debug {
|
||||
#[command(subcommand)]
|
||||
command: debug_commands::Cmd,
|
||||
},
|
||||
Elevated,
|
||||
OpenDeepLink(DeepLink),
|
||||
}
|
||||
|
||||
@@ -1,10 +1,26 @@
|
||||
//! CLI subcommands used to test features / dependencies before integrating
|
||||
//! them with the GUI, or to exercise features programmatically.
|
||||
|
||||
use crate::client::Cli;
|
||||
use anyhow::Result;
|
||||
|
||||
pub fn crash() -> Result<()> {
|
||||
#[derive(clap::Subcommand)]
|
||||
pub enum Cmd {
|
||||
Crash,
|
||||
Hostname,
|
||||
NetworkChanges,
|
||||
Wintun,
|
||||
}
|
||||
|
||||
pub fn run(cmd: Cmd) -> Result<()> {
|
||||
match cmd {
|
||||
Cmd::Crash => crash(),
|
||||
Cmd::Hostname => hostname(),
|
||||
Cmd::NetworkChanges => crate::client::network_changes::run_debug(),
|
||||
Cmd::Wintun => wintun(),
|
||||
}
|
||||
}
|
||||
|
||||
fn crash() -> Result<()> {
|
||||
// `_` doesn't seem to work here, the log files end up empty
|
||||
let _handles = crate::client::logging::setup("debug")?;
|
||||
tracing::info!("started log (DebugCrash)");
|
||||
@@ -12,7 +28,7 @@ pub fn crash() -> Result<()> {
|
||||
panic!("purposely crashing to see if it shows up in logs");
|
||||
}
|
||||
|
||||
pub fn hostname() -> Result<()> {
|
||||
fn hostname() -> Result<()> {
|
||||
println!(
|
||||
"{:?}",
|
||||
hostname::get().ok().and_then(|x| x.into_string().ok())
|
||||
@@ -20,7 +36,7 @@ pub fn hostname() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn wintun(_: Cli) -> Result<()> {
|
||||
fn wintun() -> Result<()> {
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
if crate::client::elevation::check()? {
|
||||
|
||||
Reference in New Issue
Block a user