Skip to main content

CliContext

Struct CliContext 

Source
pub struct CliContext<'a> { /* private fields */ }
Expand description

The resolved inputs a console command runs against.

Implementations§

Source§

impl<'a> CliContext<'a>

Source

pub fn new(env: &'a dyn EnvVars) -> Self

A context over env with no CLI overrides (file + env + defaults only).

Source

pub fn with_database(self, database: impl Into<String>) -> Self

Set the --database override (highest-precedence layer).

Source

pub fn with_chain_id(self, chain_id: impl Into<String>) -> Self

Set the --chain-id override.

Source

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.

Source

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).

Source

pub fn with_config(self, path: impl Into<String>) -> Self

Set the --config override (the typed config file the strategy verbs read and write).

Source

pub fn env(&self) -> &'a dyn EnvVars

The env seam (the loaders’ only env reader).

Source

pub fn database_override(&self) -> Option<&str>

The --database override, if any.

Source

pub fn node_overrides(&self) -> &NodeOverrides

The explicit node endpoints the argv facade threaded in.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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> 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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: Sized + 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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