Skip to content

Commit

Permalink
update hermes cli with running app
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Leshiy committed Jul 15, 2024
1 parent 2ce7561 commit 2ffeaef
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
15 changes: 14 additions & 1 deletion hermes/bin/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ mod build_info;
mod module;
mod run;

use std::path::PathBuf;

use build_info::BUILD_INFO;
use clap::{Parser, Subcommand};
use console::{style, Emoji};
Expand All @@ -26,6 +28,17 @@ const ENV_LOG_LEVEL: &str = "HERMES_LOG_LEVEL";
#[derive(Parser)]
#[clap(version = BUILD_INFO)]
pub(crate) struct Cli {
/// Path to the Hermes application package to run
app_package: PathBuf,

/// Path to the trusted certificate
#[clap(name = "cert", short)]
certificate: Vec<PathBuf>,

/// Flag which disables package signature verification
#[clap(long, action = clap::ArgAction::SetTrue)]
unstrusted: bool,

/// Hermes cli subcommand
#[clap(subcommand)]
command: Option<Commands>,
Expand Down Expand Up @@ -63,7 +76,7 @@ impl Cli {
logger::init(&log_config).unwrap_or_else(errors.get_add_err_fn());

match self.command {
None => run::Run::exec(),
None => run::Run::exec(self.app_package, self.certificate, self.unstrusted),
Some(Commands::Module(cmd)) => cmd.exec(),
Some(Commands::App(cmd)) => cmd.exec(),
}
Expand Down
24 changes: 21 additions & 3 deletions hermes/bin/src/cli/run.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
//! Run cli command
use crate::reactor::HermesReactor;
use std::path::PathBuf;

use crate::{
packaging::{
app::ApplicationPackage,
sign::certificate::{self, Certificate},
},
reactor::HermesReactor,
};

/// Run cli command
pub(crate) struct Run;

impl Run {
/// Run the hermes
pub(crate) fn exec() -> anyhow::Result<()> {
/// Run the hermes application
pub(crate) fn exec(
app_package: PathBuf, certificates: Vec<PathBuf>, unstrusted: bool,
) -> anyhow::Result<()> {
for cert_path in certificates {
let cert = Certificate::from_file(cert_path)?;
certificate::storage::add_certificate(cert)?;
}

let package = ApplicationPackage::from_file(app_package)?;
package.validate(unstrusted)?;

let mut reactor = HermesReactor::new(vec![])?;
reactor.wait()?;

Expand Down

0 comments on commit 2ffeaef

Please sign in to comment.