pub struct ConfigService;Expand description
Configuration service for project configuration management
§Examples
use mecha10_cli::services::ConfigService;
use std::path::PathBuf;
// Load from specific path
let config = ConfigService::load_from(&PathBuf::from("custom.json")).await?;
println!("Robot ID: {}", config.robot.id);
// Find config in current or parent directories
let config_path = ConfigService::find_config()?;Implementations§
Source§impl ConfigService
impl ConfigService
Sourcepub fn find_config() -> Result<PathBuf, Error>
pub fn find_config() -> Result<PathBuf, Error>
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 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 fn resolve_and_validate(path: Option<&Path>) -> Result<PathBuf, Error>
pub fn resolve_and_validate(path: Option<&Path>) -> Result<PathBuf, Error>
Resolve the config file to validate and validate it – the single
implementation shared by mecha10 config validate and the config-validation
step in mecha10 lint, so neither re-implements this logic locally.
pathisNone(the default): finds the project’smecha10.jsonviaSelf::find_configand validates it plus every node config it references (viamecha10_core::schema_validation::validate_project_config).pathisSome: validates exactly that one file, auto-detecting whether it’s a project config or a node config (viamecha10_core::schema_validation::validate_config_file) – no recursion into other files. This is the mode a git hook uses to check only the files staged in a commit.
§Returns
The path that was validated, so callers can report it.
§Errors
Returns an error with the underlying schema-validation failure details if the target file doesn’t exist or fails validation.
Sourcepub fn resolve_and_validate_with_node_schema_resolver(
path: Option<&Path>,
node_schema_resolver: Option<&dyn Fn(&Value) -> Option<Value>>,
) -> Result<PathBuf, Error>
pub fn resolve_and_validate_with_node_schema_resolver( path: Option<&Path>, node_schema_resolver: Option<&dyn Fn(&Value) -> Option<Value>>, ) -> Result<PathBuf, Error>
Same as Self::resolve_and_validate, but lets a caller supply a
mecha10_core::schema_validation::NodeSchemaResolver so each referenced
node config validates against a node-type-specific schema instead of the
generic envelope (LAB-1772).
This crate can’t construct a resolver itself – doing so needs each node’s
concrete config struct, and mecha10-cli-core can’t depend on
packages/nodes/* (see docs/validate-configs.md) – so it only accepts one
as a parameter. packages/cli builds the actual resolver (via
mecha10-schema-registry, which can depend on the node crates) and passes
it in here.
§Errors
Returns an error with the underlying schema-validation failure details if the target file doesn’t exist or fails validation.
Auto Trait Implementations§
impl Freeze for ConfigService
impl RefUnwindSafe for ConfigService
impl Send for ConfigService
impl Sync for ConfigService
impl Unpin for ConfigService
impl UnsafeUnpin for ConfigService
impl UnwindSafe for ConfigService
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