pub struct CliContext<'a> { /* private fields */ }Expand description
The resolved inputs a console command runs against.
Implementations§
Source§impl<'a> CliContext<'a>
impl<'a> CliContext<'a>
Sourcepub fn new(env: &'a dyn EnvVars) -> Self
pub fn new(env: &'a dyn EnvVars) -> Self
A context over env with no CLI overrides (file + env + defaults only).
Sourcepub fn with_database(self, database: impl Into<String>) -> Self
pub fn with_database(self, database: impl Into<String>) -> Self
Set the --database override (highest-precedence layer).
Sourcepub fn with_chain_id(self, chain_id: impl Into<String>) -> Self
pub fn with_chain_id(self, chain_id: impl Into<String>) -> Self
Set the --chain-id override.
Sourcepub fn with_node(self, uri: impl Into<String>, transport: NodeTransport) -> Self
pub fn with_node(self, uri: impl Into<String>, transport: NodeTransport) -> Self
Set one --node override: an explicit endpoint for the transport its
own value classified as (ADR-062 D6). The flag cannot name a transport
its value does not carry, so each occurrence fills exactly one slot.
Sourcepub fn with_node_overrides(self, nodes: NodeOverrides) -> Self
pub fn with_node_overrides(self, nodes: NodeOverrides) -> Self
Set every explicit endpoint at once (a caller that classified a whole
argv vector itself, e.g. the repeatable --node).
Sourcepub fn with_config(self, path: impl Into<String>) -> Self
pub fn with_config(self, path: impl Into<String>) -> Self
Set the --config override (the typed config file the strategy
verbs read and write).
Sourcepub fn database_override(&self) -> Option<&str>
pub fn database_override(&self) -> Option<&str>
The --database override, if any.
Sourcepub fn node_overrides(&self) -> &NodeOverrides
pub fn node_overrides(&self) -> &NodeOverrides
The explicit node endpoints the argv facade threaded in.
Sourcepub fn config_file(&self) -> Option<PathBuf>
pub fn config_file(&self) -> Option<PathBuf>
The config file the driver-domain resolvers read: the --config
override when given, else the standard path — DEGENBOT_CONFIG (honored
even when the file is missing: the operator asked for it) else the
XDG/HOME config file when it exists. None means the context has no
file layer at all, which is contractually the schema defaults.
Sourcepub fn loaded_config(&self) -> Result<&LoadedConfig, CliError>
pub fn loaded_config(&self) -> Result<&LoadedConfig, CliError>
The four layers loaded once per context: the file layer
(Self::config_file) over the env seam, plus the declared defaults.
Every driver-domain resolver reads this value, so a command resolves
its database path, chain id, and endpoints against ONE load.
§Errors
crate::error::CliError::Config carrying the loader’s fail-closed
degenbot_config::ConfigError when a file the operator named is
unreadable, unparsable, or holds an invalid value.
Sourcepub fn database_path(&self) -> Result<Resolved<PathBuf>, CliError>
pub fn database_path(&self) -> Result<Resolved<PathBuf>, CliError>
Resolve the database path: --database > DEGENBOT_DB_PATH >
database.path > the state-home default. The env seam supplies
HOME / $XDG_STATE_HOME for the ~ expansion of the default.
§Errors
crate::error::CliError::Config when the context’s config layers do
not load.
Sourcepub fn chain_id(&self) -> Result<Resolved<u64>, CliError>
pub fn chain_id(&self) -> Result<Resolved<u64>, CliError>
Resolve the session chain id: --chain-id > DEGENBOT_DEFAULT_CHAIN_ID
session.chain_id.
§Errors
crate::error::CliError::Config when no layer named a chain, when
the explicit value is not an integer, or when the config layers do not
load.
Sourcepub fn node_request_uri_for(
&self,
chain_id: u64,
) -> Result<Resolved<String>, CliError>
pub fn node_request_uri_for( &self, chain_id: u64, ) -> Result<Resolved<String>, CliError>
Resolve the node URI a REQUEST consumer uses for chain_id: ipc, then
ws, then http (ADR-062 D3).
The updater arms resolve the chain they actually operate on (which may differ from the session chain id, e.g. a validated Aave deployment).
§Errors
crate::error::CliError::Config when no layer supplied an endpoint
for the chain, or when the config layers do not load.
Sourcepub fn node_request_uri(&self) -> Result<Resolved<String>, CliError>
pub fn node_request_uri(&self) -> Result<Resolved<String>, CliError>
Resolve the node URI a REQUEST consumer uses for the session chain id.
§Errors
crate::error::CliError::Config when the chain id or the endpoint is
unresolved, or when the config layers do not load.
Sourcepub fn node_subscription_uri(&self) -> Result<Resolved<String>, CliError>
pub fn node_subscription_uri(&self) -> Result<Resolved<String>, CliError>
Resolve the node URI a SUBSCRIPTION consumer uses for the session chain id: ipc or ws, never http (ADR-062 D3 — a feed never polls).
§Errors
crate::error::CliError::Config when the chain id or the feed
endpoint is unresolved, or when the config layers do not load.
Sourcepub fn resolve_config_file(&self) -> Result<PathBuf, CliError>
pub fn resolve_config_file(&self) -> Result<PathBuf, CliError>
Resolve the config file the strategy verbs write to: the --config
override, else the DEGENBOT_CONFIG env var (honored even when the
file is absent — the operator asked for it), else the XDG config home
(a write there creates the file). No home and no override is a typed
refusal, never a silent skip.
§Errors
[CliError::Config]-carrying crate::error::CliError when no
config location resolves at all.
Sourcepub fn load_bot_config(&self) -> Result<LoadedConfig, CliError>
pub fn load_bot_config(&self) -> Result<LoadedConfig, CliError>
Load the typed config over this context’s env + the resolved file.
§Errors
The loader’s fail-closed degenbot_config::ConfigError wrapped in
crate::error::CliError::InvalidArgument.
Sourcepub fn load_bot_config_at(&self, file: &Path) -> Result<LoadedConfig, CliError>
pub fn load_bot_config_at(&self, file: &Path) -> Result<LoadedConfig, CliError>
Load the typed config over this context’s env + an explicit file. An absent file is the empty default config (a first write creates it); an existing-but-unreadable file surfaces the loader’s refusal.
§Errors
The loader’s fail-closed degenbot_config::ConfigError wrapped in
crate::error::CliError::InvalidArgument.
Auto Trait Implementations§
impl<'a> !Freeze for CliContext<'a>
impl<'a> !RefUnwindSafe for CliContext<'a>
impl<'a> !Send for CliContext<'a>
impl<'a> !Sync for CliContext<'a>
impl<'a> !UnwindSafe for CliContext<'a>
impl<'a> Unpin for CliContext<'a>
impl<'a> UnsafeUnpin for CliContext<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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