Struct cubist_config::Config
source · pub struct Config {
pub config_path: PathBuf,
pub type_: ProjType,
pub network_profiles: HashMap<NetworkProfileName, NetworkProfile>,
pub current_network_profile: NetworkProfileName,
pub bridge_provider: BridgeProvider,
/* private fields */
}
Expand description
Top-level cubist application configuration.
Configs are consumed by all SDKs.
Fields§
§config_path: PathBuf
Absolute path to the file corresponding to this configuration.
type_: ProjType
Project type
network_profiles: HashMap<NetworkProfileName, NetworkProfile>
A map of named network profiles for use in development, testing, etc.
current_network_profile: NetworkProfileName
Selected network profile. If omitted, defaults to “default”. A
network profile with the same name must be defined in network_profiles
.
bridge_provider: BridgeProvider
The bridge provider to use for cross-chain invocations.
Implementations§
source§impl Config
impl Config
sourcepub fn new(type_: ProjType, dir: impl AsRef<Path>) -> Result<Self>
pub fn new(type_: ProjType, dir: impl AsRef<Path>) -> Result<Self>
Create configuration given type and directory.
Arguments
type_
- Project typedir
- Project directory
Example
use cubist_config::{Config, ProjType};
use tempfile::tempdir;
use std::fs;
// Create temp dir
let dir = tempdir().unwrap();
fs::create_dir_all(&dir).unwrap();
// Create config (in temp dir)
let cfg: Config = Config::new(ProjType::JavaScript, &dir).unwrap();
assert_eq!(cfg.type_, ProjType::JavaScript);
assert_eq!(cfg.build_dir(), dir.path().join("build"));
assert_eq!(cfg.deploy_dir(), dir.path().join("deploy"));
// Save config file to disk
cfg.to_file(false).unwrap();
// Load config from disk
let cfg2 = Config::from_file(&cfg.config_path).unwrap();
sourcepub fn nearest() -> Result<Self>
pub fn nearest() -> Result<Self>
Create configuration from config file in the current directory or some parent directory.
Example
use cubist_config::{Config, ProjType};
use tempfile::tempdir;
use std::fs;
use std::env;
// Create temp directory and chdir
let dir = tempdir().unwrap();
fs::create_dir_all(&dir).unwrap();
assert!(env::set_current_dir(&dir).is_ok());
// Create config
let cfg: Config = Config::new(ProjType::JavaScript, ".").unwrap();
cfg.to_file(false).unwrap();
// Load config from disk
let cfg2 = Config::nearest().unwrap();
sourcepub fn from_dir(dir: impl AsRef<Path>) -> Result<Self>
pub fn from_dir(dir: impl AsRef<Path>) -> Result<Self>
Create configuration from directory (really from DEFAULT_FILENAME
file in the directory).
sourcepub fn from_file(config_path: impl AsRef<Path>) -> Result<Self>
pub fn from_file(config_path: impl AsRef<Path>) -> Result<Self>
Create configuration from JSON file. Some paths can be overridden via environment variables:
- Set
deploy_dir
viaCUBIST_DEPLOY_DIR
- Set
build_dir
viaCUBIST_BUILD_DIR
This function serves as the deserializer to all the other loaders (namely Self::nearest
and Self::from_dir
).
sourcepub fn to_file(&self, force: bool) -> Result<()>
pub fn to_file(&self, force: bool) -> Result<()>
Save configuration to new file.
Writing to an existing file is generally discouraged (but can be done with by passing true
fo the force
argument). When we read configs from file, we resolve some paths (e.g., we
turn contract globs into paths) and don’t preserve the original. We also make the build,
deploy, and contracts root dir relative to the project root. We do this largely because we
use to_file
when we create new projects. This does mean: to_file(from_file(_))
is not
the identiy function!
sourcepub fn project_dir(&self) -> PathBuf
pub fn project_dir(&self) -> PathBuf
Get the top-level project directory
sourcepub fn deploy_dir(&self) -> PathBuf
pub fn deploy_dir(&self) -> PathBuf
Get the absolute deploy directory
sourcepub fn relative_to_project_dir(&self, path: impl AsRef<Path>) -> Result<PathBuf>
pub fn relative_to_project_dir(&self, path: impl AsRef<Path>) -> Result<PathBuf>
Return relative path to the project root if the path is inside the project root.
sourcepub fn contracts(&self) -> &ContractsConfig
pub fn contracts(&self) -> &ContractsConfig
Get contracts configurations.
sourcepub fn network_for_target(&self, target: Target) -> Option<EndpointConfig>
pub fn network_for_target(&self, target: Target) -> Option<EndpointConfig>
Return configured network (if any) for a given target.
sourcepub fn network_profile(&self) -> &NetworkProfile
pub fn network_profile(&self) -> &NetworkProfile
Return the currently selected network profile.
sourcepub fn allow_import_from_external(&self) -> bool
pub fn allow_import_from_external(&self) -> bool
Returns true
if imports from external sources are allowed.
sourcepub fn get_compiler_config(&self) -> CompilerConfig
pub fn get_compiler_config(&self) -> CompilerConfig
Returns the compiler configuration for this Cubist configuration.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl JsonSchema for Config
impl JsonSchema for Config
source§fn schema_name() -> String
fn schema_name() -> String
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
$ref
keyword. Read moreAuto Trait Implementations§
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> 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> IntoResult<T> for T
impl<T> IntoResult<T> for T
type Err = Infallible
fn into_result(self) -> Result<T, <T as IntoResult<T>>::Err>
§impl<D> OwoColorize for D
impl<D> OwoColorize for D
§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
§fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>
§fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>
§fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>
§fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>
§fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>
§fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>
§fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>
§fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>
§fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>
§fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>
§fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>
§fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>
§fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>
§fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>
§fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>
§fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>
§fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>
§fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>
§fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>
§fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>
§fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>
§fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
fn blink_fast<'a>(&'a self) -> BlinkFastDisplay<'a, Self>
§fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>
§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg
or
a color-specific method, such as OwoColorize::green
, Read more§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg
or
a color-specific method, such as OwoColorize::on_yellow
, Read more