
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
bun i comline
comline makes it easy to turn a typescript function into a command line tool.
let's say we have the following function defined in greet.ts
:
/**
* @param {string} name
* @param {number} age
* @returns {string}
*/
function greet(name: string, age: number): string {
return `Hello, ${name}!`;
}
create a greet.x.ts
file with the following contents:
import { greet } from "./greet";
import { cli, parseNumberArg, parseStringArg } from "comline";
import { z } from "zod/v4";
const greetCli = cli({
cliName: "greet",
discoverConfigPath: (positionalArgs) =>
path.join(process.cwd(), `.greet-config.json`),
optionsSchema: z.object({
name: z.string(),
age: z.number(),
}),
options: {
name: {
description: `name`,
example: `--name=hello`,
flag: `n`,
parse: parseStringArg,
required: true,
},
age: {
description: `age`,
example: `--age=1`,
flag: `a`,
parse: parseNumberArg,
required: true,
},
},
});
const {
suppliedOptions: { name, age },
} = greetCli(process.argv);
const output = greet(name, age);
process.stdout.write(output);
then, run the file greet.x.ts
with the following command:
bun greet.x.ts --name=jeremybanka --age=1
this will print Hello, jeremybanka!
switches (--age
)
""
will be provided to the parse function for age
in this case switches with values (--age=1
)
"1"
will be provided to the parse function for age
in this case multiple instances of the same switch (--age=1 --age=2
)
"1,2"
will be provided to the parse function for age
in this case flags (-a
)
""
will be provided to the parse function for age
in this case multiple instances of the same flag (-aa
)
","
will be provided to the parse function for age
in this case flags with values (-a=1
)
"1"
will be provided to the parse function for age
in this case combined flags (-na
)
""
will be provided to the parse function for name
in this case""
will be provided to the parse function for age
in this case positional arguments (my-cli -- positional
)
import type { Tree, TreePath } from "comline";
import { optional, required } from "comline";
const myTree = required({
hello: optional({
world: null,
$name: optional({
good: required({
morning: null,
}),
}),
}),
}) satisfies Tree;
const validPaths: TreePath<typeof myTree>[] = [
[`hello`],
[`hello`, `world`],
[`hello`, `jeremybanka`],
[`hello`, `jeremybanka`, `good`, `morning`],
];
--
convention.=
to separate the option name from the value.FAQs
```sh bun i comline ```
The npm package comline receives a total of 1,469 weekly downloads. As such, comline popularity was classified as popular.
We found that comline demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.