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 (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_http(self, uri: impl Into<String>) -> Self

Set the --node-http override.

Source

pub fn with_node_ws(self, uri: impl Into<String>) -> Self

Set the --node-ws override.

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 resolvers’ only env reader).

Source

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

The --database override, if any.

Source

pub fn database_path(&self) -> Resolved<PathBuf>

Resolve the database path: --database > DEGENBOT_DB_PATH > the built-in default. Never fails.

Source

pub fn chain_id(&self) -> Result<Resolved<u64>, ConfigError>

Resolve the session chain id: --chain-id > DEGENBOT_DEFAULT_CHAIN_ID.

§Errors

degenbot_config::ConfigError when neither layer supplied a value, or the winning layer is not an integer.

Source

pub fn node_http_uri_for( &self, chain_id: u64, ) -> Result<Resolved<String>, ConfigError>

Resolve the HTTP node URI for chain_id: --node-http > DEGENBOT_RPC_HTTP_CHAINID_<id>.

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

degenbot_config::ConfigError when no layer supplied the URI.

Source

pub fn node_http_uri(&self) -> Result<Resolved<String>, ConfigError>

Resolve the HTTP node URI for the session chain id.

§Errors

degenbot_config::ConfigError when the chain id or endpoint is unresolved.

Source

pub fn node_uris(&self) -> Result<ResolvedNodeUris, ConfigError>

Resolve both node URIs for the session chain id.

§Errors

degenbot_config::ConfigError when the chain id or either endpoint is unresolved.

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> !RefUnwindSafe for CliContext<'a>

§

impl<'a> !Send for CliContext<'a>

§

impl<'a> !Sync for CliContext<'a>

§

impl<'a> !UnwindSafe for CliContext<'a>

§

impl<'a> Freeze 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