Completions (#1029)

* Handle `shell-completions` before anything else

* Update CHANGELOG.md
This commit is contained in:
Rayzeq 2024-02-20 22:42:09 +01:00 committed by GitHub
parent 387d344690
commit d96586c209
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 18 additions and 11 deletions

View file

@ -4,6 +4,9 @@ All notable changes to eww will be listed here, starting at changes since versio
## Unreleased ## Unreleased
### Fixes
- The `shell-completions` subcommand is now run before anything is set up
## [0.5.0] (17.02.2024) ## [0.5.0] (17.02.2024)
### BREAKING CHANGES ### BREAKING CHANGES

View file

@ -6,7 +6,6 @@ use crate::{
paths::EwwPaths, paths::EwwPaths,
}; };
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::CommandFactory as _;
use std::{ use std::{
io::{Read, Write}, io::{Read, Write},
os::unix::net::UnixStream, os::unix::net::UnixStream,
@ -21,9 +20,6 @@ pub fn handle_client_only_action(paths: &EwwPaths, action: ActionClientOnly) ->
.spawn()? .spawn()?
.wait()?; .wait()?;
} }
ActionClientOnly::ShellCompletions { shell } => {
clap_complete::generate(shell, &mut opts::RawOpt::command(), "eww", &mut std::io::stdout());
}
} }
Ok(()) Ok(())
} }

View file

@ -5,6 +5,7 @@ extern crate gtk;
extern crate gtk_layer_shell as gtk_layer_shell; extern crate gtk_layer_shell as gtk_layer_shell;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::CommandFactory as _;
use daemon_response::{DaemonResponse, DaemonResponseReceiver}; use daemon_response::{DaemonResponse, DaemonResponseReceiver};
use display_backend::DisplayBackend; use display_backend::DisplayBackend;
use opts::ActionWithServer; use opts::ActionWithServer;
@ -44,6 +45,11 @@ fn main() {
pretty_env_logger::formatted_timed_builder().filter(Some("eww"), log_level_filter).init(); pretty_env_logger::formatted_timed_builder().filter(Some("eww"), log_level_filter).init();
} }
if let opts::Action::ShellCompletions { shell } = opts.action {
clap_complete::generate(shell, &mut opts::RawOpt::command(), "eww", &mut std::io::stdout());
return;
}
#[allow(unused)] #[allow(unused)]
let use_wayland = opts.force_wayland || detect_wayland(); let use_wayland = opts.force_wayland || detect_wayland();
#[cfg(all(feature = "wayland", feature = "x11"))] #[cfg(all(feature = "wayland", feature = "x11"))]
@ -87,6 +93,7 @@ fn run<B: DisplayBackend>(opts: opts::Opt, eww_binary_name: String, display_back
.context("Failed to initialize eww paths")?; .context("Failed to initialize eww paths")?;
let should_restart = match &opts.action { let should_restart = match &opts.action {
opts::Action::ShellCompletions { .. } => unreachable!(),
opts::Action::Daemon => opts.restart, opts::Action::Daemon => opts.restart,
opts::Action::WithServer(action) => opts.restart && action.can_start_daemon(), opts::Action::WithServer(action) => opts.restart && action.can_start_daemon(),
opts::Action::ClientOnly(_) => false, opts::Action::ClientOnly(_) => false,
@ -100,6 +107,7 @@ fn run<B: DisplayBackend>(opts: opts::Opt, eww_binary_name: String, display_back
} }
let would_show_logs = match opts.action { let would_show_logs = match opts.action {
opts::Action::ShellCompletions { .. } => unreachable!(),
opts::Action::ClientOnly(action) => { opts::Action::ClientOnly(action) => {
client::handle_client_only_action(&paths, action)?; client::handle_client_only_action(&paths, action)?;
false false

View file

@ -59,6 +59,13 @@ pub(super) struct RawOpt {
#[derive(Subcommand, Debug, Serialize, Deserialize, PartialEq)] #[derive(Subcommand, Debug, Serialize, Deserialize, PartialEq)]
pub enum Action { pub enum Action {
/// Generate a shell completion script
ShellCompletions {
#[arg(short, long)]
#[serde(with = "serde_shell")]
shell: clap_complete::shells::Shell,
},
/// Start the Eww daemon. /// Start the Eww daemon.
#[command(name = "daemon", alias = "d")] #[command(name = "daemon", alias = "d")]
Daemon, Daemon,
@ -75,13 +82,6 @@ pub enum ActionClientOnly {
/// Print and watch the eww logs /// Print and watch the eww logs
#[command(name = "logs")] #[command(name = "logs")]
Logs, Logs,
/// Generate a shell completion script
ShellCompletions {
#[arg(short, long)]
#[serde(with = "serde_shell")]
shell: clap_complete::shells::Shell,
},
} }
#[derive(Subcommand, Debug, Serialize, Deserialize, PartialEq)] #[derive(Subcommand, Debug, Serialize, Deserialize, PartialEq)]