Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CLI] Fix config option for when a file or folder is passed. #18469

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 25 additions & 13 deletions crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,21 +601,31 @@ async fn start(
let epoch_duration_ms = epoch_duration_ms.unwrap_or(DEFAULT_EPOCH_DURATION_MS);
swarm_builder = swarm_builder.with_epoch_duration_ms(epoch_duration_ms);
} else {
// load from config dir that was passed, or generate a new genesis if there is no config
// dir passed and there is no config_dir in the default location
// and if a dir exists, then use that one
if let Some(config) = config.clone() {
swarm_builder = swarm_builder.dir(config);
} else if config.is_none() && !sui_config_dir()?.join(SUI_NETWORK_CONFIG).exists() {
if config.is_none() && !sui_config_dir()?.join(SUI_NETWORK_CONFIG).exists() {
genesis(None, None, None, false, epoch_duration_ms, None, false).await?;
swarm_builder = swarm_builder.dir(sui_config_dir()?);
} else {
swarm_builder = swarm_builder.dir(sui_config_dir()?);
}

// Load the config of the Sui authority.
let network_config_path = config
.clone()
.unwrap_or(sui_config_dir()?.join(SUI_NETWORK_CONFIG));
// To keep compatibility with sui-test-validator where the user can pass a config
// directory, this checks if the config is a file or a directory
let network_config_path = if let Some(ref config) = config {
if config.is_dir() {
config.join(SUI_NETWORK_CONFIG)
} else if config.is_file()
&& config
.extension()
.is_some_and(|ext| (ext == "yml" || ext == "yaml"))
{
config.clone()
} else {
config.join(SUI_NETWORK_CONFIG)
}
} else {
config
.clone()
.unwrap_or(sui_config_dir()?)
.join(SUI_NETWORK_CONFIG)
};
let network_config: NetworkConfig =
PersistedConfig::read(&network_config_path).map_err(|err| {
err.context(format!(
Expand All @@ -624,7 +634,9 @@ async fn start(
))
})?;

swarm_builder = swarm_builder.with_network_config(network_config);
swarm_builder = swarm_builder
.dir(sui_config_dir()?)
.with_network_config(network_config);
}

#[cfg(feature = "indexer")]
Expand Down
Loading