Skip to content

Commit 7bbc2b2

Browse files
committed
Merge branch 'release/v0.2.1'
2 parents 6950367 + 4971d9e commit 7bbc2b2

File tree

10 files changed

+326
-15
lines changed

10 files changed

+326
-15
lines changed

Cargo.lock

Lines changed: 101 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ readme = "README.md"
1414
[dependencies]
1515
clap = "4.5.34"
1616
colored = "3.0.0"
17+
digest = "0.10.7"
1718
md5 = "0.7.0"
19+
pbr = "1.1.1"
1820

1921
[dev-dependencies]
20-
tempfile = "3.19.1"
22+
tempfile = "3.19.1"

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-blue)
66
![License: MIT](https://img.shields.io/badge/License-MIT-green)
77
![Github Stars](https://img.shields.io/github/stars/WutongDev/wutong?style=flat&color=red)
8-
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT_zh.md)
8+
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
99

1010
[English](./README.md) | [简体中文](./docs/zh/README_zh.md)
1111

@@ -28,6 +28,8 @@ In our daily project development, we frequently encounter situations where we ne
2828

2929
**Wutong** was created to address this issue. It is a command-line tool that allows us to complete various mundane tasks that we may encounter in programming directly within the terminal, thereby significantly enhancing our coding efficiency.
3030

31+
If you wish to learn more about the motivation and purpose of the Sycamore, you can read [Wutong: Developer's command line efficiency application](Wutong%3A%20Developer%27s%20command%20line%20efficiency%20application.md)
32+
3133
---
3234

3335
## How to Install Wutong
@@ -44,14 +46,14 @@ If you are a Windows or Linux user, please wait for the subsequent version.
4446

4547
## How to Use Wutong
4648
You can obtain detailed information by typing `wutong --help` in the command line.
47-
The general functions of Wutong are listed below (v0.2.0):
49+
The general functions of Wutong are listed below (v0.2.1):
4850

4951
| Function | Description |
5052
|----------|--------------------------------------------------------------|
5153
| base | Encode input strings in base32 or base64 |
5254
| bc | Convert input numbers to binary, octal, decimal, hexadecimal |
5355
| color | Convert between RGB and Hex colors |
54-
| md5 | Hash input strings using MD5 |
56+
| md5 | Hash input strings and files using MD5 |
5557
| charcode | Convert string encodings |
5658
| flow | Manage git repositories according to the Gitflow workflow |
5759

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
This article was first published on CSDN [《Wutong: A Command-Line Efficiency Tool for Developers》](https://blog.csdn.net/cat_bayi/article/details/146281331) by Gavin Zheng.
2+
3+
# Why Wutong is Needed
4+
As stated in **Wutong**'s [README document](https://github.com/GavZheng/wutong/blob/main/README.md), data encoding and conversion are among the frequent tasks developers encounter during development. For example, converting strings to Base64 encoding for network transmission or converting numbers to binary formats for low-level operations. These tasks, while simple, are scattered throughout the development workflow, adding unnecessary burdens to developers.
5+
6+
Traditionally, developers need to leave their familiar development environments and search for specialized tools or websites to complete these tasks. This involves switching between multiple applications, performing complex interactions, and manually copying results back to their development environments. This process is not only time-consuming but, more importantly, the frequent context switching disrupts developers' focus, leading to loss of concentration and inspiration. Such interruptions significantly impact productivity, especially during intensive coding sessions.
7+
8+
To address this issue, developers need a tool that can perform these tasks directly within the terminal environment, reducing context switching and maintaining workflow continuity. [**Wutong**](https://github.com/GavZheng/wutong) was born out of this need. Written in **Rust**, **Wutong** is **small** in memory footprint and **fast** in execution speed. It provides an integrated **command-line tool** that embeds common functionalities like data encoding and conversion directly into the terminal. With its simplicity and speed, **Wutong** helps developers complete tasks quickly while avoiding efficiency losses and focus fragmentation caused by frequent tool switching.
9+
10+
# How Wutong Solves This Problem
11+
As a developer, I designed **Wutong** with a philosophy centered on focus, efficiency, and integration. As mentioned in [**Wutong's Contribution Guide**](https://github.com/GavZheng/wutong/blob/main/CONTRIBUTING.md), **Wutong** aims to create a **seamless**, **efficient**, and **integrated** development environment, allowing developers to focus more on the code itself and create outstanding software products.
12+
13+
To demonstrate why this claim holds, consider the following scenario:
14+
If you need to generate an MD5 hash for a piece of text, traditionally, you would:
15+
1. Leave your IDE,
16+
2. Open a browser,
17+
3. Search for "MD5,"
18+
4. Browse and select a website from the results,
19+
5. Copy the text into the website to get the result.
20+
21+
This takes five steps! Your focus would shift at least five times over 30 seconds or more. By the time you return to your IDE, can you still maintain your original train of thought? Worse, if the website doesn’t meet your needs, you might have to backtrack, search again, and repeat the process.
22+
23+
With **Wutong**, you only need one step: type a command and press Enter.
24+
25+
For example, to get the MD5 hash of "wutong," simply run:
26+
```bash
27+
wutong md5 wutong
28+
```
29+
**Wutong** will output the result directly in the terminal.
30+
31+
This is just an example for generating an MD5 hash. What if you need to merge a branch or create a new branch following Gitflow conventions? That could take even more time for research and experimentation, possibly leading to unexpected issues.
32+
33+
With **Wutong**, creating a `feature/wutong` branch is as simple as:
34+
```bash
35+
wutong flow -f wutong
36+
```
37+
38+
# Explore Wutong
39+
You can find **Wutong** on its GitHub repository: [https://github.com/GavZheng/wutong](https://github.com/GavZheng/wutong). **We desperately need** your Star 🌟. Your support not only boosts my confidence and motivation as the author but also determines whether **Wutong** can be published on more platforms. Currently, **Wutong** cannot be added to Homebrew due to insufficient Stars.
40+
41+
# Join Wutong
42+
Unfortunately, **Wutong** currently has only one member—me. As stated in [**Wutong's README**](https://github.com/GavZheng/wutong/blob/main/README.md), I warmly welcome and highly encourage developers worldwide to join and contribute to **Wutong**'s development. In my vision, the **Wutong** community will use English as its primary language, with documentation supporting multiple languages.
43+
44+
If you want to become one of **Wutong**'s first community members or early contributors, please refer to the [**Wutong Contribution Guide**](https://github.com/GavZheng/wutong/blob/main/CONTRIBUTING.md). You must adhere to the [**Contributor Covenant**](https://github.com/GavZheng/wutong/blob/main/docs/zh/CODE_OF_CONDUCT_zh.md) and the [**Contributor License Agreement (CLA)**](https://github.com/GavZheng/wutong/blob/main/CLA.md).

docs/zh/README_zh.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
**梧桐**正是为了解决这个问题而诞生的。它是一个命令行工具,允许我们在终端中直接完成各种在编程中可能遇到的琐屑任务,从而大大提高了我们的编码效率。
3232

33+
如果您想了解更多关于梧桐树的动机和目的,您可以阅读 [梧桐:开发者的命令行效率工具](梧桐:开发者的命令行效率工具.md)
34+
3335
---
3436

3537
## 如何安装梧桐
@@ -45,14 +47,14 @@ PS:仅支持 macOS 13 或更高版本。
4547

4648
## 如何使用梧桐
4749
你可以通过在命令行键入`wutong --help`来获取详细信息。
48-
梧桐的大致功能如下表(v0.2.0
50+
梧桐的大致功能如下表(v0.2.1
4951

5052
| 功能 | 描述 |
5153
|----------|----------------------------|
5254
| base | 将输入的字符串进行base32、base64编码编码 |
5355
| bc | 将输入的数字转换为二、八、十、十六进制 |
5456
| color | RGB和Hex颜色的相互转换 |
55-
| md5 | 将输入的字符串进行md5哈希 |
57+
| md5 | 将输入的字符串和文件进行md5哈希 |
5658
| charcode | 字符串编码转换 |
5759
| flow | 根据 Gitflow 工作流程管理 git 存储库 |
5860

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
本文最早发表于CSDN[《梧桐:开发者的命令行效率应用》](https://blog.csdn.net/cat_bayi/article/details/146281331) 作者Gavin Zheng
2+
3+
# 为什么需要梧桐
4+
正如**梧桐**[Readme文档](https://github.com/GavZheng/wutong/blob/main/README.md)所言,在开发过程中,数据的编码与转换是开发者频繁面临的任务之一。例如,将字符串转换为Base64编码用于网络传输,或者将数字转换为二进制格式以进行底层操作。这些任务虽然简单,但却分散在开发流程中,给开发者带来了额外的负担。
5+
6+
传统上,开发者需要离开熟悉的开发环境,寻找专门的工具或网站来完成这些任务。这不仅包括在多个应用程序之间切换,还涉及复杂的交互操作,最后还需手动复制结果返回到开发环境中。这一过程不仅耗时,更重要的是,频繁的上下文切换会打断开发者的思路,导致专注力的丧失和灵感的流失。这种中断对开发效率的影响是显著的,尤其是在高强度的编码工作中。
7+
8+
为了解决这一问题,开发者需要一个能够在终端环境中直接完成这些任务的工具,从而减少上下文切换的频率,保持开发流程的连贯性。[**梧桐**](https://github.com/GavZheng/wutong)正是基于这样的需求而诞生的。**梧桐****Rust**编写,拥有足够****的内存占用,足够****的速度,它通过提供一个集成的**命令行工具**,将数据编码和转换等常用功能直接嵌入到终端中,用最简单的使用方式和最快的速度帮助开发者快速完成任务,同时避免因频繁切换工具而导致的效率损失和专注力分散。
9+
10+
# 梧桐如何解决这个问题
11+
作为开发者,我在设计之初就将专注、高效与集成定为了**梧桐**的设计哲学。如[**梧桐的贡献者指南**](https://github.com/GavZheng/wutong/blob/main/CONTRIBUTING.md)中所言,**梧桐**的设计哲学是围绕着提升开发者效率和保持专注力展开的,它致力于打造一个**无缝****高效****集成**的开发环境,让开发者能够更专注于代码本身,创造出更加出色的软件产品。
12+
13+
正因如此,**梧桐**的使用将非常简单。为了便于理解这一点,以下通过一个场景说明:
14+
如果你需要获得一个文本的MD5哈希值,传统方式需要:
15+
1. 离开IDE
16+
2. 打开浏览器
17+
3. 搜索"MD5"
18+
4. 从结果中选择网站并输入文本
19+
5. 复制结果返回IDE
20+
21+
这需要整整五步!你的思路会在30秒甚至更长时间内被多次打断。而使用**梧桐**,只需一步:键入命令并回车。
22+
23+
例如,获取"wutong"的MD5哈希值只需运行:
24+
```bash
25+
wutong md5 wutong
26+
```
27+
**梧桐**会直接在命令行输出结果。
28+
29+
这仅仅是生成MD5哈希的示例。如果需要按Gitflow规范合并分支或创建新分支呢?传统方式可能需要更多时间研究甚至遇到意外问题。
30+
31+
而使用**梧桐**创建`feature/wutong`分支只需:
32+
```bash
33+
wutong flow -f wutong
34+
```
35+
36+
# 深入梧桐
37+
你可以在GitHub找到**梧桐**[https://github.com/GavZheng/wutong](https://github.com/GavZheng/wutong)。我们**非常需要**你的Star🌟——这不仅关系作者的信心与动力,也决定**梧桐**能否上线更多平台(当前因Star数量不足无法上线Homebrew)。
38+
39+
# 加入梧桐
40+
目前**梧桐**仅有我一名成员。如[**Readme文档**](https://github.com/GavZheng/wutong/blob/main/README.md)所述,我们热忱欢迎全球开发者加入!社区默认语言为英语,文档支持多语言。若希望成为首批贡献者,请参考[**贡献者指南**](https://github.com/GavZheng/wutong/blob/main/CONTRIBUTING.md),并遵守[**行为准则**](https://github.com/GavZheng/wutong/blob/main/docs/zh/CODE_OF_CONDUCT_zh.md)[**贡献者协议**](https://github.com/GavZheng/wutong/blob/main/CLA.md)

src/main.rs

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,15 @@ mod color;
55
mod flow;
66
mod md5;
77

8-
use clap::{Arg, ArgGroup, Command};
8+
use clap::{Arg, ArgAction, ArgGroup, Command};
99
use colored::Colorize;
10+
use std::io;
11+
12+
#[derive(Debug)]
13+
pub enum Md5Error {
14+
FileNotFound,
15+
IoError(io::Error),
16+
}
1017

1118
#[derive(Debug, Clone, Copy)]
1219
pub enum BranchType {
@@ -65,12 +72,29 @@ fn main() {
6572
),
6673
)
6774
.subcommand(
68-
Command::new("md5").about("MD5 hashing.").arg(
69-
Arg::new("text")
70-
.short('t')
71-
.long("text")
72-
.help("Input text to be hashed."),
73-
),
75+
Command::new("md5")
76+
.about("MD5 hashing")
77+
.arg(
78+
Arg::new("text")
79+
.value_name("TEXT")
80+
.default_value("")
81+
.action(ArgAction::Set)
82+
.help("Input text (default mode)")
83+
.index(1),
84+
)
85+
.arg(
86+
Arg::new("file")
87+
.short('f')
88+
.long("file")
89+
.value_name("PATH")
90+
.action(ArgAction::Set)
91+
.help("Input file path"),
92+
)
93+
.group(
94+
ArgGroup::new("input")
95+
.args(["text", "file"])
96+
.multiple(false),
97+
),
7498
)
7599
.subcommand(
76100
Command::new("charcode")
@@ -235,8 +259,17 @@ fn main() {
235259
_ => panic!("{}", "Error: Invalid base conversion option".red()),
236260
},
237261
Some(("md5", subcommand_md5)) => {
238-
let result = md5::text::md5_text(subcommand_md5.get_one::<String>("text").unwrap());
239-
println!("{}", result);
262+
if let Some(_file_path) = subcommand_md5.get_one::<String>("file") {
263+
let result =
264+
md5::file::md5_file(subcommand_md5.get_one::<String>("file").unwrap().as_ref());
265+
match result {
266+
Ok(result) => println!("{}", result),
267+
Err(error) => println!("{} {:?}", "Error:".red(), error),
268+
}
269+
} else {
270+
let result = md5::text::md5_text(subcommand_md5.get_one::<String>("text").unwrap());
271+
println!("{}", result)
272+
}
240273
}
241274
Some(("charcode", subcommand_charcode)) => {
242275
let result = charcode::ascii_unicode::ascii_unicode(

0 commit comments

Comments
 (0)