笔者此前没开发过 Rust Cli
于是在业余时间作为练手搞了个命令行一笔画绘线工具: Stroke
工具架构
. ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── src │ └── main.rs └── target
使用 Clap + Cai架构图怎么画ro RS 作为项目基础
clap = { version = "3.1.10", features = ["derive"] } cairo-rs = { version = "0.15.10", features = ["png"] }
设计 Clap Cli 接口定义
struct Stroke {
#[clap(short, long, default_value = "00ffff")]
color: String,
#[clap(short, long, default_value = "output.png")]
output: String,
#[clap(short, long)]
view: bool,
to: Vec<f64>,
}
设计 [解析]+[绘制] 的主要流程
let stk = Stroke::parse(); let (points, size) = stk.get_points_and_size(); if points.len() < 2 { println!("n Maybe you need run:n stroke -h"); return; } stk.draw(points, size); stk.open();
创建 Homebrew Tap
class Stroke < Formula desc "A MacOS command stroke tool written in Rust" homepage "https://github.com/meloalright/stroke" url "https://github.com/meloalright/stroke/releases/download/0.1.2/stroke.zip" sha256 "cfb991af3fa6012fd59002a33077c6a1921721e4f9e2324c09e1897a2af07be3" license "MIT" def install bin.install "stroke" system "#{bin}/stroke -V" end test do system "#{bin}/stroke -V" end end
跑一下试试

鸣谢
感谢大家阅读 欢迎提出建议 或者点个 ⭐️
仓库链接 Repo: Stroke
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)