Skip to content

Commit 05efbcb

Browse files
authored
V0.6.0 (#9)
* Add aes module * Add completion module
1 parent d7316d1 commit 05efbcb

File tree

7 files changed

+540
-29
lines changed

7 files changed

+540
-29
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "dtool"
3-
version = "0.5.0"
3+
version = "0.6.0"
44
authors = ["GB <[email protected]>"]
5-
description = "A collection of development tools"
5+
description = "A command-line tool collection to assist development"
66
categories = ["command-line-utilities"]
77
homepage = "https://github.com/guoxbin/dtool"
88
repository = "https://github.com/guoxbin/dtool"
99
license = "GPL-3.0"
1010
readme = "README.md"
11-
keywords = [ "urlencode", "timestamp", "base58", "base64", "hex" ]
11+
keywords = [ "tools", "conversion", "codec", "utilities", "hex" ]
1212
edition = "2018"
1313

1414
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![Build Status](https://travis-ci.org/guoxbin/dtool.svg?branch=master)](https://travis-ci.org/guoxbin/dtool)
44
[![Crates.io](https://img.shields.io/crates/v/dtool)](https://crates.io/crates/dtool)
55

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

88
## Table of Contents
99

@@ -31,6 +31,7 @@ Now `dtool` supports:
3131
- Regex match
3232
- Pbkdf2
3333
- Case conversion (upper, lower, title, camel, pascal, snake, shouty snake, kebab)
34+
- AES encrypt / decrypt
3435

3536
## Usage
3637

src/app.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use clap::App;
2+
use crate::modules::ModuleManager;
3+
4+
pub fn build_app<'a, 'b>() -> (App<'a, 'b>, ModuleManager<'a, 'b>){
5+
6+
let mut app = App::new(env!("CARGO_PKG_NAME"))
7+
.version(env!("CARGO_PKG_VERSION"))
8+
.author(env!("CARGO_PKG_AUTHORS"))
9+
.about(env!("CARGO_PKG_DESCRIPTION"));
10+
11+
let module_manager = ModuleManager::new();
12+
let subcommands = module_manager.apps();
13+
14+
for subcommand in subcommands {
15+
app = app.subcommand(subcommand);
16+
}
17+
18+
(app, module_manager)
19+
}

src/main.rs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
1-
use clap::{App};
2-
1+
mod app;
32
mod modules;
43

54
fn main() {
65

7-
let mut app = App::new(env!("CARGO_PKG_NAME"))
8-
.version(env!("CARGO_PKG_VERSION"))
9-
.author(env!("CARGO_PKG_AUTHORS"))
10-
.about(env!("CARGO_PKG_DESCRIPTION"));
11-
12-
let module_manager = modules::ModuleManager::new();
13-
let subcommands = module_manager.apps();
14-
15-
for subcommand in subcommands {
16-
app = app.subcommand(subcommand);
17-
}
6+
let (app, module_manager) = app::build_app();
187

198
let mut app_clone = app.clone();
209

src/modules.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ mod html;
1515
mod re;
1616
mod usage;
1717
mod pbkdf2;
18+
mod aes;
1819
mod case;
20+
mod completion;
1921

2022
pub struct Command<'a, 'b> {
2123
pub app: App<'a, 'b>,
@@ -55,29 +57,30 @@ impl<'a, 'b> ModuleManager<'a, 'b> {
5557
mm.register(re::commands());
5658
mm.register(pbkdf2::commands());
5759
mm.register(case::commands());
60+
mm.register(aes::commands());
5861
mm
5962
}
6063

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

63-
self.commands.iter().map(|(_, command)| command.app.to_owned()).chain( iter::once(usage::usage_app()) ).collect()
66+
self.commands.iter().map(|(_, command)| command.app.to_owned())
67+
.chain( iter::once(usage::usage_app()) )
68+
.chain(iter::once(completion::completion_app()))
69+
.collect()
6470

6571
}
6672

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

69-
if let Some(command) = self.commands.get(name){
70-
match (command.f)(matches){
71-
Ok(result) => result.iter().for_each(|x|println!("{}", x)),
72-
Err(e) => eprintln!("{}", e),
73-
}
74-
}
75+
let result = match name{
76+
"usage" => usage::usage(matches, &self.commands),
77+
"completion" => completion::completion(matches),
78+
_ => (self.commands.get(name).expect("subcommand must exit").f)(matches),
79+
};
7580

76-
if name == "usage" {
77-
match usage::usage(matches, &self.commands){
78-
Ok(result) => result.iter().for_each(|x|println!("{}", x)),
79-
Err(e) => eprintln!("{}", e),
80-
}
81+
match result{
82+
Ok(result) => result.iter().for_each(|x|println!("{}", x)),
83+
Err(e) => eprintln!("{}", e),
8184
}
8285

8386
}

0 commit comments

Comments
 (0)