pub struct ConfigService;Expand description
Configuration service for project configuration management
§Examples
use mecha10_cli::services::ConfigService;
use std::path::PathBuf;
// Load config from default location
let config = ConfigService::load_default().await?;
println!("Robot ID: {}", config.robot.id);
// Load from specific path
let config = ConfigService::load_from(&PathBuf::from("custom.json")).await?;
// Find config in current or parent directories
let config_path = ConfigService::find_config()?;Implementations§
Source§impl ConfigService
impl ConfigService
Sourcepub async fn load_default() -> Result<ProjectConfig>
pub async fn load_default() -> Result<ProjectConfig>
Load project configuration from the default location (mecha10.json)
§Errors
Returns an error if:
- The file doesn’t exist
- The file cannot be read
- The JSON is invalid
- The configuration doesn’t match the expected schema
Sourcepub async fn load_from(path: &Path) -> Result<ProjectConfig>
pub async fn load_from(path: &Path) -> Result<ProjectConfig>
Sourcepub fn find_config() -> Result<PathBuf>
pub fn find_config() -> Result<PathBuf>
Find mecha10.json in the current directory or any parent directory
Searches upward from the current working directory until it finds a mecha10.json file or reaches the root directory.
§Returns
Returns the path to the found configuration file.
§Errors
Returns an error if no mecha10.json file is found in the current directory or any parent directory.
Sourcepub fn find_config_from(start_dir: &Path) -> Result<PathBuf>
pub fn find_config_from(start_dir: &Path) -> Result<PathBuf>
Sourcepub fn is_initialized(dir: &Path) -> bool
pub fn is_initialized(dir: &Path) -> bool
Sourcepub fn is_initialized_here() -> bool
pub fn is_initialized_here() -> bool
Check if a project is initialized in the current directory
Sourcepub async fn load_robot_id(path: &Path) -> Result<String>
pub async fn load_robot_id(path: &Path) -> Result<String>
Sourcepub fn default_config_paths() -> Vec<PathBuf>
pub fn default_config_paths() -> Vec<PathBuf>
Get the default config paths to try in order
Returns a list of paths that are commonly used for configuration files.
Sourcepub async fn try_load_from_defaults() -> Result<(PathBuf, ProjectConfig)>
pub async fn try_load_from_defaults() -> Result<(PathBuf, ProjectConfig)>
Try to load configuration from any of the default paths
Attempts to load configuration from each default path in order until one succeeds.
§Errors
Returns an error if none of the default paths contain a valid config.
Auto Trait Implementations§
impl Freeze for ConfigService
impl RefUnwindSafe for ConfigService
impl Send for ConfigService
impl Sync for ConfigService
impl Unpin for ConfigService
impl UnwindSafe for ConfigService
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§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