-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #41 from anton-rs/10-07-feat_cli_subcommands
10 07 feat cli subcommands
- Loading branch information
Showing
6 changed files
with
76 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use bollard::Docker; | ||
use clap::Args; | ||
use eyre::Result; | ||
use std::path::{Path, PathBuf}; | ||
|
||
use op_config::Config; | ||
use op_stages::Stages; | ||
|
||
/// The Up CLI Subcommand. | ||
#[derive(Debug, Args)] | ||
pub struct UpCommand { | ||
/// An optional path to a stack config file. | ||
#[arg(long, short)] | ||
pub config: Option<PathBuf>, | ||
|
||
/// Whether to build a hard-coded default devnet stack, ignoring the config file. | ||
#[arg(long, short)] | ||
pub devnet: bool, | ||
} | ||
|
||
impl UpCommand { | ||
/// Create a new Up CLI Subcommand. | ||
pub fn new(config: Option<PathBuf>, devnet: bool) -> Self { | ||
Self { config, devnet } | ||
} | ||
|
||
/// 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: remove this once we have a proper stage docker component | ||
// for now, this placeholds use of [bollard]. | ||
let docker = Docker::connect_with_local_defaults()?; | ||
let version = docker.version().await?; | ||
tracing::info!(target: "cli", "docker version: {:?}", version); | ||
|
||
if self.devnet { | ||
tracing::info!(target: "cli", "Building default devnet stack"); | ||
Stages::from(Config::default()).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); | ||
|
||
tracing::info!(target: "cli", "Stack: {:#?}", stack); | ||
|
||
Stages::from(stack).execute().await | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters