Skip to content

Commit

Permalink
Merge pull request #60 from anton-rs/reafcell/monorepo-updates
Browse files Browse the repository at this point in the history
feat(bin): Force Overwrite CLI Flag
  • Loading branch information
merklefruit authored Oct 16, 2023
2 parents 0a70a64 + 4fb0d17 commit 753376a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
23 changes: 20 additions & 3 deletions bin/opup/src/up.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@ pub struct UpCommand {
/// Whether to build a hard-coded default devnet stack, ignoring the config file.
#[arg(long, short)]
pub devnet: bool,

/// Force enables op-up to enter overwrite mode.
///
/// It enables overwriting of persistant artifacts from previous runs,
/// for example, git repository clones.
#[arg(long, short)]
pub force: bool,
}

impl UpCommand {
/// Create a new Up CLI Subcommand.
pub fn new(config: Option<PathBuf>, devnet: bool) -> Self {
Self { config, devnet }
Self {
config,
devnet,
force: false,
}
}

/// Run the Up CLI Subcommand.
Expand All @@ -35,17 +46,23 @@ impl UpCommand {
let version = docker.version().await?;
tracing::info!(target: "cli", "docker version: {:?}", version);

// todo get the force arg and pass it into the stages pipeline
// should the stack config be transformed to include this and
// other flags?

if self.devnet {
tracing::info!(target: "cli", "Building default devnet stack");
Stages::from(Config::default()).execute().await
Stages::from(Config::default().force_overwrites(self.force))
.execute()
.await
} else {
// Get the directory of the config file if it exists.
let config_dir = self.config.as_ref().and_then(|p| p.parent());
let config_dir = config_dir.unwrap_or_else(|| Path::new("."));

// Build a config from the parsed config directory.
tracing::info!(target: "cli", "Loading op-stack config from {:?}", config_dir);
let stack = Config::load_with_root(config_dir);
let stack = Config::load_with_root(config_dir).force_overwrites(self.force);

tracing::info!(target: "cli", "Stack: {:#?}", stack);

Expand Down
6 changes: 6 additions & 0 deletions crates/config/src/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,12 @@ impl Config<'_> {
dirs_next::home_dir().map(|p| p.join(Config::STACK_DIR_NAME))
}

/// Force monorepo artifact overwrites.
pub fn force_overwrites(mut self, force: bool) -> Self {
self.monorepo.force = force;
self
}

/// Sets the l1 client to use via a cli prompt.
pub fn set_l1_client(&mut self) -> Result<()> {
make_selection!(
Expand Down
5 changes: 4 additions & 1 deletion crates/primitives/src/monorepo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ pub struct MonorepoConfig {
pub git_url: String,
/// The URL from which to download the Optimism Monorepo tarball.
pub tarball_url: String,
/// Optionally force overwriting local monorepo artifacts.
pub force: bool,
}

impl Default for MonorepoConfig {
Expand All @@ -37,6 +39,7 @@ impl Default for MonorepoConfig {
git_url: "[email protected]:ethereum-optimism/optimism.git".to_string(),
tarball_url: "https://github.com/ethereum-optimism/optimism/archive/develop.tar.gz"
.to_string(),
force: false,
}
}
}
Expand Down Expand Up @@ -140,7 +143,7 @@ impl Monorepo {
///
/// If the monorepo already exists, this method will garacefully log a warning and return.
pub fn obtain_from_source(&self) -> Result<()> {
if self.path().exists() {
if self.path().exists() && !self.config.force {
tracing::warn!(target: "monorepo", "Monorepo already exists, skipping...");
return Ok(());
}
Expand Down

0 comments on commit 753376a

Please sign in to comment.