Skip to content

Commit

Permalink
V0.6.0 (#9)
Browse files Browse the repository at this point in the history
* Add aes module

* Add completion module
  • Loading branch information
guoxbin authored Jan 13, 2020
1 parent d7316d1 commit 05efbcb
Show file tree
Hide file tree
Showing 7 changed files with 540 additions and 29 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[package]
name = "dtool"
version = "0.5.0"
version = "0.6.0"
authors = ["GB <[email protected]>"]
description = "A collection of development tools"
description = "A command-line tool collection to assist development"
categories = ["command-line-utilities"]
homepage = "https://github.com/guoxbin/dtool"
repository = "https://github.com/guoxbin/dtool"
license = "GPL-3.0"
readme = "README.md"
keywords = [ "urlencode", "timestamp", "base58", "base64", "hex" ]
keywords = [ "tools", "conversion", "codec", "utilities", "hex" ]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Build Status](https://travis-ci.org/guoxbin/dtool.svg?branch=master)](https://travis-ci.org/guoxbin/dtool)
[![Crates.io](https://img.shields.io/crates/v/dtool)](https://crates.io/crates/dtool)

`dtool` is a command line tool collection to assist development
`dtool` is a command-line tool collection to assist development

## Table of Contents

Expand Down Expand Up @@ -31,6 +31,7 @@ Now `dtool` supports:
- Regex match
- Pbkdf2
- Case conversion (upper, lower, title, camel, pascal, snake, shouty snake, kebab)
- AES encrypt / decrypt

## Usage

Expand Down
19 changes: 19 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use clap::App;
use crate::modules::ModuleManager;

pub fn build_app<'a, 'b>() -> (App<'a, 'b>, ModuleManager<'a, 'b>){

let mut app = App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"));

let module_manager = ModuleManager::new();
let subcommands = module_manager.apps();

for subcommand in subcommands {
app = app.subcommand(subcommand);
}

(app, module_manager)
}
15 changes: 2 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,9 @@
use clap::{App};

mod app;
mod modules;

fn main() {

let mut app = App::new(env!("CARGO_PKG_NAME"))
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"));

let module_manager = modules::ModuleManager::new();
let subcommands = module_manager.apps();

for subcommand in subcommands {
app = app.subcommand(subcommand);
}
let (app, module_manager) = app::build_app();

let mut app_clone = app.clone();

Expand Down
27 changes: 15 additions & 12 deletions src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ mod html;
mod re;
mod usage;
mod pbkdf2;
mod aes;
mod case;
mod completion;

pub struct Command<'a, 'b> {
pub app: App<'a, 'b>,
Expand Down Expand Up @@ -55,29 +57,30 @@ impl<'a, 'b> ModuleManager<'a, 'b> {
mm.register(re::commands());
mm.register(pbkdf2::commands());
mm.register(case::commands());
mm.register(aes::commands());
mm
}

pub fn apps(&self) -> Vec<App<'a, 'b>> {

self.commands.iter().map(|(_, command)| command.app.to_owned()).chain( iter::once(usage::usage_app()) ).collect()
self.commands.iter().map(|(_, command)| command.app.to_owned())
.chain( iter::once(usage::usage_app()) )
.chain(iter::once(completion::completion_app()))
.collect()

}

pub fn run(&self, name: &str, matches: &ArgMatches<'a>) {

if let Some(command) = self.commands.get(name){
match (command.f)(matches){
Ok(result) => result.iter().for_each(|x|println!("{}", x)),
Err(e) => eprintln!("{}", e),
}
}
let result = match name{
"usage" => usage::usage(matches, &self.commands),
"completion" => completion::completion(matches),
_ => (self.commands.get(name).expect("subcommand must exit").f)(matches),
};

if name == "usage" {
match usage::usage(matches, &self.commands){
Ok(result) => result.iter().for_each(|x|println!("{}", x)),
Err(e) => eprintln!("{}", e),
}
match result{
Ok(result) => result.iter().for_each(|x|println!("{}", x)),
Err(e) => eprintln!("{}", e),
}

}
Expand Down
Loading

0 comments on commit 05efbcb

Please sign in to comment.