Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Parses Command Line Arguments To Node.JS CLI Programs, Keeps Them In Arguments.xml File To Paste Into README Documentation And Generate Google Closure Compatible Exports.
yarn add -E argufy
Argufy Parses Command Line Arguments to Node.JS CLI Programs. It also allows to manage arguments by keeping their definitions in the XML file, so that they can then be embedded into documentation quickly without manual copy-paste. Finally, it produces JavaScript code to extract arguments that is compatible with Google Closure Compiler.
The best way to use Argufy is to create an arguments.xml
file and place all definitions in it. For example, Argufy defines the following CLI arguments:
Arguments.xml File (view source) |
---|
|
When run from the CLI, Argufy will then generate the get-args.js
file that will parse process.argv
using the API, and export them as ES6 named exports:
Closure-Compatible Arguments |
---|
|
It also exports the configuration object which can be then used to pass to Usually — the help generator for CLI programs:
Usually Integration (view source) |
---|
|
When run as node example -h , the following output will be shown to the user to indicate how to use the program:
|
|
The CLI is essentially an abstraction over the API, in which the Argufy config must be written and maintained manually. The main advantage of it is that the types can then be embedded into documentation when it is compiled with the Documentary package. An example of the table and arguments for Argufy usage are shown below.
Argument | Short | Description |
---|---|---|
input |
The location of the arguments.xml file. Default types/arguments.xml .
| |
--output | -o | The destination where to save output. If not passed, prints to stdout. |
--help | -h | Print the help information and exit. |
--version | -v | Show the version's number and exit. |
The package is available by importing its default and named functions:
import argufy from 'argufy'
The types and externs for Google Closure Compiler via Depack are defined in the _argufy
namespace.
argufy(
config: Config,
argv?: string[],
): Object
The flags from the arguments will be extracted according to the configuration object and the arguments array. If arguments array is not passed, process.argv
is used to find arguments.
The package assumes that the arguments begin from the 3rd position, i.e., standard Node.JS use such as node example.js --title "Hello World"
, or example --title "Hello World"
if the program has a shebang and/or is run via the bin
package.json property.
import argufy from 'argufy'
const config = {
title: { short: 't', command: true },
list: { short: 'l', boolean: true },
app: 'a',
delay: 'y',
file: 'f',
wait: { short: 'w', number: true },
'no-empty': 'e',
resize: 'z',
colors: 'c',
dir: 'D',
}
const res = argufy(config, process.argv)
console.log(JSON.stringify(res, null, 2))
node example.js --title "Hello World" -w 10 -l -app Argufy
# or
node example.js HelloWorld -w 10 -l -app Argufy
{
"_argv": [],
"title": "HelloWorld",
"list": true,
"app": "Argufy",
"wait": 10
}
The configuration for each flag can either be a shorthand string, or an object of the Flag type. The types are shown below. The special _argv
property will be assigned to contain all unmatched arguments. For example, it can be used to pass any additional parameters through to other program.
Object<string, string|!_argufy.Flag>
_argufy.Config
: The configuration for parsing, where each key is a flag name and values are either strings, or objects with possible properties:
_argufy.Flag
: The flag passed to the program.
Name | Type | Description | Default |
---|---|---|---|
short | string | Shorthand for this argument, usually one letter. | - |
boolean | boolean | Whether the flag is a boolean and does not require a value. | false |
number | boolean | Specifies whether the flag should be parsed as a number. | false |
command | boolean | If set to true, the value is read from the first argument passed to the CLI command (e.g., $ cli command ). | false |
multiple | boolean | When using the command property, will parse the commands as an array. | false |
default | string | The default value for the argument. Does not actually set the value, only used in reducing the usage info (argufy bin on the other hand will set the default). | - |
description | string | The description to be used by usually . | - |
reduceUsage(
config: Config,
): Object
Given the Argufy config, creates an object that can be passed to Usually. Can be used to reduce the config auto-generated and exported from the JavaScript file with the CLI.
import { reduceUsage } from 'argufy'
import { argsConfig } from '../src/get-args'
console.log(reduceUsage(argsConfig))
{ input: 'The location of the `arguments.xml` file.\nDefault: types/arguments.xml.',
'--output, -o': 'The destination where to save output.\nIf not passed, prints to stdout.',
'--help, -h': 'Print the help information and exit.',
'--version, -v': 'Show the version\'s number and exit.' }
© Art Deco 2019 | Tech Nation Visa Sucks |
---|
FAQs
Parses Command Line Arguments To Node.JS CLI Programs, Keeps Them In Arguments.xml File To Paste Into README Documentation And Generate Google Closure Compatible Exports.
The npm package argufy receives a total of 116 weekly downloads. As such, argufy popularity was classified as not popular.
We found that argufy 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.