Skip to content

Commit

Permalink
Upgrade Clap to v3 (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimDiekmann authored Jan 3, 2022
1 parent 3f5e9a8 commit 1cfc2e7
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 122 deletions.
123 changes: 35 additions & 88 deletions packages/engine/Cargo.lock

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

2 changes: 1 addition & 1 deletion packages/engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ default-members = [".", "bin/*", "lib/*"]
[dependencies]
flatbuffers_gen = { path = "lib/flatbuffers_gen" }

argh = "0.1.4"
arr_macro = "0.1.3"
arrow = { version = "1.0.1", default-features = false }
async-trait = "0.1.48"
clap = { version = "3.0.0", features = ["cargo", "derive", "env"] }
csv = "1.1.5"
derive-new = "0.5"
enum_dispatch = "0.3.7"
Expand Down
4 changes: 3 additions & 1 deletion packages/engine/bin/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
name = "cli"
version = "0.0.0"
edition = "2021"
# TODO: Add authors to be shown in CLI
description = "The hEngine Command line interface"

[dependencies]
hash_engine = { path = "../.." }
#server = { path = "../server", artifact = "bin" }

anyhow = "1.0.51"
async-trait = "0.1.48"
clap = { version = "3.0.0", features = ["cargo", "derive", "env"] }
lazy_static = "1.4.0"
log = "0.4.11"
pretty_env_logger = "0.4.0"
rand = "0.8.3"
rand_distr = "0.4.2"
serde = { version = "1.0.111", features = ["derive"] }
serde_json = "1.0.59"
structopt = "0.3.25"
tokio = { version = "1.5.0", features = ["macros", "rt-multi-thread", "sync", "process", "io-util", "net", "rt", "fs"] }
11 changes: 5 additions & 6 deletions packages/engine/bin/cli/src/experiment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{iter::FromIterator, path::PathBuf, time::Duration};
use std::{iter::FromIterator, time::Duration};

use anyhow::{bail, format_err, Context, Result};
use hash_engine::{
Expand All @@ -23,10 +23,10 @@ lazy_static::lazy_static! {
/// The simulations will run to completion and the connection will finish once the last run is done,
/// or if there is an error.
pub async fn run_experiment(args: Args, handler: Handler) -> Result<()> {
let project = &args.project;
let absolute_project_path = PathBuf::from(project)
let absolute_project_path = args
.project
.canonicalize()
.with_context(|| format!("Could not canonicalize project path: {project:?}"))?;
.with_context(|| format!("Could not canonicalize project path: {:?}", args.project))?;
let project_name = args.project_name.clone().unwrap_or(
absolute_project_path
.file_name()
Expand Down Expand Up @@ -92,8 +92,7 @@ async fn run_experiment_with_manifest(
};
debug!("Received start message from {experiment_id}");

let mut output_folder = PathBuf::from(args.output);
output_folder.push(project_name);
let output_folder = args.output.join(project_name);

let map_iter = [(
OUTPUT_PERSISTENCE_KEY.to_string(),
Expand Down
44 changes: 24 additions & 20 deletions packages/engine/bin/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,73 +11,77 @@ pub mod exsrv;
pub mod manifest;
pub mod process;

use std::path::PathBuf;

use anyhow::Result;
use clap::{AppSettings, Parser};
use experiment::run_experiment;
use structopt::StructOpt;

use crate::exsrv::create_server;

/// The hEngine Command line interface.
///
/// Can run single or simple experiments.
#[derive(Debug, StructOpt)]
/// Arguments passed to the CLI
#[derive(Debug, Parser)]
#[clap(about, version, author)]
#[clap(global_setting(AppSettings::PropagateVersion))]
#[clap(setting(AppSettings::UseLongFormatForHelpSubcommand))]
pub struct Args {
/// Path to the project to be run.
#[structopt(short, long, env = "HASH_PROJECT")]
project: String,
#[clap(short, long, env = "HASH_PROJECT")]
project: PathBuf,

/// The Project Name.
///
/// If not provided, the name of the project directory will be used.
#[structopt(short = "n", long)]
#[clap(short = 'n', long)]
project_name: Option<String>,

/// Project output path folder.
///
/// The folder will be created if it's missing.
#[structopt(short, long, default_value = "./output", env = "HASH_OUTPUT")]
output: String,
#[clap(short, long, default_value = "./output", env = "HASH_OUTPUT")]
output: PathBuf,

/// Experiment type to be run.
#[structopt(subcommand)]
#[clap(subcommand)]
r#type: ExperimentType,

/// Max number of parallel workers (must be power of 2).
#[structopt(short = "w", long, default_value = "4", env = "HASH_WORKERS")]
#[clap(short = 'w', long, default_value = "4", env = "HASH_WORKERS")]
num_workers: u16,
}

/// Type of experiment to be run.
#[derive(Debug, StructOpt)]
#[derive(Debug, clap::Subcommand)]
pub enum ExperimentType {
/// Run a single run experiment.
#[structopt(name = "single-run")]
#[clap(name = "single-run")]
SingleRunExperiment(SingleExperimentArgs),
/// Run a simple experiment.
#[structopt(name = "simple")]
#[clap(name = "simple")]
SimpleExperiment(SimpleExperimentArgs),
// Generate shell completitions
}

/// Single Run Experiment.
#[derive(PartialEq, Debug, StructOpt)]
#[derive(PartialEq, Debug, clap::Args)]
pub struct SingleExperimentArgs {
#[structopt(short, long, env = "HASH_NUM_STEPS")]
/// Number of steps to run.
#[clap(short, long, env = "HASH_NUM_STEPS")]
num_steps: usize,
}

/// Simple Experiment.
#[derive(PartialEq, Debug, StructOpt)]
#[derive(PartialEq, Debug, clap::Args)]
pub struct SimpleExperimentArgs {
/// Name of the experiment to be run.
#[structopt(short = "n", long, env = "HASH_EXPERIMENT")]
#[clap(short = 'n', long, env = "HASH_EXPERIMENT")]
experiment_name: String,
}

#[tokio::main]
async fn main() -> Result<()> {
pretty_env_logger::init();
let args = Args::from_args();
let args = Args::parse();

let nng_listen_url = {
use std::time::{SystemTime, UNIX_EPOCH};
Expand Down
Loading

0 comments on commit 1cfc2e7

Please sign in to comment.