Schniz/cmd-ts — dự án backend — đang có 366 sao GitHub trong nhóm Backend. 💻 A type-driven command line argument parser
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
💻 A type-driven command line argument parser, with awesome error reporting 🤤
Not all command line arguments are strings, but for some reason, our CLI parsers force us to use strings everywhere. 🤔 cmd-ts is a fully-fledged command line argument parser, influenced by Rust's clap and structopt:
🤩 Awesome autocomplete, awesome safeness
🎭 Decode your own custom types from strings with logic and context-aware error handling
That works okay. But we can do better. In which ways?
Error handling is out of the command line argument parser context, and in userland, making things less consistent and pretty.
It shows we lack composability and encapsulation — and we miss a way to distribute shared "command line" behavior.
What if we had a way to get a Stream out of the parser, instead of a plain string? This is where cmd-ts gets its power from, custom type decoding:
// ReadStream.ts
import { Type } from 'cmd-ts';
import fs from 'fs';
// Type<string, Stream> reads as "A type from `string` to `Stream`"
const ReadStream: Type<string, Stream> = {
async from(str) {
if (!fs.existsSync(str)) {
// Here is our error handling!
throw new Error('File not found');
}
return fs.createReadStream(str);
},
};
Now we can use (and share) this type and always get a Stream, instead of carrying the implementation detail around:
Encapsulating runtime behaviour and safe type conversions can help us with awesome user experience:
We can throw an error when the file is not found
We can try to parse the string as a URI and check if the protocol is HTTP, if so - make an HTTP request and return the body stream
We can see if the string is -, and when it happens, return process.stdin like many Unix applications
And the best thing about it — everything is encapsulated to an easily tested type definition, which can be easily shared and reused. Take a look at io-ts-types, for instance, which has types like DateFromISOString, NumberFromString and more, which is something we can totally do.
Inspiration
This project was previously called clio-ts, because it was based on io-ts. This is no longer the case, because I want to reduce the dependency count and mental overhead. I might have a function to migrate types between the two.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/Schniz/cmd-ts là nguồn chính thức.
Schniz/cmd-ts có bao nhiêu sao?
Schniz/cmd-ts có 366 sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/Schniz/cmd-ts. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
Schniz/cmd-ts có phải mã nguồn mở không?
Có — Schniz/cmd-ts phát hành theo license MIT, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/Schniz/cmd-ts.
Schniz/cmd-ts còn đang phát triển không?
Commit gần nhất trên Schniz/cmd-ts là 8 ngày trước (theo timestamp GitHub). Repo có 33 fork — một chỉ báo về mức độ quan tâm của cộng đồng.
Schniz/cmd-ts là gì?
Schniz/cmd-ts (Schniz/cmd-ts) là dự án TypeScript trên GitHub. Theo mô tả gốc: 💻 A type-driven command line argument parser
Schniz/cmd-ts so với các dự án Backend khác thế nào?
Schniz/cmd-ts được TopGit xếp vào nhóm Backend, với 366 sao GitHub và viết bằng TypeScript. Xem trang chủ đề Backend trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
Vẫn đang phân vân về cmd-ts?
Một cú bấm sẽ gửi câu hỏi kèm trang này cho AI — xem AI nói gì về cmd-ts.