Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sywac

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sywac - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

28

api.js

@@ -40,2 +40,3 @@ 'use strict'

this._showHelpByDefault = 'showHelpByDefault' in opts ? opts.showHelpByDefault : false
this._magicCommandAdded = false
this.configure(opts)

@@ -264,3 +265,6 @@ if (!Api.ROOT_NAME) Api.ROOT_NAME = this.name

} else if (typeof dsl === 'string') {
opts = Object.assign({}, opts)
opts.flags = dsl
} else {
Object.assign({}, opts)
}

@@ -289,3 +293,3 @@ if (!opts.flags && opts.aliases) opts.flags = [].concat(opts.aliases)[0]

positional (dsl, opts) {
opts = opts || {}
opts = Object.assign({}, opts) // copy object so we don't alter object with external refs
let addedToHelp = false

@@ -295,6 +299,6 @@

if (Array.isArray(dsl)) {
opts.params = dsl
opts.params = dsl.slice()
} else if (typeof dsl === 'object') {
if (dsl.params) opts = dsl
else opts.params = dsl
if (dsl.params) opts = Object.assign({}, dsl)
else opts.params = Object.assign({}, dsl)
} else if (typeof dsl === 'string') {

@@ -313,3 +317,3 @@ this.helpOpts.usagePositionals = (this.helpOpts.usagePositionals || []).concat(dsl)

let obj = opts.params[key]
if (obj && !obj.flags) obj.flags = array[index]
if (obj && !obj.flags) obj = Object.assign({flags: array[index]}, obj)
// if (obj && !obj.aliases) obj.aliases = key

@@ -323,5 +327,5 @@ return obj

let params = Array.isArray(opts.params) ? opts.params : Object.keys(opts.params).map(key => {
let params = Array.isArray(opts.params) ? opts.params.slice() : Object.keys(opts.params).map(key => {
let obj = opts.params[key]
if (obj && !obj.flags) obj.flags = key
if (obj && !obj.flags) obj = Object.assign({flags: key}, obj)
return obj

@@ -336,2 +340,3 @@ })

if (typeof param === 'string') param = { flags: param }
else param = Object.assign({}, param)
if (!param.flags && param.aliases) param.flags = [].concat(param.aliases)[0]

@@ -558,3 +563,4 @@

})
if (this._showHelpByDefault && hasCommands && !hasDefaultCommand) {
if (!this._magicCommandAdded && this._showHelpByDefault && hasCommands && !hasDefaultCommand) {
this._magicCommandAdded = true
this._internalCommand(Api.DEFAULT_COMMAND_INDICATOR, (argv, context) => {

@@ -578,3 +584,3 @@ context.deferHelp().addDeferredHelp(this.initHelpBuffer())

// next determine shouldCoerceAndCheck
const shouldCoerceAndCheck = this.shouldCoerceAndCheck(context, hasCommands, hasDefaultCommand)
const shouldCoerceAndCheck = this.shouldCoerceAndCheck(context)
// then populate argv with other types, letting them know if it makes sense to apply coercion

@@ -619,7 +625,7 @@ context.populateArgv(this.types.map(type => type.toResult(context, shouldCoerceAndCheck)))

// basically, we don't want to run the custom check handler if help text or version will be output
shouldCoerceAndCheck (context, hasCommands, hasDefaultCommand) {
shouldCoerceAndCheck (context) {
return !context.helpRequested &&
!context.versionRequested &&
!(context.messages && context.messages.length) &&
!(this._showHelpByDefault && hasCommands && !hasDefaultCommand && !context.explicitCommandMatch(this.name))
(!this._magicCommandAdded || context.explicitCommandMatch(this.name))
}

@@ -626,0 +632,0 @@

@@ -220,2 +220,6 @@ 'use strict'

resetSource (id, source) {
this.sources.set(id, { source: source, position: [], raw: [] })
}
employSource (id, source, position, raw) {

@@ -222,0 +226,0 @@ let obj = this.lookupSource(id)

'use strict'
// setInterval(() => {
// console.log('100...')
// }, 100)
module.exports = require('./api').get()
// base: Boolean, String, Number, Date, Directory, File, Version, Help
// wrappers: Array, Command
// unsure: Enum, Positional
// example custom: Range, Port, HostPort (or BaseUrl)

@@ -149,3 +149,3 @@ // copyright license from https://github.com/chalk/ansi-regex/blob/master/license

props.defaultValue = value.slice(firstEqual + 1)
if (props.variadic) props.defaultValue = [props.defaultValue]
if (props.variadic) props.defaultValue = [].concat(props.defaultValue.split(',')).filter(Boolean).map(s => s.trim())
value = value.slice(0, firstEqual)

@@ -152,0 +152,0 @@ }

{
"name": "sywac",
"version": "0.3.0",
"version": "0.4.0",
"description": "So you want a CLI...",

@@ -13,3 +13,3 @@ "main": "index.js",

"pretest": "standard",
"test": "tap --cov test/*.js test/lib/*.js"
"test": "tap --cov --jobs=4 test/test*.js test/lib/test*.js test/types/test*.js"
},

@@ -37,2 +37,4 @@ "engines": {

"devDependencies": {
"del": "^3.0.0",
"require-uncached": "^1.0.3",
"standard": "^10.0.2",

@@ -39,0 +41,0 @@ "tap": "^10.7.0"

@@ -5,2 +5,4 @@ # ![sywac](logo.png)

[![Build Status](https://travis-ci.org/sywac/sywac.svg?branch=master)](https://travis-ci.org/sywac/sywac)
A better CLI framework, made for the ES2015 era.

@@ -25,2 +27,3 @@

- Parse strings as easily as `process.argv`
- Supports concurrent parsing, safe for chatbots or other server-side apps

@@ -27,0 +30,0 @@ ## Installation

@@ -21,3 +21,6 @@ 'use strict'

if (override || !this._api) this._api = opts.api || this._api
if (override || !this._api) {
this._api = opts.api || this._api
if (opts.api) this._apiConfigured = false
}
if (override || !this._positionalOpts) this._positionalOpts = this._assignPositionalOpts(this._positionalOpts || {}, opts)

@@ -102,13 +105,16 @@ if (override || !this._positionalDsl) this._positionalDsl = opts.paramsDsl || this._positionalDsl

// add positionals from preconfigured opts
if (typeof this._positionalDsl === 'string' && this._positionalDsl.length) {
this.api.positional(this._positionalDsl, this._positionalOpts)
} else if (this._positionalOpts && this._positionalOpts.params) {
this.api.positional(this._positionalOpts)
}
if (!this._apiConfigured) {
this._apiConfigured = true
// add positionals from preconfigured opts
if (typeof this._positionalDsl === 'string' && this._positionalDsl.length) {
this.api.positional(this._positionalDsl, this._positionalOpts)
} else if (this._positionalOpts && this._positionalOpts.params) {
this.api.positional(this._positionalOpts)
}
// TODO add other types from preconfigured opts ?
// TODO add other types from preconfigured opts ?
// call sync "setup" handler, if defined
this.setupHandler(this.api)
// call sync "setup" handler, if defined
this.setupHandler(this.api)
}

@@ -115,0 +121,0 @@ return this.api.parseFromContext(context).then(whenDone => {

@@ -25,2 +25,6 @@ 'use strict'

get datatype () {
return 'enum'
}
choice (c) {

@@ -27,0 +31,0 @@ if (c) this._choices = this._choices.concat(c)

@@ -75,6 +75,2 @@ 'use strict'

get source () {
return this.elementType.source
}
toResult (context, shouldCoerce) {

@@ -81,0 +77,0 @@ return this.elementType.toResult(context, shouldCoerce)

@@ -85,2 +85,3 @@ 'use strict'

context.resetSource(this.id, Type.SOURCE_DEFAULT)
const v = unparsed.map(arg => {

@@ -136,3 +137,3 @@ this.applySource(context, null, arg.index, arg.raw)

// (can populate via flags or positional args, but not both at same time)
let positionals = this.positionals.filter(p => p.source !== Type.SOURCE_FLAG)
let positionals = this.positionals.filter(p => context.lookupSourceValue(p.id) !== Type.SOURCE_FLAG)
let numRequiredLeft = positionals.filter(p => p.isRequired).length

@@ -139,0 +140,0 @@ let current = positionals.shift()

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