mirror of
https://github.com/actions/labeler
synced 2026-05-08 17:21:03 +02:00
build
This commit is contained in:
8
node_modules/yargs/lib/argsert.js
generated
vendored
8
node_modules/yargs/lib/argsert.js
generated
vendored
@@ -1,16 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
// hoisted due to circular dependency on command.
|
||||
module.exports = argsert
|
||||
const command = require('./command')()
|
||||
const YError = require('./yerror')
|
||||
|
||||
const positionName = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']
|
||||
|
||||
module.exports = function argsert (expected, callerArguments, length) {
|
||||
function argsert (expected, callerArguments, length) {
|
||||
// TODO: should this eventually raise an exception.
|
||||
try {
|
||||
// preface the argument description with "cmd", so
|
||||
// that we can run it through yargs' command parser.
|
||||
let position = 0
|
||||
let parsed = {demanded: [], optional: []}
|
||||
let parsed = { demanded: [], optional: [] }
|
||||
if (typeof expected === 'object') {
|
||||
length = callerArguments
|
||||
callerArguments = expected
|
||||
|
||||
34
node_modules/yargs/lib/command.js
generated
vendored
34
node_modules/yargs/lib/command.js
generated
vendored
@@ -1,6 +1,8 @@
|
||||
'use strict'
|
||||
|
||||
const inspect = require('util').inspect
|
||||
const isPromise = require('./is-promise')
|
||||
const { applyMiddleware, commandMiddlewareFactory } = require('./middleware')
|
||||
const path = require('path')
|
||||
const Parser = require('yargs-parser')
|
||||
|
||||
@@ -15,12 +17,12 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
||||
let aliasMap = {}
|
||||
let defaultCommand
|
||||
globalMiddleware = globalMiddleware || []
|
||||
self.addHandler = function addHandler (cmd, description, builder, handler, middlewares) {
|
||||
|
||||
self.addHandler = function addHandler (cmd, description, builder, handler, commandMiddleware) {
|
||||
let aliases = []
|
||||
const middlewares = commandMiddlewareFactory(commandMiddleware)
|
||||
handler = handler || (() => {})
|
||||
middlewares = middlewares || []
|
||||
globalMiddleware.push(...middlewares)
|
||||
middlewares = globalMiddleware
|
||||
|
||||
if (Array.isArray(cmd)) {
|
||||
aliases = cmd.slice(1)
|
||||
cmd = cmd[0]
|
||||
@@ -223,23 +225,25 @@ module.exports = function command (yargs, usage, validation, globalMiddleware) {
|
||||
positionalMap = populatePositionals(commandHandler, innerArgv, currentContext, yargs)
|
||||
}
|
||||
|
||||
const middlewares = globalMiddleware.slice(0).concat(commandHandler.middlewares || [])
|
||||
applyMiddleware(innerArgv, yargs, middlewares, true)
|
||||
|
||||
// we apply validation post-hoc, so that custom
|
||||
// checks get passed populated positional arguments.
|
||||
if (!yargs._hasOutput()) yargs._runValidation(innerArgv, aliases, positionalMap, yargs.parsed.error)
|
||||
|
||||
if (commandHandler.handler && !yargs._hasOutput()) {
|
||||
yargs._setHasOutput()
|
||||
if (commandHandler.middlewares.length > 0) {
|
||||
const middlewareArgs = commandHandler.middlewares.reduce(function (initialObj, middleware) {
|
||||
return Object.assign(initialObj, middleware(innerArgv))
|
||||
}, {})
|
||||
Object.assign(innerArgv, middlewareArgs)
|
||||
}
|
||||
const handlerResult = commandHandler.handler(innerArgv)
|
||||
if (handlerResult && typeof handlerResult.then === 'function') {
|
||||
handlerResult.then(
|
||||
null,
|
||||
(error) => yargs.getUsageInstance().fail(null, error)
|
||||
|
||||
innerArgv = applyMiddleware(innerArgv, yargs, middlewares, false)
|
||||
|
||||
const handlerResult = isPromise(innerArgv)
|
||||
? innerArgv.then(argv => commandHandler.handler(argv))
|
||||
: commandHandler.handler(innerArgv)
|
||||
|
||||
if (isPromise(handlerResult)) {
|
||||
handlerResult.catch(error =>
|
||||
yargs.getUsageInstance().fail(null, error)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
49
node_modules/yargs/lib/completion-templates.js
generated
vendored
Normal file
49
node_modules/yargs/lib/completion-templates.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
exports.completionShTemplate =
|
||||
`###-begin-{{app_name}}-completions-###
|
||||
#
|
||||
# yargs command completion script
|
||||
#
|
||||
# Installation: {{app_path}} {{completion_command}} >> ~/.bashrc
|
||||
# or {{app_path}} {{completion_command}} >> ~/.bash_profile on OSX.
|
||||
#
|
||||
_yargs_completions()
|
||||
{
|
||||
local cur_word args type_list
|
||||
|
||||
cur_word="\${COMP_WORDS[COMP_CWORD]}"
|
||||
args=("\${COMP_WORDS[@]}")
|
||||
|
||||
# ask yargs to generate completions.
|
||||
type_list=$({{app_path}} --get-yargs-completions "\${args[@]}")
|
||||
|
||||
COMPREPLY=( $(compgen -W "\${type_list}" -- \${cur_word}) )
|
||||
|
||||
# if no match was found, fall back to filename completion
|
||||
if [ \${#COMPREPLY[@]} -eq 0 ]; then
|
||||
COMPREPLY=()
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
complete -o default -F _yargs_completions {{app_name}}
|
||||
###-end-{{app_name}}-completions-###
|
||||
`
|
||||
|
||||
exports.completionZshTemplate = `###-begin-{{app_name}}-completions-###
|
||||
#
|
||||
# yargs command completion script
|
||||
#
|
||||
# Installation: {{app_path}} {{completion_command}} >> ~/.zshrc
|
||||
# or {{app_path}} {{completion_command}} >> ~/.zsh_profile on OSX.
|
||||
#
|
||||
_{{app_name}}_yargs_completions()
|
||||
{
|
||||
local reply
|
||||
local si=$IFS
|
||||
IFS=$'\n' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" {{app_path}} --get-yargs-completions "\${words[@]}"))
|
||||
IFS=$si
|
||||
_describe 'values' reply
|
||||
}
|
||||
compdef _{{app_name}}_yargs_completions {{app_name}}
|
||||
###-end-{{app_name}}-completions-###
|
||||
`
|
||||
28
node_modules/yargs/lib/completion.js
generated
vendored
28
node_modules/yargs/lib/completion.js
generated
vendored
@@ -1,5 +1,4 @@
|
||||
'use strict'
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
// add bash completions to your
|
||||
@@ -9,6 +8,7 @@ module.exports = function completion (yargs, usage, command) {
|
||||
completionKey: 'get-yargs-completions'
|
||||
}
|
||||
|
||||
const zshShell = process.env.SHELL && process.env.SHELL.indexOf('zsh') !== -1
|
||||
// get a list of completion commands.
|
||||
// 'args' is the array of strings from the line to be completed
|
||||
self.getCompletion = function getCompletion (args, done) {
|
||||
@@ -16,6 +16,7 @@ module.exports = function completion (yargs, usage, command) {
|
||||
const current = args.length ? args[args.length - 1] : ''
|
||||
const argv = yargs.parse(args, true)
|
||||
const aliases = yargs.parsed.aliases
|
||||
const parentCommands = yargs.getContext().commands
|
||||
|
||||
// a custom completion function can be provided
|
||||
// to completion().
|
||||
@@ -54,22 +55,33 @@ module.exports = function completion (yargs, usage, command) {
|
||||
}
|
||||
}
|
||||
|
||||
if (!current.match(/^-/)) {
|
||||
if (!current.match(/^-/) && parentCommands[parentCommands.length - 1] !== current) {
|
||||
usage.getCommands().forEach((usageCommand) => {
|
||||
const commandName = command.parseCommand(usageCommand[0]).cmd
|
||||
if (args.indexOf(commandName) === -1) {
|
||||
completions.push(commandName)
|
||||
if (!zshShell) {
|
||||
completions.push(commandName)
|
||||
} else {
|
||||
const desc = usageCommand[1] || ''
|
||||
completions.push(commandName.replace(/:/g, '\\:') + ':' + desc)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (current.match(/^-/)) {
|
||||
if (current.match(/^-/) || (current === '' && completions.length === 0)) {
|
||||
const descs = usage.getDescriptions()
|
||||
Object.keys(yargs.getOptions().key).forEach((key) => {
|
||||
// If the key and its aliases aren't in 'args', add the key to 'completions'
|
||||
const keyAndAliases = [key].concat(aliases[key] || [])
|
||||
const notInArgs = keyAndAliases.every(val => args.indexOf(`--${val}`) === -1)
|
||||
if (notInArgs) {
|
||||
completions.push(`--${key}`)
|
||||
if (!zshShell) {
|
||||
completions.push(`--${key}`)
|
||||
} else {
|
||||
const desc = descs[key] || ''
|
||||
completions.push(`--${key.replace(/:/g, '\\:')}:${desc.replace('__yargsString__:', '')}`)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -79,10 +91,8 @@ module.exports = function completion (yargs, usage, command) {
|
||||
|
||||
// generate the completion script to add to your .bashrc.
|
||||
self.generateCompletionScript = function generateCompletionScript ($0, cmd) {
|
||||
let script = fs.readFileSync(
|
||||
path.resolve(__dirname, '../completion.sh.hbs'),
|
||||
'utf-8'
|
||||
)
|
||||
const templates = require('./completion-templates')
|
||||
let script = zshShell ? templates.completionZshTemplate : templates.completionShTemplate
|
||||
const name = path.basename($0)
|
||||
|
||||
// add ./to applications not yet installed as bin.
|
||||
|
||||
32
node_modules/yargs/lib/decamelize.js
generated
vendored
Normal file
32
node_modules/yargs/lib/decamelize.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
'use strict'
|
||||
|
||||
module.exports = (text, separator) => {
|
||||
separator = typeof separator === 'undefined' ? '_' : separator
|
||||
|
||||
return text
|
||||
.replace(/([a-z\d])([A-Z])/g, `$1${separator}$2`)
|
||||
.replace(/([A-Z]+)([A-Z][a-z\d]+)/g, `$1${separator}$2`)
|
||||
.toLowerCase()
|
||||
}
|
||||
3
node_modules/yargs/lib/is-promise.js
generated
vendored
Normal file
3
node_modules/yargs/lib/is-promise.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
module.exports = function isPromise (maybePromise) {
|
||||
return maybePromise instanceof Promise
|
||||
}
|
||||
17
node_modules/yargs/lib/levenshtein.js
generated
vendored
17
node_modules/yargs/lib/levenshtein.js
generated
vendored
@@ -1,11 +1,22 @@
|
||||
/*
|
||||
Copyright (c) 2011 Andrei Mackenzie
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
// levenshtein distance algorithm, pulled from Andrei Mackenzie's MIT licensed.
|
||||
|
||||
59
node_modules/yargs/lib/middleware.js
generated
vendored
59
node_modules/yargs/lib/middleware.js
generated
vendored
@@ -1,10 +1,65 @@
|
||||
module.exports = function (globalMiddleware, context) {
|
||||
return function (callback) {
|
||||
'use strict'
|
||||
|
||||
// hoisted due to circular dependency on command.
|
||||
module.exports = {
|
||||
applyMiddleware,
|
||||
commandMiddlewareFactory,
|
||||
globalMiddlewareFactory
|
||||
}
|
||||
const isPromise = require('./is-promise')
|
||||
const argsert = require('./argsert')
|
||||
|
||||
function globalMiddlewareFactory (globalMiddleware, context) {
|
||||
return function (callback, applyBeforeValidation = false) {
|
||||
argsert('<array|function> [boolean]', [callback, applyBeforeValidation], arguments.length)
|
||||
if (Array.isArray(callback)) {
|
||||
for (let i = 0; i < callback.length; i++) {
|
||||
if (typeof callback[i] !== 'function') {
|
||||
throw Error('middleware must be a function')
|
||||
}
|
||||
callback[i].applyBeforeValidation = applyBeforeValidation
|
||||
}
|
||||
Array.prototype.push.apply(globalMiddleware, callback)
|
||||
} else if (typeof callback === 'function') {
|
||||
callback.applyBeforeValidation = applyBeforeValidation
|
||||
globalMiddleware.push(callback)
|
||||
}
|
||||
return context
|
||||
}
|
||||
}
|
||||
|
||||
function commandMiddlewareFactory (commandMiddleware) {
|
||||
if (!commandMiddleware) return []
|
||||
return commandMiddleware.map(middleware => {
|
||||
middleware.applyBeforeValidation = false
|
||||
return middleware
|
||||
})
|
||||
}
|
||||
|
||||
function applyMiddleware (argv, yargs, middlewares, beforeValidation) {
|
||||
const beforeValidationError = new Error('middleware cannot return a promise when applyBeforeValidation is true')
|
||||
return middlewares
|
||||
.reduce((accumulation, middleware) => {
|
||||
if (middleware.applyBeforeValidation !== beforeValidation &&
|
||||
!isPromise(accumulation)) {
|
||||
return accumulation
|
||||
}
|
||||
|
||||
if (isPromise(accumulation)) {
|
||||
return accumulation
|
||||
.then(initialObj =>
|
||||
Promise.all([initialObj, middleware(initialObj, yargs)])
|
||||
)
|
||||
.then(([initialObj, middlewareObj]) =>
|
||||
Object.assign(initialObj, middlewareObj)
|
||||
)
|
||||
} else {
|
||||
const result = middleware(argv, yargs)
|
||||
if (beforeValidation && isPromise(result)) throw beforeValidationError
|
||||
|
||||
return isPromise(result)
|
||||
? result.then(middlewareObj => Object.assign(accumulation, middlewareObj))
|
||||
: Object.assign(accumulation, result)
|
||||
}
|
||||
}, argv)
|
||||
}
|
||||
|
||||
17
node_modules/yargs/lib/usage.js
generated
vendored
17
node_modules/yargs/lib/usage.js
generated
vendored
@@ -1,6 +1,7 @@
|
||||
'use strict'
|
||||
// this file handles outputting usage instructions,
|
||||
// failures, etc. keeps logging in one place.
|
||||
const decamelize = require('./decamelize')
|
||||
const stringWidth = require('string-width')
|
||||
const objFilter = require('./obj-filter')
|
||||
const path = require('path')
|
||||
@@ -180,7 +181,7 @@ module.exports = function usage (yargs, y18n) {
|
||||
usages.forEach((usage) => {
|
||||
ui.div(`${usage[0].replace(/\$0/g, base$0)}`)
|
||||
if (usage[1]) {
|
||||
ui.div({text: `${usage[1]}`, padding: [1, 0, 0, 0]})
|
||||
ui.div({ text: `${usage[1]}`, padding: [1, 0, 0, 0] })
|
||||
}
|
||||
})
|
||||
ui.div()
|
||||
@@ -204,6 +205,10 @@ module.exports = function usage (yargs, y18n) {
|
||||
const context = yargs.getContext()
|
||||
const parentCommands = context.commands.length ? `${context.commands.join(' ')} ` : ''
|
||||
|
||||
if (yargs.getParserConfiguration()['sort-commands'] === true) {
|
||||
commands = commands.sort((a, b) => a[0].localeCompare(b[0]))
|
||||
}
|
||||
|
||||
commands.forEach((command) => {
|
||||
const commandString = `${base$0} ${parentCommands}${command[0].replace(/^\$0 ?/, '')}` // drop $0 from default commands.
|
||||
ui.span(
|
||||
@@ -212,7 +217,7 @@ module.exports = function usage (yargs, y18n) {
|
||||
padding: [0, 2, 0, 2],
|
||||
width: maxWidth(commands, theWrap, `${base$0}${parentCommands}`) + 4
|
||||
},
|
||||
{text: command[1]}
|
||||
{ text: command[1] }
|
||||
)
|
||||
const hints = []
|
||||
if (command[2]) hints.push(`[${__('default:').slice(0, -1)}]`) // TODO hacking around i18n here
|
||||
@@ -220,7 +225,7 @@ module.exports = function usage (yargs, y18n) {
|
||||
hints.push(`[${__('aliases:')} ${command[3].join(', ')}]`)
|
||||
}
|
||||
if (hints.length) {
|
||||
ui.div({text: hints.join(' '), padding: [0, 0, 0, 2], align: 'right'})
|
||||
ui.div({ text: hints.join(' '), padding: [0, 0, 0, 2], align: 'right' })
|
||||
} else {
|
||||
ui.div()
|
||||
}
|
||||
@@ -296,11 +301,11 @@ module.exports = function usage (yargs, y18n) {
|
||||
].filter(Boolean).join(' ')
|
||||
|
||||
ui.span(
|
||||
{text: kswitch, padding: [0, 2, 0, 2], width: maxWidth(switches, theWrap) + 4},
|
||||
{ text: kswitch, padding: [0, 2, 0, 2], width: maxWidth(switches, theWrap) + 4 },
|
||||
desc
|
||||
)
|
||||
|
||||
if (extra) ui.div({text: extra, padding: [0, 0, 0, 2], align: 'right'})
|
||||
if (extra) ui.div({ text: extra, padding: [0, 0, 0, 2], align: 'right' })
|
||||
else ui.div()
|
||||
})
|
||||
|
||||
@@ -428,7 +433,7 @@ module.exports = function usage (yargs, y18n) {
|
||||
}
|
||||
|
||||
self.functionDescription = (fn) => {
|
||||
const description = fn.name ? require('decamelize')(fn.name, '-') : __('generated-value')
|
||||
const description = fn.name ? decamelize(fn.name, '-') : __('generated-value')
|
||||
return ['(', description, ')'].join('')
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user