GlobalConfigManager

Struct GlobalConfigManager 

Source
pub struct GlobalConfigManager { /* private fields */ }
Expand description

Configuration manager with caching for global configuration.

Provides a higher-level interface for working with global configuration that includes caching to avoid repeated file I/O operations. This is particularly useful in command-line applications that may access configuration multiple times.

§Features

  • Lazy Loading: Configuration is loaded only when first accessed
  • Caching: Subsequent accesses use the cached configuration
  • Reload Support: Can reload from disk when needed
  • Custom Paths: Supports custom configuration file paths for testing

§Examples

§Basic Usage

use agpm_cli::config::GlobalConfigManager;

let mut manager = GlobalConfigManager::new()?;

// First access loads from disk
let config = manager.get().await?;
println!("Found {} sources", config.sources.len());

// Subsequent accesses use cache
let config2 = manager.get().await?;

§Modifying Configuration

use agpm_cli::config::GlobalConfigManager;

let mut manager = GlobalConfigManager::new()?;

// Get mutable reference
let config = manager.get_mut().await?;
config.add_source(
    "new".to_string(),
    "https://github.com/owner/repo.git".to_string()
);

// Save changes to disk
manager.save().await?;

Implementations§

Source§

impl GlobalConfigManager

Source

pub fn new() -> Result<Self>

Create a new configuration manager using the default global config path.

The manager will use the platform-appropriate default location for the global configuration file.

§Examples
use agpm_cli::config::GlobalConfigManager;

let manager = GlobalConfigManager::new()?;
§Errors

Returns an error if the default configuration path cannot be determined.

Source

pub const fn with_path(path: PathBuf) -> Self

Create a configuration manager with a custom file path.

This method is primarily useful for testing or when you need to use a non-standard location for the configuration file.

§Parameters
  • path: Custom path for the configuration file
§Examples
use agpm_cli::config::GlobalConfigManager;
use std::path::PathBuf;

let manager = GlobalConfigManager::with_path(PathBuf::from("/tmp/test.toml"));
Source

pub async fn get(&mut self) -> Result<&GlobalConfig>

Get a reference to the global configuration, loading it if necessary.

If the configuration hasn’t been loaded yet, this method will load it from disk. Subsequent calls will return the cached configuration.

§Returns

A reference to the cached GlobalConfig.

§Examples
use agpm_cli::config::GlobalConfigManager;

let mut manager = GlobalConfigManager::new()?;
let config = manager.get().await?;
println!("Global config has {} sources", config.sources.len());
§Errors

Returns an error if:

  • The configuration file exists but cannot be read
  • The configuration file contains invalid TOML syntax
Source

pub async fn get_mut(&mut self) -> Result<&mut GlobalConfig>

Get a mutable reference to the global configuration, loading it if necessary.

Similar to get, but returns a mutable reference allowing modification of the configuration.

§Returns

A mutable reference to the cached GlobalConfig.

§Examples
use agpm_cli::config::GlobalConfigManager;

let mut manager = GlobalConfigManager::new()?;
let config = manager.get_mut().await?;

config.add_source(
    "new".to_string(),
    "https://github.com/owner/repo.git".to_string()
);
§Errors

Returns an error if:

  • The configuration file exists but cannot be read
  • The configuration file contains invalid TOML syntax
Source

pub async fn save(&self) -> Result<()>

Save the current cached configuration to disk.

Writes the current configuration state to the file system. If no configuration has been loaded, this method does nothing.

§Examples
use agpm_cli::config::GlobalConfigManager;

let mut manager = GlobalConfigManager::new()?;

// Modify configuration
let config = manager.get_mut().await?;
config.add_source("test".to_string(), "https://test.com/repo.git".to_string());

// Save changes
manager.save().await?;
§Errors

Returns an error if:

  • The file cannot be written (permissions, disk space, etc.)
  • Parent directories cannot be created
Source

pub async fn reload(&mut self) -> Result<()>

Reload the configuration from disk, discarding cached data.

Forces a reload of the configuration from the file system, discarding any cached data. Useful when the configuration file may have been modified externally.

§Examples
use agpm_cli::config::GlobalConfigManager;

let mut manager = GlobalConfigManager::new()?;

// Load initial configuration
let config1 = manager.get().await?;
let count1 = config1.sources.len();

// Configuration file modified externally...

// Reload to pick up external changes
manager.reload().await?;
let config2 = manager.get().await?;
let count2 = config2.sources.len();
§Errors

Returns an error if:

  • The configuration file exists but cannot be read
  • The configuration file contains invalid TOML syntax

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more