Hello, I'm an open source software engineer in my late 30s living in #Seoul, #Korea, and an avid advocate of #FLOSS and the #fediverse.
I'm the creator of @fedify, an #ActivityPub server framework in #TypeScript, @hollo, an ActivityPub-enabled microblogging software for single users, and @botkit, a simple ActivityPub bot framework.
A new drawing community called https://oeee.cafe (@oeee_cafe) made by @jihyeok and others just implemented #ActivityPub and joined the #fediverse. It's exciting to see niche art focused software using these tools and techniques to share in our weird network we have here.
Excited to share some great news from the #creative community! Oeee Cafe, a fantastic oekaki#drawing platform, just added #ActivityPub support today. This means all the amazing artwork being created there can now be shared and discovered across the #fediverse, which is such a wonderful step toward connecting creative communities.
Big shoutout to my friend @jihyeok for building this platform and bringing it to the fediverse. It's always inspiring to see developers creating spaces for artists and then opening them up to the broader federated community. If you're into digital art or just appreciate seeing creative work, definitely worth checking out what people are sharing from Oeee Cafe on your timeline now. You can find me there at @hongminhee if you want to connect!
I added ActivityPub support to Oeee Cafe, which is a safe-for-work Oekaki-style drawing board.
You can view the handles for artists or communities you like in the profile or the community main page. Subscribe and get new artwork right in your Fediverse timeline!
Special thanks to @hongminhee who helped me implement ActivityPub. Quoted is his drawing in the early days of Oeee Cafe.
Show GN: Optique: TypeScript를 위한 타입 안전한 CLI 파서 ------------------------------ 안녕하세요! TypeScript로 CLI 도구를 자주 만들다 보니 기존 라이브러리들의 한계가 아쉬워서 새로운 CLI 파서를 만들게 되었습니다. 혹시 관심 있으신 분들께 소개해보고 싶어 글을 올립니다.
Coming soon on your Mastodon server… The long awaited quote posts, with user-control (you can chose if you want to be quoted on a per-post basis, change it later, and retract any quote of your post)
Amazing work by the team 🎉
Expect a blog post with all the details in a few weeks, support in the mobile apps, then we will enable the feature on mastodon.social, then release Mastodon 4.5
I've recently been working on Optique, a CLI parser combinator for TypeScript. Optique allows you to describe complex CLIs by combining smaller parts. You can also handle the CLI parsing results in a type-safe manner (see code below). The idea came from Haskell's optparse-applicative, but since TypeScript's API style is so different from Haskell's, I referenced Zod and similar libraries for the API design. For a more detailed introduction, please refer to the article I posted on Hackers' Pub!
ALT text detailsconst parser = or(
object({
type: constant("network"),
host: option(
"-h", "--host",
string({ metavar: "HOST" }),
),
port: option(
"-p", "--port",
integer({ metavar: "PORT", min: 0, max: 65535 }),
),
}),
object({
type: constant("local"),
file: option(
"-s", "--socket-file",
string({ metavar: "FILE" }),
),
}),
)
type Result = InferValue<typeof parser>;
// The above type is inferred as:
type Result = {
readonly type: "network";
readonly host: string;
readonly port: number;
} | {
readonly type: "local";
readonly file: string;
}
최근 Optique라는 다소 실험적인 CLI 파서 라이브러리를 제작하게 되었습니다. 이 글을 쓰는 2025년 8월 21일 시점으로 아직 0.1.0도 릴리스되지 않았지만, 나름대로 재미있는 발상이라고 생각해서 이 글을 통해 소개합니다.
Optique는 크게 두 가지 다른 라이브러리로부터 영향을 받았습니다. 하나는 Haskell의 optparse-applicative라는 라이브러리인데, 이 라이브러리로부터 얻은 교훈은 CLI 파서도 파서 컴비네이터가 될 수 있고, 그렇게 만들었을 때 매우 유용하다는 사실입니다. 다른 하나는 TypeScript 사용자들에게 이미 익숙한 Zod입니다. 비록 optparse-applicative에서 아이디어의 줄기를 얻긴 했지만, Haskell과 TypeScript는 너무나 다른 언어라서 API를 구성하는 방식에 큰 차이가 있습니다. 그래서 API를 구성하는 방식에 있어서는 Zod를 비롯한 여러 유효성 검사 라이브러리를 참고하게 되었습니다.
Optique는 여러 작은 파서들과 파서 컴비네이터들을 레고 부품처럼 조립하여 CLI가 어떠한 모양이어야 하는지를 표현합니다. 예를 들어 가장 작은 부품 중 하나로는 option()이 있습니다:
const parser = option("-a", "--allow", url());
이 파서를 실행하려면 run()이라는 API를 사용하면 됩니다:
(참고로 run() 함수는 암시적으로 process.argv.slice(2)를 읽습니다.)
const allow: URL = run(parser);
위 코드에서 제가 일부러 URL이라는 타입을 명시하긴 했지만, 굳이 그렇게 하지 않아도 저절로 URL 타입으로 추론됩니다. 위 파서는 -a/--allow=URL 옵션만을 받아들입니다. 다른 옵션이나 인자를 줄 경우 오류가 납니다. -a/--allow=URL 옵션이 주어지지 않아도 오류가 납니다.
만약 -a/--allow=URL 옵션을 필수가 아닌 선택으로 두려면 어떻게 해야 할까요? 그럴 때는 optional() 컴비네이터로 option() 파서를 감싸면 됩니다.
prog -a https://example.com/ --allow https://hackers.pub/prog -d https://example.com/ --disallow https://hackers.pub/
하지만 다음과 같이 -a/--allow=URL 옵션과 -d/--disallow=URL 옵션이 섞여있을 때는 오류를 냅니다:
prog -a https://example.com/ --disallow https://hackers.pub/
아무튼, 그럼 이 파서의 결과는 어떤 타입이 될까요?
const result: readonly URL[] = run(parser);
이런, or() 컴비네이터가 감싸는 2개의 파서 모두 readonly URL[] 타입의 값을 만들기 때문에 readonly URL[] | readonly URL[] 타입이 되어, 결과적으로 readonly URL[] 타입이 되어버렸습니다. 제대로 된 변별 공용체(discriminated union) 형식으로 바꾸고 싶군요. 아래와 같은 타입이면 좋을 것 같습니다.
변별자(discriminator)를 부여하기 위해 constant() 파서도 사용했습니다. 이 파서는 조금 특이한 파서인데, 아무 것도 읽지 않고 주어진 값을 만들기만 합니다. 즉, 항상 성공하는 파서입니다. 이렇게 변별 공용체를 구성할 때 주로 쓰이지만, 다른 창의적인 방식으로도 쓰일 수 있을 겁니다.
같은 방식을 응용하면 겹쳐진 서브커맨드(nested subcommands)도 구현할 수 있겠죠?
자, 이렇게 Optique가 CLI를 표현하는 방식을 보여드렸는데요. 어떤 것 같나요? Optique의 방식이 복잡한 CLI를 표현하기에 적합하다는 게 와닿으시나요?
물론, Optique의 방식도 완벽하지는 않습니다. 아주 전형적이고 단순한 CLI를 정의하는 데에는 오히려 더 손이 가는 것도 사실입니다. 또한, Optique는 오로지 CLI 파서의 역할만 하고 있기 때문에 일반적인 CLI 앱 프레임워크가 제공하는 다양한 기능은 제공하지 않기도 합니다. (추후 Optique에 더 많은 기능을 추가할 예정이긴 합니다만…)
그럼에도 Optique의 접근 방식에 흥미를 느끼셨다면, 소개 문서나 튜토리얼도 한 번 살펴보시기 바랍니다.
최근 Optique라는 다소 실험적인 CLI 파서 라이브러리를 제작하게 되었습니다. 이 글을 쓰는 2025년 8월 21일 시점으로 아직 0.1.0도 릴리스되지 않았지만, 나름대로 재미있는 발상이라고 생각해서 이 글을 통해 소개합니다.
Optique는 크게 두 가지 다른 라이브러리로부터 영향을 받았습니다. 하나는 Haskell의 optparse-applicative라는 라이브러리인데, 이 라이브러리로부터 얻은 교훈은 CLI 파서도 파서 컴비네이터가 될 수 있고, 그렇게 만들었을 때 매우 유용하다는 사실입니다. 다른 하나는 TypeScript 사용자들에게 이미 익숙한 Zod입니다. 비록 optparse-applicative에서 아이디어의 줄기를 얻긴 했지만, Haskell과 TypeScript는 너무나 다른 언어라서 API를 구성하는 방식에 큰 차이가 있습니다. 그래서 API를 구성하는 방식에 있어서는 Zod를 비롯한 여러 유효성 검사 라이브러리를 참고하게 되었습니다.
Optique는 여러 작은 파서들과 파서 컴비네이터들을 레고 부품처럼 조립하여 CLI가 어떠한 모양이어야 하는지를 표현합니다. 예를 들어 가장 작은 부품 중 하나로는 option()이 있습니다:
const parser = option("-a", "--allow", url());
이 파서를 실행하려면 run()이라는 API를 사용하면 됩니다:
(참고로 run() 함수는 암시적으로 process.argv.slice(2)를 읽습니다.)
const allow: URL = run(parser);
위 코드에서 제가 일부러 URL이라는 타입을 명시하긴 했지만, 굳이 그렇게 하지 않아도 저절로 URL 타입으로 추론됩니다. 위 파서는 -a/--allow=URL 옵션만을 받아들입니다. 다른 옵션이나 인자를 줄 경우 오류가 납니다. -a/--allow=URL 옵션이 주어지지 않아도 오류가 납니다.
만약 -a/--allow=URL 옵션을 필수가 아닌 선택으로 두려면 어떻게 해야 할까요? 그럴 때는 optional() 컴비네이터로 option() 파서를 감싸면 됩니다.
prog -a https://example.com/ --allow https://hackers.pub/prog -d https://example.com/ --disallow https://hackers.pub/
하지만 다음과 같이 -a/--allow=URL 옵션과 -d/--disallow=URL 옵션이 섞여있을 때는 오류를 냅니다:
prog -a https://example.com/ --disallow https://hackers.pub/
아무튼, 그럼 이 파서의 결과는 어떤 타입이 될까요?
const result: readonly URL[] = run(parser);
이런, or() 컴비네이터가 감싸는 2개의 파서 모두 readonly URL[] 타입의 값을 만들기 때문에 readonly URL[] | readonly URL[] 타입이 되어, 결과적으로 readonly URL[] 타입이 되어버렸습니다. 제대로 된 변별 공용체(discriminated union) 형식으로 바꾸고 싶군요. 아래와 같은 타입이면 좋을 것 같습니다.
변별자(discriminator)를 부여하기 위해 constant() 파서도 사용했습니다. 이 파서는 조금 특이한 파서인데, 아무 것도 읽지 않고 주어진 값을 만들기만 합니다. 즉, 항상 성공하는 파서입니다. 이렇게 변별 공용체를 구성할 때 주로 쓰이지만, 다른 창의적인 방식으로도 쓰일 수 있을 겁니다.
같은 방식을 응용하면 겹쳐진 서브커맨드(nested subcommands)도 구현할 수 있겠죠?
자, 이렇게 Optique가 CLI를 표현하는 방식을 보여드렸는데요. 어떤 것 같나요? Optique의 방식이 복잡한 CLI를 표현하기에 적합하다는 게 와닿으시나요?
물론, Optique의 방식도 완벽하지는 않습니다. 아주 전형적이고 단순한 CLI를 정의하는 데에는 오히려 더 손이 가는 것도 사실입니다. 또한, Optique는 오로지 CLI 파서의 역할만 하고 있기 때문에 일반적인 CLI 앱 프레임워크가 제공하는 다양한 기능은 제공하지 않기도 합니다. (추후 Optique에 더 많은 기능을 추가할 예정이긴 합니다만…)
그럼에도 Optique의 접근 방식에 흥미를 느끼셨다면, 소개 문서나 튜토리얼도 한 번 살펴보시기 바랍니다.