Skip to content

feat: Add Args documentation #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,20 @@ export default defineConfig({
},
{ label: "Guides", autogenerate: { directory: "clack/guides" } },
],
},
{
label: "Args",
id: "args",
icon: "seti:shell",
link: "/args/getting-started",
Comment on lines +94 to +97
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

items: [
{ label: "Basics", link: "/args/getting-started" },
{
label: "API",
link: "args/api",
},
{ label: "Guides", autogenerate: { directory: "args/guides" } },
],
}
]),
],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@astrojs/starlight": "^0.32.2",
"@bomb.sh/args": "^0.3.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm do we need to install this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to check, but I'm pretty sure that without it twoslash won't be able to do its magic.

But maybe it can be moved into dev dependencies ? 🤔

"@clack/core": "^0.4.1",
"@clack/prompts": "^0.10.0",
"@types/node": "^22.13.11",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/content/docs/args/api.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
title: Args
description: Learn about the Args package and its capabilities
---
95 changes: 95 additions & 0 deletions src/content/docs/args/getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
title: Getting Started
description: Learn how to get started with Args
---

import { Tabs, TabItem } from '@astrojs/starlight/components';

A <1kB library for parsing CLI flags. Inspired by Deno's `std/cli` [`parseArgs`](https://github.com/denoland/std/blob/main/cli/parse_args.ts) module.

## Features

🤏 very small

🍃 very simple

🏃 very fast (beats [`node:util`](https://nodejs.org/api/util.html#utilparseargsconfig))

🔏 strongly typed

## Installation

You can install Args using npm, yarn, or pnpm:

<Tabs>
<TabItem label="npm" icon="seti:npm">
```bash
npm install @bomb.sh/args
```
</TabItem>
<TabItem label="pnpm" icon="pnpm">
```bash
pnpm add @bomb.sh/args
```
</TabItem>
<TabItem label="Yarn" icon="seti:yarn">
```bash
yarn add @bomb.sh/args
```
</TabItem>
</Tabs>


## Quick Start

Basic usage does not require any configuration.

```ts twoslash
import { parse } from "@bomb.sh/args";

// my-cli build --bundle -rf --a value --b=value --c 1
const argv = process.argv.slice(2);
const args = parse(argv);

console.log(args);
// { _: ['build'], bundle: true, r: true, f: true, a: "value", b: "value", c: 1 }
```

Parsing can be configured to ensure arguments are coerced to specific types, which enhances type safety.

```ts twoslash
import { parse } from "@bomb.sh/args";

const args = parse(process.argv, {
default: { a: 1, b: 2, c: "value" },
alias: { h: "help" },
boolean: ["foo", "bar"],
string: ["baz", "qux"],
array: ["input"],
});
```

## Benchmarks

```
mri x 1,650,986 ops/sec ±0.32% (97 runs sampled)
@bomb.sh/args x 1,407,191 ops/sec ±0.38% (99 runs sampled)
minimist x 383,506 ops/sec ±0.28% (99 runs sampled)
node:util x 320,953 ops/sec ±0.35% (98 runs sampled)
yargs-parser x 31,874 ops/sec ±1.32% (92 runs sampled)
```

## Acknowledgements

This package was previously published as `ultraflag` up until `v0.3.0`, when it was renamed to `@bomb.sh/args`.

## Next Steps

1. Check out our [Examples](/docs/args/guides/examples) for more practical use cases
2. Learn about [Best Practices](/docs/args/guides/best-practices) for building CLIs
3. Explore the [API Reference](/docs/args/api) for detailed documentation
4. Join our [Discord community](https://bomb.sh/chat) for support and discussions

## Contributing

We welcome contributions! Please check out our [Contributing Guide](/contributing) for details on our code of conduct and the process for submitting pull requests.
18 changes: 18 additions & 0 deletions src/content/docs/args/guides/best-practices.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
title: Best Practices
description: Learn the best practices for using Args effectively
---

This guide covers recommended practices and patterns for using Args effectively in your applications.

## General Guidelines

_TBD_

## Performance Considerations

_TBD_

## Accessibility

_TBD_
14 changes: 14 additions & 0 deletions src/content/docs/args/guides/examples.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Examples
description: Learn through practical examples of using Args
---

This guide provides practical examples of using Args in different scenarios.

## Basic Examples

_TBD_

## Advanced Examples

_TBD_