1
0

add privilege checker

This commit is contained in:
2025-10-09 13:53:31 +08:00
parent 03a1796e07
commit 682be6ab58
7 changed files with 277 additions and 200 deletions

View File

@ -1,8 +1,22 @@
use clap::{Parser, Subcommand};
use std::process;
use wfassoc::{Program, RegisterKind, WfError};
use wfassoc::{Error as WfError};
use thiserror::Error as TeError;
type Result<T> = std::result::Result<T, WfError>;
// region: Basic Types
/// All errors occurs in this executable.
#[derive(TeError, Debug)]
enum Error {
/// Error from wfassoc core.
#[error("{0}")]
Core(#[from] WfError)
}
/// Result type used in this executable.
type Result<T> = std::result::Result<T, Error>;
// endregion
// region: Command Line Parser
@ -35,14 +49,14 @@ enum ForTarget {
System,
}
impl From<ForTarget> for RegisterKind {
fn from(target: ForTarget) -> Self {
match target {
ForTarget::User => RegisterKind::User,
ForTarget::System => RegisterKind::System,
}
}
}
// impl From<ForTarget> for RegisterKind {
// fn from(target: ForTarget) -> Self {
// match target {
// ForTarget::User => RegisterKind::User,
// ForTarget::System => RegisterKind::System,
// }
// }
// }
#[derive(Subcommand)]
enum Commands {
@ -62,19 +76,23 @@ enum Commands {
// region: Correponding Runner
fn run_register(cli: Cli) -> Result<()> {
let program = Program::new();
let kind: RegisterKind = cli.for_which.into();
program.register(kind)
// let program = Program::new();
// let kind: RegisterKind = cli.for_which.into();
// program.register(kind)?;
Ok(())
}
fn run_unregister(cli: Cli) -> Result<()> {
let program = Program::new();
program.unregister()
// let program = Program::new();
// program.unregister()?;
Ok(())
}
fn run_query(cli: Cli) -> Result<()> {
let program = Program::new();
program.query()
// let program = Program::new();
// program.query()?;
println!("Has privilege: {}", wfassoc::has_privilege());
Ok(())
}
// endregion