Struct spacetimedb_cli::Config
source · pub struct Config { /* private fields */ }
Implementations§
source§impl Config
impl Config
pub fn default_server_name(&self) -> Option<&str>
sourcepub fn add_server(
&mut self,
host: String,
protocol: String,
ecdsa_public_key: Option<String>,
nickname: Option<String>
) -> Result<()>
pub fn add_server( &mut self, host: String, protocol: String, ecdsa_public_key: Option<String>, nickname: Option<String> ) -> Result<()>
Add a ServerConfig
to the home configuration.
Returns an Err
on name conflict,
i.e. if a ServerConfig
with the nickname
or host
already exists.
Callers should call Config::save
afterwards
to ensure modifications are persisted to disk.
sourcepub fn set_default_server(
&mut self,
nickname_or_host_or_url: &str
) -> Result<()>
pub fn set_default_server( &mut self, nickname_or_host_or_url: &str ) -> Result<()>
Set the default server in the home configuration.
Returns an Err
if nickname_or_host_or_url
does not refer to an existing ServerConfig
in the home configuration.
Callers should call Config::save
afterwards
to ensure modifications are persisted to disk.
sourcepub fn remove_server(
&mut self,
nickname_or_host_or_url: &str,
delete_identities: bool
) -> Result<Vec<IdentityConfig>>
pub fn remove_server( &mut self, nickname_or_host_or_url: &str, delete_identities: bool ) -> Result<Vec<IdentityConfig>>
Delete a ServerConfig
from the home configuration.
Returns an Err
if nickname_or_host_or_url
does not refer to an existing ServerConfig
in the home configuration.
If delete_identities
is true,
also removes any saved IdentityConfig
s
which apply to the removed server.
This requires that the server have a saved fingerprint.
Callers should call Config::save
afterwards
to ensure modifications are persisted to disk.
sourcepub fn get_host_url(&self, server: Option<&str>) -> Result<String>
pub fn get_host_url(&self, server: Option<&str>) -> Result<String>
Get a URL for the specified server
.
Returns the URL of the default server if server
is None
.
Entries in the project configuration supersede entries in the home configuration.
If server
is Some
and is a complete URL,
including protocol and hostname,
returns that URL without accessing the configuration.
Returns an Err
if:
server
isSome
, but not a complete URL, and the supplied name does not refer to any server in either the project or the home configuration.server
isNone
, but neither the home nor the project configuration has a default server.
sourcepub fn host<'a>(&'a self, server: Option<&'a str>) -> Result<&'a str>
pub fn host<'a>(&'a self, server: Option<&'a str>) -> Result<&'a str>
Get the hostname of the specified server
.
Returns the hostname of the default server if server
is None
.
Entries in the project configuration supersede entries in the home configuration.
If server
is Some
and is a complete URL,
including protocol and hostname,
returns that hostname without accessing the configuration.
Returns an Err
if:
server
isSome
, but not a complete URL, and the supplied name does not refer to any server in either the project or the home configuration.server
isNone
, but neither the home nor the project configuration has a default server.
sourcepub fn protocol<'a>(&'a self, server: Option<&'a str>) -> Result<&'a str>
pub fn protocol<'a>(&'a self, server: Option<&'a str>) -> Result<&'a str>
Get the protocol of the specified server
, either "http"
or "https"
.
Returns the protocol of the default server if server
is None
.
Entries in the project configuration supersede entries in the home configuration.
If server
is Some
and is a complete URL,
including protocol and hostname,
returns that protocol without accessing the configuration.
In that case, the protocol is not validated.
Returns an Err
if:
server
isSome
, but not a complete URL, and the supplied name does not refer to any server in either the project or the home configuration.server
isNone
, but neither the home nor the project configuration has a default server.
pub fn default_identity(&self, server: Option<&str>) -> Result<&str>
sourcepub fn set_default_identity(
&mut self,
default_identity: String,
server: Option<&str>
) -> Result<()>
pub fn set_default_identity( &mut self, default_identity: String, server: Option<&str> ) -> Result<()>
Set the default identity for server
in the home configuration.
Does not validate that default_identity
applies to server
.
Returns an Err
if:
server
isSome
, but does not refer to any server in the home configuration.server
isNone
, but the home configuration does not have a default server.
sourcepub fn set_identity_nickname(
&mut self,
identity: &Identity,
nickname: &str
) -> Result<Option<String>, Error>
pub fn set_identity_nickname( &mut self, identity: &Identity, nickname: &str ) -> Result<Option<String>, Error>
Sets the nickname
for the provided identity
.
If the identity
already has a nickname
set, it will be overwritten and returned. If the
identity
is not found, an error will be returned.
§Returns
Ok(Option<String>)
- If the identity was found, the old nickname will be returned.Err(anyhow::Error)
- If the identity was not found.
pub fn identity_configs(&self) -> &[IdentityConfig]
pub fn identity_configs_mut(&mut self) -> &mut Vec<IdentityConfig>
pub fn server_configs(&self) -> &[ServerConfig]
pub fn load() -> Self
pub fn new_with_localhost() -> Self
pub fn save(&self)
pub fn get_default_identity_config( &self, server: Option<&str> ) -> Result<&IdentityConfig>
pub fn name_exists(&self, nickname: &str) -> bool
pub fn get_identity_config_by_name(&self, name: &str) -> Option<&IdentityConfig>
pub fn get_identity_config_by_identity( &self, identity: &Identity ) -> Option<&IdentityConfig>
pub fn get_identity_config_by_identity_mut( &mut self, identity: &Identity ) -> Option<&mut IdentityConfig>
sourcepub fn resolve_name_to_identity(
&self,
identity_or_name: &str
) -> Result<Identity>
pub fn resolve_name_to_identity( &self, identity_or_name: &str ) -> Result<Identity>
Converts some given identity_or_name
into an identity.
If identity_or_name
is None
then None
is returned. If identity_or_name
is Some
,
then if its an identity then its just returned. If its not an identity it is assumed to be
a name and it is looked up as an identity nickname. If the identity exists it is returned,
otherwise we panic.
sourcepub fn get_identity_config(
&self,
identity_or_name: &str
) -> Option<&IdentityConfig>
pub fn get_identity_config( &self, identity_or_name: &str ) -> Option<&IdentityConfig>
Converts some given identity_or_name
into an IdentityConfig
.
§Returns
None
- If an identity config with the givenidentity_or_name
does not exist.Some
- A mutable reference to theIdentityConfig
with the givenidentity_or_name
.
sourcepub fn get_identity_config_mut(
&mut self,
identity_or_name: &str
) -> Option<&mut IdentityConfig>
pub fn get_identity_config_mut( &mut self, identity_or_name: &str ) -> Option<&mut IdentityConfig>
Converts some given identity_or_name
into a mutable IdentityConfig
.
§Returns
None
- If an identity config with the givenidentity_or_name
does not exist.Some
- A mutable reference to theIdentityConfig
with the givenidentity_or_name
.
pub fn delete_identity_config_by_name( &mut self, name: &str ) -> Option<IdentityConfig>
pub fn delete_identity_config_by_identity( &mut self, identity: &Identity ) -> Option<IdentityConfig>
sourcepub fn delete_all_identity_configs(&mut self)
pub fn delete_all_identity_configs(&mut self)
Deletes all stored identity configs. This function does not save the config after removing all configs.
pub fn update_all_default_identities(&mut self)
pub fn set_default_identity_if_unset( &mut self, server: Option<&str>, identity: &str ) -> Result<()>
pub fn server_decoding_key(&self, server: Option<&str>) -> Result<DecodingKey>
pub fn server_nick_or_host<'a>( &'a self, server: Option<&'a str> ) -> Result<&'a str>
pub fn server_fingerprint(&self, server: Option<&str>) -> Result<Option<&str>>
pub fn set_server_fingerprint( &mut self, server: Option<&str>, new_fingerprint: String ) -> Result<()>
pub fn remove_identities_for_server( &mut self, server: Option<&str> ) -> Result<Vec<IdentityConfig>>
pub fn remove_identities_for_fingerprint( &mut self, fingerprint: &str ) -> Result<Vec<IdentityConfig>>
pub fn edit_server( &mut self, server: &str, new_nickname: Option<&str>, new_host: Option<&str>, new_protocol: Option<&str> ) -> Result<(Option<String>, Option<String>, Option<String>)>
pub fn delete_server_fingerprint(&mut self, server: Option<&str>) -> Result<()>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
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