pub struct BashArityDict { /* private fields */ }Expand description
Arity dictionary for bash command-prefix allow rules.
Provides arity-aware prefix extraction so that auto_allow = ["git status"]
correctly matches git status -s and git status --porcelain without
also matching git push.
§Example
use codewhale_execpolicy::bash_arity::BashArityDict;
let dict = BashArityDict::new();
assert_eq!(dict.classify(&["git", "status", "-s"]), "git status");
assert_eq!(dict.classify(&["git", "push", "origin"]), "git push");
assert_eq!(dict.classify(&["npm", "run", "dev"]), "npm run dev");
assert_eq!(dict.classify(&["ls", "-la"]), "ls");Implementations§
Source§impl BashArityDict
impl BashArityDict
Sourcepub fn new() -> Self
pub fn new() -> Self
Construct a new dictionary pre-loaded with BASH_ARITY_TABLE.
Sourcepub fn classify(&self, tokens: &[&str]) -> String
pub fn classify(&self, tokens: &[&str]) -> String
Return the canonical command prefix for a slice of command tokens.
§Algorithm
- Strip all flag tokens (tokens that start with
-). - Build candidates of depth 1..=3 from positional tokens (longest first).
- If a candidate matches a dictionary entry, return
aritypositional tokens joined with spaces. - If no dictionary entry matches, return the single base command name.
Sourcepub fn allow_rule_matches(&self, pattern: &str, command: &str) -> bool
pub fn allow_rule_matches(&self, pattern: &str, command: &str) -> bool
Return true if the allow-rule pattern (a command prefix string such
as "git status") matches the concrete command command.
Matching is arity-aware:
"git status"matches"git status -s"and"git status --porcelain"."git status"does not match"git push origin main".- Exact string patterns (e.g.
"ls") still work as before.
For patterns that are not in the arity table, the function falls back to a plain prefix test on the normalised command so that existing exact-match rules continue to work unchanged.
Trait Implementations§
Source§impl Clone for BashArityDict
impl Clone for BashArityDict
Source§fn clone(&self) -> BashArityDict
fn clone(&self) -> BashArityDict
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BashArityDict
impl Debug for BashArityDict
Auto Trait Implementations§
impl Freeze for BashArityDict
impl RefUnwindSafe for BashArityDict
impl Send for BashArityDict
impl Sync for BashArityDict
impl Unpin for BashArityDict
impl UnsafeUnpin for BashArityDict
impl UnwindSafe for BashArityDict
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more