Skip to content

Commit

Permalink
move commands to other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
HectorCastelli committed Jan 5, 2024
1 parent 29f12aa commit 0c01ddd
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 38 deletions.
21 changes: 21 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use clap::Subcommand;

mod assemble;
mod initialize;

#[derive(Subcommand)]
pub(crate) enum Commands {
Assemble(assemble::Assemble),
Initialize(initialize::Initialize),
}

trait CommandExecutor {
fn execute(&self);
}

pub(crate) fn execute_command(command: Commands) {
match command {
Commands::Assemble(a) => a.execute(),
Commands::Initialize(a) => a.execute(),
}
}
25 changes: 25 additions & 0 deletions src/commands/assemble.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use std::path::PathBuf;

use clap::Args;
use log::{debug, trace};

use super::CommandExecutor;

#[derive(Args)]
/// Assembles a powerd6 module from a directory
pub(crate) struct Assemble {
/// The path of the directory to be assembled
#[arg(short, long, default_value = "./")]
pub(crate) config: PathBuf,
}

impl CommandExecutor for Assemble {
fn execute(&self) {
trace!("Executing assemble");
debug!("Open config directory: {:?}", self.config);
debug!("Assemble module information");
debug!("Assemble authors information");
debug!("Assemble schema information");
debug!("Assemble contents information");
}
}
28 changes: 28 additions & 0 deletions src/commands/initialize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::path::PathBuf;

use clap::Args;
use log::{debug, trace};

use super::CommandExecutor;

#[derive(Args)]
/// Initializes a directory for a powerd6 module
pub(crate) struct Initialize {
/// The path of the directory to be initialized
#[arg(short, long, default_value = "./")]
pub(crate) config: PathBuf,
}

impl CommandExecutor for Initialize {
fn execute(&self) {
trace!("Executing initialize");
debug!(
"Create config directory if not exists: {:?}",
self.config
);
debug!("Create module.yaml");
debug!("Create authors directory");
debug!("Create schema directory");
debug!("Create contents directory");
}
}
47 changes: 9 additions & 38 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use std::path::PathBuf;

use clap::{Parser, Subcommand, ValueEnum};
use log::{LevelFilter, trace, error, debug};
use clap::{Parser, ValueEnum};
use log::{LevelFilter, trace};
use simplelog::{ColorChoice, CombinedLogger, Config, TermLogger, TerminalMode};

use crate::commands::Commands;

mod commands;

#[derive(Parser)]
#[command(version, about)]
struct Cli {
/// Turn debugging information on
#[arg(short, long, global=true, value_enum, default_value_t=LogLevel::Info)]
log_level: LogLevel,

#[command(subcommand, )]
#[command(subcommand)]
command: Commands,
}

Expand All @@ -38,21 +40,6 @@ impl Into<LevelFilter> for LogLevel {
}
}

#[derive(Subcommand)]
enum Commands {
/// Assembles a powerd6 module from a directory
Assemble {
/// The path of the directory to be assembled
#[arg(short, long, default_value = "./")]
config: PathBuf,
},
/// Initializes a directory for a powerd6 module
Initialize {
/// The path of the directory to be initialized
#[arg(short, long, default_value = "./")]
config: PathBuf,
},
}

fn main() {
// Parse input
Expand All @@ -68,22 +55,6 @@ fn main() {
.unwrap();
trace!("Loggers initialized!");

match &cli.command {
Commands::Assemble { config } => {
trace!("Executing assemble");
debug!("Open config directory: {:?}", config);
debug!("Assemble module information");
debug!("Assemble authors information");
debug!("Assemble schema information");
debug!("Assemble contents information");
},
Commands::Initialize { config } => {
trace!("Executing initialize");
debug!("Create config directory if not exists: {:?}", config);
debug!("Create module.yaml");
debug!("Create authors directory");
debug!("Create schema directory");
debug!("Create contents directory");
},
}
trace!("Executing command");
commands::execute_command(cli.command)
}

0 comments on commit 0c01ddd

Please sign in to comment.