
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
@benev/argv
Advanced tools
@benev/argv
the greatest command line parser for typescript, maybe
๐ค for making node cli programs
๐ต๏ธ incredible typescript type inference
๐งผ zero dependencies
๐ made free and open source, just for you
--help
pagespizza --help
pizza large --pepperoni --slices 3
# or, any way you like it
pizza --slices=9 large
pizza medium -p --slices=5
pizza small --pepperoni="no" --slices="2"
cli
@benev/argv
via npm
npm i @benev/argv
import {cli, command, arg, param, string, number} from "@benev/argv"
const {args, params} = cli(process.argv, {
name: "pizza",
commands: command({
args: [
arg("size").required(string),
],
params: {
slices: param.default(number, "1"),
pepperoni: param.flag("p"),
},
}),
}).tree
args.size // "large"
params.slices // 5
params.pepperoni // true
args
and params
command({
args: [],
params: {},
})
help
string
command({
help: "what a time to be alive!",
args: [],
params: {},
})
command({
args: [
arg("active").required(boolean),
arg("count").default(number, "101"),
arg("name").optional(string),
],
params: {},
})
required
, default
, and optional
default
requires a fallback valuestring
, number
, and boolean
, but you can make your own typescommand({
args: [],
params: {
active: param.required(boolean),
count: param.default(number, "101"),
name: param.optional(string),
verbose: param.flag("-v"),
},
})
flag
, of course, it's automatically a boolean
(how could it be otherwise?)validate
function on any arg
or param
arg("quality").optional(number, {
validate: n => {
if (n > 100) throw new Error("to big")
if (n < 0) throw new Error("to smol")
return n
},
})
validate
, it will be printed all nice-like to the userhelp
literally everywhere!arg
and param
can have its own help
command({
help: "it's the best command, nobody makes commands like me",
args: [
arg("active").required(boolean, {
help: "all systems go?",
}),
arg("count").default(number, "101", {
help: "number of dalmatians",
}),
arg("name").optional(string, {
help: `
see this multi-line string?
it will be trimmed all nicely on the help page.
`
}),
],
params: {
active: param.required(boolean, {
help: "toggle this carefully!",
}),
count: param.default(number, "101", {
help: "classroom i'm late for",
}),
name: param.optional(string, {
help: "pick your pseudonym",
}),
verbose: param.flag("-v", {
help: "going loud",
}),
},
})
list
helperparam.required(list(string))
list
helper
mp3,wav,ogg
["mp3", "wav", "ogg"]
param.required(list(number))
number[]
array (not strings)list
preserves the type's validationchoice
helperparam.required(string, choice(["thick", "thin"]))
param.required(string, choice(["thick", "thin"], {
help: "made with organic whole-wheat flour",
}))
multipleChoice
helperparam.required(string, multipleChoice(["bacon", "lettuce", "tomatoes"]))
param.required(string, choice(["bacon", "lettuce", "tomatoes"], {
help: "all available ingredients are gmo'd",
zeroAllowed: true, // defaults to false
}))
commands
commands
object is a recursive tree with command
leaves
const {tree} = cli(process.argv, {
name: "converter",
commands: {
image: command({
args: [],
params: {
quality: param.required(number),
},
}),
media: {
audio: command({
args: [],
params: {
mono: param.required(boolean),
},
}),
video: command({
args: [],
params: {
codec: param.required(string),
},
})
},
},
})
tree
object that reflects its shape
tree.image?.params.quality // 9
tree.media.audio?.mono // false
tree.media.video?.codec // "av1"
undefined
except for the "selected" commandexecute
function
command({
args: [],
params: {
active: param.required(boolean),
count: param.default(number, "101"),
},
async execute({params}) {
params.active // true
params.count // 101
},
})
args
, params
, and some more stuffexecute
function can opt-into pretty-printing errors (with colors) by throwing an ExecutionError
import {ExecutionError, command} from "@benev/argv"
async execute({params}) {
throw new ExecutionError("scary error printed in red!")
}
execute
function
// ๐ awaiting cli execution
await cli(process.argv, {
name: "pizza",
commands: {
meatlovers: command({
args: [],
params: {
meatiness: param.required(number),
},
async execute({params}) {
console.log(params.meatiness) // 9
},
}),
hawaiian: command({
args: [],
params: {
pineappleyness: param.required(number),
},
async execute({params}) {
console.log(params.pineappleyness) // 8
},
}),
},
}).execute()
// โ๏ธ calling cli final execute
const date = asType({
name: "date",
coerce: string => new Date(string),
})
name
is shown in help pagescoerce
function takes a string input, and you turn it into anything you likeparam.required(date)
param.required(list(date))
const myTypes = asTypes({
date: string => new Date(string),
integer: string => Math.floor(Number(string)),
})
asTypes
will use your object's property names as the type name
const integer = asType({
name: "integer",
coerce: string => {
const n = Number(string)
if (isNaN(n))
throw new Error("not a number")
if (!Number.isSafeInteger(n))
throw new Error("not a safe integer")
return n
},
})
import {themes} from "@benev/argv"
await cli(process.argv, {
// the default theme
theme: themes.standard,
...otherStuff,
}).execute()
themes.seaside
for a more chill vibethemes.noColor
to disable ansi colorsimport {theme, color} from "@benev/argv"
const seaside = theme({
plain: [color.white],
error: [color.brightRed, color.bold],
program: [color.brightCyan, color.bold],
command: [color.cyan, color.bold],
property: [color.blue],
link: [color.brightBlue, color.underline],
arg: [color.brightBlue, color.bold],
param: [color.brightBlue, color.bold],
flag: [color.brightBlue],
required: [color.cyan],
mode: [color.blue],
type: [color.brightBlue],
value: [color.cyan],
})
v0.3.12
FAQs
command line argument parser
The npm package @benev/argv receives a total of 181 weekly downloads. As such, @benev/argv popularity was classified as not popular.
We found that @benev/argv 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.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last weekโs supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.