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

chore(bin): Cleanup #63

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
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
17 changes: 5 additions & 12 deletions bin/opup/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
/// The CLI entrypoint for the binary.
pub mod cli;

/// Command banners.
pub mod banners;

/// Telemetry contains helpers for initializing telemetry.
pub mod telemetry;

/// Runner contains asynchronous helpers for running commands.
pub mod runner;

/// The Up subcommand module that contains the logic for bringing up the stack.
pub(crate) mod up;

// Internally Exposed Modules
pub(crate) mod banners;
pub(crate) mod list;
pub(crate) mod runner;
pub(crate) mod telemetry;
pub(crate) mod up;
15 changes: 0 additions & 15 deletions bin/opup/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,3 @@ where
tokio_runtime.block_on(fut)?;
Ok(())
}

/// Run a future until ctrl-c is pressed.
pub fn run_blocking_until_ctrl_c<F>(fut: F) -> Result<()>
where
F: Future<Output = Result<()>> + Send + 'static,
{
let tokio_runtime = tokio_runtime()?;
let handle = tokio_runtime.handle().clone();
let fut = tokio_runtime
.handle()
.spawn_blocking(move || handle.block_on(fut));
tokio_runtime.block_on(async move { fut.await.expect("join task") })?;
std::thread::spawn(move || drop(tokio_runtime));
Ok(())
}
46 changes: 22 additions & 24 deletions bin/opup/src/up.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use clap::Args;
use eyre::Result;
use std::path::{Path, PathBuf};
use tracing::instrument;

use op_config::Config;
use op_stages::Stages;
Expand Down Expand Up @@ -34,33 +35,30 @@ impl UpCommand {
}
}

/// Run the Up CLI Subcommand.
pub fn run(&self) -> Result<()> {
crate::runner::run_until_ctrl_c(async {
tracing::info!(target: "cli", "bootstrapping op stack");

// todo get the force arg and pass it into the stages pipeline
// should the stack config be transformed to include this and
// other flags?
/// Internal async executor.
async fn execute(&self) -> Result<()> {
tracing::info!("bootstrapping op stack");

if self.devnet {
tracing::info!(target: "cli", "Building default devnet stack");
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("."));
if self.devnet {
tracing::info!("Building default devnet stack");
let config = Config::default().force_overwrites(self.force);
return Stages::from(config).execute().await;
}

// 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).force_overwrites(self.force);
// 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("."));
tracing::info!("Using config directory: {:?}", config_dir);

tracing::info!(target: "cli", "Stack: {:#?}", stack);
// Load the config file from the parsed path.
let config = Config::load_with_root(config_dir).force_overwrites(self.force);
tracing::info!("Built config, executing stages");
Stages::from(config).execute().await
}

Stages::from(stack).execute().await
}
})
/// Entrypoint
#[instrument(name = "up", target = "run")]
pub fn run(&self) -> Result<()> {
crate::runner::run_until_ctrl_c(async { self.execute().await })
}
}
Loading