Socket
Socket
Sign inDemoInstall

cac

Package Overview
Dependencies
Maintainers
2
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cac - npm Package Compare versions

Comparing version 2.3.2 to 3.0.0

67

dist/cac.common.js

@@ -12,5 +12,7 @@ 'use strict';

var readPkg = _interopDefault(require('read-pkg-up'));
var suffix = _interopDefault(require('suffix'));
delete require.cache[__filename]
var parentDir = path.dirname(module.parent.filename)
var parentFile = module.parent.filename
var parentDir = path.dirname(parentFile)

@@ -66,5 +68,9 @@ var prefixedOption = function (option, aliasOptions) {

help: {
name: 'help',
alias: 'h',
description: 'Output usage information'
},
version: {
name: 'version',
alias: 'v',
description: 'Output version number'

@@ -124,2 +130,4 @@ }

this.options[name] = {
name: name,
alias: alias,
description: description,

@@ -144,3 +152,3 @@ defaultValue: defaultValue

chalk.yellow(prefixedOption(option, this$1.aliasOptions)),
chalk.grey(this$1.options[option].description),
chalk.grey(this$1.options[option].description),
showDefaultValue(this$1.options[option].defaultValue)

@@ -167,9 +175,29 @@ ]; }))

CAC.prototype.command = function command (names, description, fn) {
CAC.prototype.command = function command () {
var args = [], len = arguments.length;
while ( len-- ) args[ len ] = arguments[ len ];
// first arg is always the command
var names = args[0]
// second arg can be description or command function
var description = ''
var commandFn
if (typeof args[1] === 'string') {
description = args[1]
commandFn = args[2]
} else if (typeof args[1] === 'function') {
commandFn = args[1]
}
// read name and alias from the command
// eg: i, init => name: ini, alias: i
var ref = parseNames(names);
var name = ref.name;
var alias = ref.alias;
this.commands[name] = {
name: name,
alias: alias,
description: description,
fn: fn
fn: commandFn
}

@@ -183,14 +211,31 @@ this.aliasCommand(name, alias)

var commandFn = command && command.fn
if (typeof commandFn === 'function') {
var result
if (!commandFn) {
// when commandFn is undefined
// load it from the directory of executable file
var binName = suffix(path.basename(parentFile), ("-" + (command.name)))
var subCommand = path.join(parentDir, binName)
try {
result = commandFn(this.argv.input, this.argv.flags)
commandFn = require(subCommand)
} catch (err) {
this.handleError(err)
if (err.code === 'MODULE_NOT_FOUND') {
console.error('\n%s(1) does not exist, try --help\n', binName)
process.exit(1)
} else {
throw err
}
}
if (result && result.then) {
result.catch(this.handleError)
}
}
var result
try {
var input = command.name === '*' ? this.argv.input : this.argv.input.slice(1)
result = commandFn(input, this.argv.flags)
} catch (err) {
this.handleError(err)
}
if (result && result.then) {
result.catch(this.handleError)
}
return this

@@ -197,0 +242,0 @@ };

13

package.json
{
"name": "cac",
"version": "2.3.2",
"version": "3.0.0",
"description": "Command & Conquer, the command-line queen.",

@@ -18,4 +18,4 @@ "license": "MIT",

"test2": "npm run build && npm test",
"build": "bubleup",
"dev": "node watch"
"build": "bili",
"dev": "bili --watch"
},

@@ -47,3 +47,5 @@ "watch": {

"rules": {
"xo/no-process-exit": 0
"xo/no-process-exit": 0,
"unicorn/no-process-exit": 0,
"import/no-dynamic-require": 0
}

@@ -57,5 +59,6 @@ },

"read-pkg-up": "^1.0.1",
"suffix": "^0.1.0",
"text-table": "^0.2.0"
},
"bubleup": {
"bili": {
"transforms": {

@@ -62,0 +65,0 @@ "dangerousForOf": true

@@ -23,3 +23,3 @@ # cac [![NPM version](https://img.shields.io/npm/v/cac.svg)](https://npmjs.com/package/cac) [![NPM downloads](https://img.shields.io/npm/dm/cac.svg)](https://npmjs.com/package/cac) [![Build Status](https://img.shields.io/circleci/project/egoist/cac/master.svg)](https://circleci.com/gh/egoist/cac)

cli.command('hi', 'Say hi!', (input) => {
console.log(`hi ${input[1] || 'boy'}!`)
console.log(`hi ${input[0] || 'boy'}!`)
})

@@ -26,0 +26,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc