Skip to content

Commit

Permalink
Merge branch 'master' into chore--update-merod-command-instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejVukosav authored Dec 21, 2024
2 parents dbeae8e + f6ccc81 commit 2cd3c3b
Show file tree
Hide file tree
Showing 13 changed files with 473 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dist/
lib/
node_modules/
certs/
output/*
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/meroctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ eyre.workspace = true
futures-util.workspace = true
libp2p.workspace = true
notify.workspace = true
rand.workspace = true
reqwest = { workspace = true, features = ["json"] }
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
Expand Down
14 changes: 14 additions & 0 deletions crates/meroctl/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::process::ExitCode;

use bootstrap::BootstrapCommand;
use camino::Utf8PathBuf;
use clap::{Parser, Subcommand};
use const_format::concatcp;
Expand All @@ -11,6 +12,7 @@ use crate::defaults;
use crate::output::{Format, Output, Report};

mod app;
mod bootstrap;
mod call;
mod context;
mod identity;
Expand Down Expand Up @@ -53,6 +55,7 @@ pub enum SubCommands {
Identity(IdentityCommand),
Proxy(ProxyCommand),
Call(CallCommand),
Bootstrap(BootstrapCommand),
}

#[derive(Debug, Parser)]
Expand All @@ -70,6 +73,16 @@ pub struct RootArgs {
pub output_format: Format,
}

impl RootArgs {
pub const fn new(home: Utf8PathBuf, node_name: String, output_format: Format) -> Self {
Self {
home,
node_name,
output_format,
}
}
}

pub struct Environment {
pub args: RootArgs,
pub output: Output,
Expand All @@ -92,6 +105,7 @@ impl RootCommand {
SubCommands::Identity(identity) => identity.run(&environment).await,
SubCommands::Proxy(proxy) => proxy.run(&environment).await,
SubCommands::Call(call) => call.run(&environment).await,
SubCommands::Bootstrap(call) => call.run(&environment).await,
};

if let Err(err) = result {
Expand Down
2 changes: 1 addition & 1 deletion crates/meroctl/src/cli/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::cli::Environment;
use crate::output::Report;

mod get;
mod install;
pub mod install;
mod list;

pub const EXAMPLES: &str = r"
Expand Down
9 changes: 8 additions & 1 deletion crates/meroctl/src/cli/app/install.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use calimero_primitives::application::ApplicationId;
use calimero_primitives::hash::Hash;
use calimero_server_primitives::admin::{
InstallApplicationRequest, InstallApplicationResponse, InstallDevApplicationRequest,
Expand Down Expand Up @@ -36,6 +37,12 @@ impl Report for InstallApplicationResponse {

impl InstallCommand {
pub async fn run(self, environment: &Environment) -> Result<()> {
let _ignored = self.install_app(environment).await?;

Ok(())
}

pub async fn install_app(self, environment: &Environment) -> Result<ApplicationId> {
let config = load_config(&environment.args.home, &environment.args.node_name)?;
let mut is_dev_installation = false;
let metadata = self.metadata.map(String::into_bytes).unwrap_or_default();
Expand Down Expand Up @@ -76,6 +83,6 @@ impl InstallCommand {

environment.output.write(&response);

Ok(())
Ok(response.data.application_id)
}
}
41 changes: 41 additions & 0 deletions crates/meroctl/src/cli/bootstrap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use clap::{Parser, Subcommand};
use const_format::concatcp;
use eyre::Result as EyreResult;
use start::StartBootstrapCommand;

use super::Environment;

mod start;

pub const EXAMPLES: &str = r"
# Setup and run 2 nodes with demo app
$ meroctl -- --node-name node1 bootstrap start --merod-path /path/to/merod
# Setup and run 2 nodes with provided app
$ meroctl -- --node-name node1 bootstrap start --merod-path /path/to/merod --app-path /path/to/app
";

#[derive(Debug, Parser)]
#[command(about = "Command for starting bootstrap")]
#[command(after_help = concatcp!(
"Examples:",
EXAMPLES
))]
pub struct BootstrapCommand {
#[command(subcommand)]
pub subcommand: BootstrapSubCommands,
}

#[derive(Debug, Subcommand)]
pub enum BootstrapSubCommands {
Start(StartBootstrapCommand),
}

impl BootstrapCommand {
pub async fn run(self, environment: &Environment) -> EyreResult<()> {
match self.subcommand {
BootstrapSubCommands::Start(generate) => generate.run(environment).await,
}
}
}
Loading

0 comments on commit 2cd3c3b

Please sign in to comment.