From 2b81f0ed08928da4b14b07ed99a18c11e7582a8b Mon Sep 17 00:00:00 2001 From: Reilly Wood Date: Wed, 28 Feb 2024 23:01:18 -0800 Subject: [PATCH] Fix failure to launch on WSL --- Cargo.lock | 1 + Cargo.toml | 1 + src/main.rs | 19 ++++++++++++------- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8e59bfb..148c498 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1738,6 +1738,7 @@ dependencies = [ "env_logger", "futures", "indexmap", + "is-wsl", "itertools", "lazy_static", "libc", diff --git a/Cargo.toml b/Cargo.toml index 92a777f..0b143a2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -58,6 +58,7 @@ clipboard-anywhere = "0.2.2" chrono = { version = "0.4.31", default-features = false } lazy_static = "1.4.0" nix = { version = "0.27.1", features = ["user"] } +is-wsl = "0.4.0" # build with `cargo build --profile profiling` # to analyze performance with tooling like perf / samply / superluminal diff --git a/src/main.rs b/src/main.rs index 4fd790e..b9a6a32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,9 +10,9 @@ use systemctl_tui::{ #[derive(Parser, Debug)] #[command(version = version(), about = "A simple TUI for systemd services")] struct Args { - /// The scope of the services to display - #[clap(short, long, default_value = "all")] - scope: Scope, + /// The scope of the services to display. Defaults to "all" normally and "global" on WSL + #[clap(short, long)] + scope: Option, /// Enable performance tracing (in Chromium Event JSON format) #[clap(short, long)] trace: bool, @@ -36,13 +36,18 @@ async fn main() -> Result<()> { initialize_logging(args.trace)?; initialize_panic_handler(); - // There's probably a nicer way to do this than defining scope in separate places, but this is fine for now + // There's probably a nicer way to do this than defining the scope enum twice, but this is fine for now let scope = match args.scope { - Scope::Global => systemd::Scope::Global, - Scope::User => systemd::Scope::User, - Scope::All => systemd::Scope::All, + Some(Scope::Global) => systemd::Scope::Global, + Some(Scope::User) => systemd::Scope::User, + Some(Scope::All) => systemd::Scope::All, + // So, WSL doesn't *really* support user services yet: https://github.com/microsoft/WSL/issues/8842 + // Revisit this if that changes + None => if is_wsl::is_wsl() { systemd::Scope::Global } else { systemd::Scope::All }, }; + eprintln!("Using scope: {:?}", scope); + let mut app = App::new(scope)?; app.run().await?;