pub struct OperationContext { /* private fields */ }Expand description
Context for a single CLI operation (install, update, validate, etc.)
This context object flows through the operation call chain, providing
operation-scoped state like warning deduplication. It uses Mutex
for interior mutability to support async operations that may span
multiple threads.
§Thread Safety
This struct is thread-safe and can be shared across async .await points.
Uses Mutex for interior mutability, which has minimal overhead since
contention is unlikely (warnings are infrequent).
§Lifecycle
- Created at the start of a CLI command (
InstallCommand::execute(), etc.) - Passed down through resolver → extractor → parser call chain
- Automatically cleaned up when the operation completes
§Examples
use agpm_cli::core::OperationContext;
use std::path::Path;
// Create context at operation start
let ctx = OperationContext::new();
// Use for warning deduplication
if ctx.should_warn_file(Path::new("invalid.md")) {
eprintln!("Warning: Invalid file");
}
// Same file won't warn again
assert!(!ctx.should_warn_file(Path::new("invalid.md")));Implementations§
Source§impl OperationContext
impl OperationContext
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new operation context.
Call this at the start of each CLI operation that needs state tracking.
§Examples
use agpm_cli::core::OperationContext;
let ctx = OperationContext::new();Sourcepub fn should_warn_file(&self, path: &Path) -> bool
pub fn should_warn_file(&self, path: &Path) -> bool
Check if we should warn about a file and mark it as warned.
Returns true if this is the first warning for this file in this operation,
false if we’ve already warned about it (deduplicated).
§Deduplication Strategy
Uses filename-based keys (not full paths) to handle different path representations consistently:
/foo/bar/test.mdand./bar/test.mdboth key on"test.md"- This works across worktrees, relative paths, and symlinks
§Arguments
path- Path to the file being processed
§Returns
true- First warning for this file, caller should display the warningfalse- Already warned about this file, caller should skip the warning
§Examples
use agpm_cli::core::OperationContext;
use std::path::Path;
let ctx = OperationContext::new();
let path = Path::new("agents/invalid.md");
// First call returns true
assert!(ctx.should_warn_file(path));
// Second call returns false (deduplicated)
assert!(!ctx.should_warn_file(path));Sourcepub fn warning_count(&self) -> usize
pub fn warning_count(&self) -> usize
Get the count of unique files that have been warned about.
Useful for diagnostics and testing.
§Examples
use agpm_cli::core::OperationContext;
use std::path::Path;
let ctx = OperationContext::new();
assert_eq!(ctx.warning_count(), 0);
ctx.should_warn_file(Path::new("file1.md"));
ctx.should_warn_file(Path::new("file2.md"));
assert_eq!(ctx.warning_count(), 2);Trait Implementations§
Source§impl Debug for OperationContext
impl Debug for OperationContext
Source§impl Default for OperationContext
impl Default for OperationContext
Source§fn default() -> OperationContext
fn default() -> OperationContext
Auto Trait Implementations§
impl !Freeze for OperationContext
impl RefUnwindSafe for OperationContext
impl Send for OperationContext
impl Sync for OperationContext
impl Unpin for OperationContext
impl UnwindSafe for OperationContext
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more