Skip to content

Commit

Permalink
Merge pull request #37 from anton-rs/10-07-feat_cli_subcommands
Browse files Browse the repository at this point in the history
feat(bin): cli subcommands
  • Loading branch information
refcell authored Oct 7, 2023
2 parents 454fbcf + 84ce227 commit 5839a0b
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions bin/opup/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,50 @@
use clap::{ArgAction, Parser};
use clap::{ArgAction, Parser, Subcommand};
use eyre::Result;
use std::path::PathBuf;

/// Command line arguments
#[derive(Parser, Debug)]
#[command(author, version, about)]
#[command(author, version, about, long_about = None)]
pub struct Args {
/// Verbosity level (0-4)
#[arg(long, short, action = ArgAction::Count, default_value = "2")]
v: u8,

/// The subcommand to run
#[clap(subcommand)]
pub command: Option<Command>,

/// An optional path to a stack config file.
#[arg(long, short)]
config: Option<PathBuf>,
}

/// Possible CLI subcommands
#[derive(Debug, Subcommand)]
pub enum Command {
/// Build and run the devnet stack
Up,
/// Bring the devnet stack down
Down,
/// Nuke the devnet stack
Nuke,
/// Clean all stack artifacts
Clean,
}

pub fn run() -> Result<()> {
let Args { v, config } = Args::parse();
let Args { v, config, command } = Args::parse();

crate::telemetry::init_tracing_subscriber(v)?;

crate::banners::banner()?;

// todo: switch on subcommands
// default should be to run the devnet stack
// should also allow nuking the devnet
// and stopping an already running devnet
match command {
Some(Command::Up) | None => crate::stack::Stack::new(config).run()?,
Some(Command::Down) => unimplemented!("down command not yet implemented"),
Some(Command::Nuke) => unimplemented!("nuke command not yet implemented"),
Some(Command::Clean) => unimplemented!("clean command not yet implemented"),
}

crate::stack::Stack::new(config).run()
Ok(())
}

0 comments on commit 5839a0b

Please sign in to comment.