
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
This is an npm module that provides simple, yet powerful, routing for command line interfaces, in a similar fashion to mainstream HTTP routing.
$ npm install clhoe
In order to do antyhing with Clhoe, we first need to include her. Yes, the name is one heck of a pun on the actual name.
const Clhoe = require('clhoe')
Routing is done by calling the route
function on Clhoe
. The defined routes
will be executed automatically once all routes have been added.
Clhoe.route((command) => {
// TODO: add routes
})
Inside the closure passed to route
, we get the opportunity to define command
routes. The command
parameter passed to the closure we provided, is a function
that when called, creates a new route: it takes the form
command(path, callback)
, whereas the callback will be executed if the path
matches with what is entered into the terminal.
For an example, let us create a command that creates a new project:
command('new project', () => {
console.log('Creating a new project...')
})
The callback will be called, if an only if, the passed arguments from the terminal are in the following order:
$ mycommand new project
Creating a new project...
Otherwise, nothing will be matched. How to add default behavior if no route was matched will be discussed once all the syntax has been covered.
The above example is quite dull on its own. At the very least, it would be nice if the user could specify the name they want for their project:
command('new [project]', ({ project }) => {
console.log('Creating a new project ' + project + '...')
})
The []
enclosed area captures whatever is typed in by the user and stores that
in a variable, which we are able to extract from an object passed along to the
callback provided to the command.
If the following is executed:
$ mycommand new monkeys
Creating a new project monkeys...
You can see we also specified a name for that project.
Let us elaborate upon what we have and take it even further. For instance, let us say we wanted to have a means of specifying the type of the project, but we want it to be optional.
This can be accomplished by introducing an optional group, for which we can use
the {}
syntax:
command('new [project] {--type [type]}', ({ project, type }) => {
type = type || 'default'
if (!['default', 'amazing'].includes(type))
throw new Error('Invalid type!')
console.log('Creating a new ' + type + ' project ' + project + '...')
})
The type
property on the variables object will be undefined
if the user
did not enter it, as such we are making sure it is given a default value.
$ mycommand new monkeys --type amazing
Creating a new amazing project monkeys...
Using what we know, let us implement an optional flag -v
for the same program
that will print additional information regarding the process of setting our
project up.
command('new [project] {--type [type]} {-v}', ({ project, type }, groups) => {
type = type || 'default'
if (!['default', 'amazing'].includes(type))
throw new Error('Invalid type!')
console.log('Creating a new ' + type + ' project ' + project + '...')
if (groups.includes('-v'))
{
// TODO: implement verbose mode
}
})
We can check if an optional group was used by seeing if its name is available in
the groups
array added to the callback. If -v
is included, we wish to
create our example application in verbose mode.
It is also possible to capture a varargs number of strings from the command the user typed in:
command('new [project] [...args]', ({ project, args }) => {
console.log('Creating project ' + project + ' with:')
for (let arg of args)
console.log(arg)
})
The args
we extracted will always be in the form of an array, as such on
running the command, we might get something like this:
$ mycommand new monkeys lots of strings
Creating project monkeys with:
lots
of
strings
It is possible to use optional groups at the same time as using varargs, as optional groups are always evaluated first, before anything else is evaluated.
If no route was matched, a default callback (if provided) will be called:
Clhoe.route((command) => {
// ...
}).else(() => {
console.log('No command was matched!')
})
The chained else
function will add such a callback.
Let us have a look at how a help command might be implemented:
let help = () => {
console.log('Help command!')
}
Clhoe.route((command) => {
// Full match: 'help'
command('help', help)
// ...
}).else(help)
Thus, either if $ mycommand help
is successfully matched, or no match at all
occurred, the help
closure will be called:
$ mycommand help
Help command!
$ mycommand i will not match a route
Help command!
This module, and the code therein, is licensed under ISC.
FAQs
Provides simple, yet powerful, routing for command line interfaces.
The npm package clhoe receives a total of 0 weekly downloads. As such, clhoe popularity was classified as not popular.
We found that clhoe demonstrated a not healthy version release cadence and project activity because the last version was released 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
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.