fix: correct awww subcommand to img, support bare path arg, add --version
This commit is contained in:
parent
b064e86f2f
commit
5c9efcf316
2 changed files with 12 additions and 8 deletions
16
src/main.rs
16
src/main.rs
|
|
@ -4,17 +4,19 @@ use std::process;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "breadpaper", about = "Wallpaper manager for the bread desktop")]
|
#[command(name = "breadpaper", version, about = "Wallpaper manager for the bread desktop")]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
/// Image file to set as wallpaper (shorthand for `set`)
|
||||||
|
path: Option<PathBuf>,
|
||||||
|
|
||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
command: Command,
|
command: Option<Command>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
enum Command {
|
enum Command {
|
||||||
/// Set wallpaper, generate pywal palette, and reload bread themes
|
/// Set wallpaper, generate pywal palette, and reload bread themes
|
||||||
Set {
|
Set {
|
||||||
/// Path to the image file
|
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
},
|
},
|
||||||
/// Print the current wallpaper path
|
/// Print the current wallpaper path
|
||||||
|
|
@ -24,9 +26,11 @@ enum Command {
|
||||||
fn main() {
|
fn main() {
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
|
|
||||||
let result = match cli.command {
|
let result = match (cli.command, cli.path) {
|
||||||
Command::Set { path } => breadpaper::set(&path),
|
(Some(Command::Set { path }), _) | (None, Some(path)) => breadpaper::set(&path),
|
||||||
Command::Get => breadpaper::get().map(|p| println!("{}", p.display())),
|
(Some(Command::Get), _) | (None, None) => {
|
||||||
|
breadpaper::get().map(|p| println!("{}", p.display()))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Err(e) = result {
|
if let Err(e) = result {
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ use anyhow::{Context, Result, bail};
|
||||||
|
|
||||||
pub fn apply(path: &Path) -> Result<()> {
|
pub fn apply(path: &Path) -> Result<()> {
|
||||||
let status = Command::new("awww")
|
let status = Command::new("awww")
|
||||||
.arg("set")
|
.arg("img")
|
||||||
.arg(path)
|
.arg(path)
|
||||||
.status()
|
.status()
|
||||||
.context("failed to run awww — is awww-daemon running?")?;
|
.context("failed to run awww — is awww-daemon running?")?;
|
||||||
|
|
||||||
if !status.success() {
|
if !status.success() {
|
||||||
bail!("awww set exited with {}", status);
|
bail!("awww img exited with {}", status);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue