Skip to content

Commit

Permalink
Merge pull request #4 from opeolluwa/dev
Browse files Browse the repository at this point in the history
refactor
  • Loading branch information
opeolluwa authored Aug 24, 2023
2 parents f0fb709 + f212b41 commit 2d810db
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 50 deletions.
41 changes: 3 additions & 38 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,11 @@
use clap::{Parser, Subcommand};
use commands::{
download::DownloadCommands, email::EmailCommands, gitignore::GitIgnoreCommands,
readme::ReadmeCommands, sms::SmsCommands,
};
use include_dir::{include_dir, Dir};

use parser::Utils;
pub const SOURCE_DIR: Dir = include_dir!("src/templates");

mod commands;
mod parser;
mod utils;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
struct Utils {
#[command(subcommand)]
command: Commands,
}

#[derive(Subcommand)]
enum Commands {
/// download files, videos, etc
Download(DownloadCommands),
/// send email
Email(EmailCommands),
/// generate project readmes
Readme(ReadmeCommands),
///send SMS
Sms(SmsCommands),
/// handle git operations
// Git(GitCommands),
/// include .gitignore
GitIgnore(GitIgnoreCommands),
}

fn main() {
let utils = Utils::parse();

match utils.command {
// Commands::Download(download) => DownloadCommands::parse(),
Commands::GitIgnore(git_ignore) => git_ignore.parse(),
// Commands::Git(git) => git.parse(),
Commands::Readme(readme) => readme.parse(),
_ => panic!(),
}
Utils::run();
}
51 changes: 39 additions & 12 deletions src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,43 @@
/// the core parser
/// the Utils struct shall bear other subcommands
use clap::{Parser, Subcommand};
use commands::{
download::DownloadCommands, email::EmailCommands, gitignore::GitIgnoreCommands,
readme::ReadmeCommands, sms::SmsCommands,
};

use crate::commands;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Utils {
//sub commands
command: UtilSubCommands,
// add config parser
#[command(subcommand)]
pub command: Commands,
}

impl Utils {
pub fn run() {
let utils = Utils::parse();

match utils.command {
Commands::GitIgnore(git_ignore) => git_ignore.parse(),
Commands::Readme(readme) => readme.parse(),
_ => panic!(),
}
}
}

/// the utils sub commands
pub enum UtilSubCommands {
/// the readme parser

/// the gitignore parser
/// the youtube video downloader
/// git and github repository parser
#[derive(Subcommand)]
pub enum Commands {
/// download files, videos, etc
Download(DownloadCommands),
/// send email
Email(EmailCommands),
/// generate project readmes
Readme(ReadmeCommands),
///send SMS
Sms(SmsCommands),
/// handle git operations
// Git(GitCommands),
/// include .gitignore
GitIgnore(GitIgnoreCommands),
}

0 comments on commit 2d810db

Please sign in to comment.