feat: full poc
This commit is contained in:
parent
b76036038e
commit
a8847b93cf
14 changed files with 630 additions and 323 deletions
12
cli/Cargo.toml
Normal file
12
cli/Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "tagctl"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
nix = { version = "0.30", features = ["process", "user"] }
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
niri-tag = { path = "../lib" }
|
59
cli/main.rs
Normal file
59
cli/main.rs
Normal file
|
@ -0,0 +1,59 @@
|
|||
use anyhow::{Context, Result, anyhow};
|
||||
use clap::{Parser, Subcommand};
|
||||
use niri_tag::TagCmd;
|
||||
use nix::unistd::geteuid;
|
||||
use std::{io::Write, os::unix::net::UnixStream};
|
||||
|
||||
#[derive(Parser)]
|
||||
#[command(name = "tagctl")]
|
||||
#[command(about = "ipc wrapper for niri-tag")]
|
||||
struct Cli {
|
||||
#[command(subcommand)]
|
||||
cmd: Commands,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Subcommand)]
|
||||
enum Commands {
|
||||
Add { tag: u8 },
|
||||
Remove { tag: u8 },
|
||||
Toggle { tag: u8 },
|
||||
Enable { tag: u8 },
|
||||
Disable { tag: u8 },
|
||||
ToggleWs { tag: u8 },
|
||||
}
|
||||
|
||||
impl From<Commands> for niri_tag::TagCmd {
|
||||
fn from(value: Commands) -> Self {
|
||||
match value {
|
||||
Commands::Add { tag } => TagCmd::Add(tag),
|
||||
Commands::Remove { tag } => TagCmd::Remove(tag),
|
||||
Commands::Enable { tag } => TagCmd::Enable(tag),
|
||||
Commands::Disable { tag } => TagCmd::Disable(tag),
|
||||
Commands::Toggle { tag } => TagCmd::Toggle(tag),
|
||||
Commands::ToggleWs { tag } => TagCmd::ToggleWs(tag),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let cli = Cli::parse();
|
||||
use Commands::*;
|
||||
|
||||
println!("{:?}", cli.cmd);
|
||||
match cli.cmd {
|
||||
Add { tag } if tag > 0 => (),
|
||||
Remove { tag } if tag > 0 => (),
|
||||
Enable { tag } if tag > 0 => (),
|
||||
Disable { tag } if tag > 0 => (),
|
||||
Toggle { tag } if tag > 0 => (),
|
||||
ToggleWs { tag } if tag > 0 => (),
|
||||
_ => return Err(anyhow!("Can't change tag 0!")),
|
||||
};
|
||||
|
||||
let cmd = TagCmd::from(cli.cmd);
|
||||
|
||||
let mut ipc = UnixStream::connect(format!("/run/user/{}/niri-tag.sock", geteuid()))
|
||||
.context("Connecting to niri-tag ipc socket")?;
|
||||
ipc.write_all(serde_json::to_string(&cmd)?.as_bytes())?;
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue