progress on migrating to heex templates and font-icons
This commit is contained in:
parent
d43daafdb7
commit
3eff955672
21793 changed files with 2161968 additions and 16895 deletions
21
assets_old/node_modules/coa/LICENSE
generated
vendored
Normal file
21
assets_old/node_modules/coa/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015-present Sergey Berezhnoy <veged@ya.ru>
|
||||
|
||||
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.
|
340
assets_old/node_modules/coa/README.md
generated
vendored
Normal file
340
assets_old/node_modules/coa/README.md
generated
vendored
Normal file
|
@ -0,0 +1,340 @@
|
|||
# Command-Option-Argument
|
||||
|
||||
Yet another parser for command line options.
|
||||
|
||||
[![NPM Status][npm-img]][npm]
|
||||
[![Travis Status][test-img]][travis]
|
||||
[![AppVeyor Status][appveyor-img]][appveyor]
|
||||
[![Coverage Status][coverage-img]][coveralls]
|
||||
[![Dependency Status][dependency-img]][david]
|
||||
|
||||
[npm]: https://www.npmjs.org/package/coa
|
||||
[npm-img]: https://img.shields.io/npm/v/coa.svg
|
||||
[travis]: https://travis-ci.org/veged/coa
|
||||
[test-img]: https://img.shields.io/travis/veged/coa.svg
|
||||
[appveyor]: https://ci.appveyor.com/project/zxqfox/coa
|
||||
[appveyor-img]: https://ci.appveyor.com/api/projects/status/github/veged/coa?svg=true
|
||||
[coveralls]: https://coveralls.io/r/veged/coa
|
||||
[coverage-img]: https://img.shields.io/coveralls/veged/coa.svg
|
||||
[david]: https://david-dm.org/veged/coa
|
||||
[dependency-img]: http://img.shields.io/david/veged/coa.svg
|
||||
|
||||
## What is it?
|
||||
|
||||
COA is a parser for command line options that aim to get maximum profit from formalization your program API.
|
||||
Once you write definition in terms of commands, options and arguments you automaticaly get:
|
||||
|
||||
* Command line help text
|
||||
* Program API for use COA-based programs as modules
|
||||
* Shell completion
|
||||
|
||||
### Other features
|
||||
|
||||
* Rich types for options and arguments, such as arrays, boolean flags and required
|
||||
* Commands can be async throught using promising (powered by [Q](https://github.com/kriskowal/q))
|
||||
* Easy submoduling some existing commands to new top-level one
|
||||
* Combined validation and complex parsing of values
|
||||
|
||||
### TODO
|
||||
|
||||
* Localization
|
||||
* Shell-mode
|
||||
* Configs
|
||||
* Aliases
|
||||
* Defaults
|
||||
|
||||
## Examples
|
||||
|
||||
````javascript
|
||||
require('coa').Cmd() // main (top level) command declaration
|
||||
.name(process.argv[1]) // set top level command name from program name
|
||||
.title('My awesome command line util') // title for use in text messages
|
||||
.helpful() // make command "helpful", i.e. options -h --help with usage message
|
||||
.opt() // add some option
|
||||
.name('version') // name for use in API
|
||||
.title('Version') // title for use in text messages
|
||||
.short('v') // short key: -v
|
||||
.long('version') // long key: --version
|
||||
.flag() // for options without value
|
||||
.act(function(opts) { // add action for option
|
||||
// return message as result of action
|
||||
return JSON.parse(require('fs').readFileSync(__dirname + '/package.json'))
|
||||
.version;
|
||||
})
|
||||
.end() // end option chain and return to main command
|
||||
.cmd().name('subcommand').apply(require('./subcommand').COA).end() // load subcommand from module
|
||||
.cmd() // inplace subcommand declaration
|
||||
.name('othercommand').title('Awesome other subcommand').helpful()
|
||||
.opt()
|
||||
.name('input').title('input file, required')
|
||||
.short('i').long('input')
|
||||
.val(function(v) { // validator function, also for translate simple values
|
||||
return require('fs').createReadStream(v) })
|
||||
.req() // make option required
|
||||
.end() // end option chain and return to command
|
||||
.end() // end subcommand chain and return to parent command
|
||||
.run(process.argv.slice(2)); // parse and run on process.argv
|
||||
````
|
||||
|
||||
````javascript
|
||||
// subcommand.js
|
||||
exports.COA = function() {
|
||||
this
|
||||
.title('Awesome subcommand').helpful()
|
||||
.opt()
|
||||
.name('output').title('output file')
|
||||
.short('o').long('output')
|
||||
.output() // use default preset for "output" option declaration
|
||||
.end()
|
||||
};
|
||||
````
|
||||
|
||||
## API reference
|
||||
|
||||
### Cmd
|
||||
Command is a top level entity. Commands may have options and arguments.
|
||||
|
||||
#### Cmd.api
|
||||
Returns object containing all its subcommands as methods to use from other programs.<br>
|
||||
**@returns** *{Object}*
|
||||
|
||||
#### Cmd.name
|
||||
Set a canonical command identifier to be used anywhere in the API.<br>
|
||||
**@param** *String* `_name` command name<br>
|
||||
**@returns** *COA.Cmd* `this` instance (for chainability)
|
||||
|
||||
#### Cmd.title
|
||||
Set a long description for command to be used anywhere in text messages.<br>
|
||||
**@param** *String* `_title` command title<br>
|
||||
**@returns** *COA.Cmd* `this` instance (for chainability)
|
||||
|
||||
#### Cmd.cmd
|
||||
Create new or add existing subcommand for current command.<br>
|
||||
**@param** *COA.Cmd* `[cmd]` existing command instance<br>
|
||||
**@returns** *COA.Cmd* new or added subcommand instance
|
||||
|
||||
#### Cmd.opt
|
||||
Create option for current command.<br>
|
||||
**@returns** *COA.Opt* `new` option instance
|
||||
|
||||
#### Cmd.arg
|
||||
Create argument for current command.<br>
|
||||
**@returns** *COA.Opt* `new` argument instance
|
||||
|
||||
#### Cmd.act
|
||||
Add (or set) action for current command.<br>
|
||||
**@param** *Function* `act` action function,
|
||||
invoked in the context of command instance
|
||||
and has the parameters:<br>
|
||||
- *Object* `opts` parsed options<br>
|
||||
- *Array* `args` parsed arguments<br>
|
||||
- *Object* `res` actions result accumulator<br>
|
||||
It can return rejected promise by Cmd.reject (in case of error)
|
||||
or any other value treated as result.<br>
|
||||
**@param** *{Boolean}* [force=false] flag for set action instead add to existings<br>
|
||||
**@returns** *COA.Cmd* `this` instance (for chainability)
|
||||
|
||||
#### Cmd.apply
|
||||
Apply function with arguments in context of command instance.<br>
|
||||
**@param** *Function* `fn`<br>
|
||||
**@param** *Array* `args`<br>
|
||||
**@returns** *COA.Cmd* `this` instance (for chainability)
|
||||
|
||||
#### Cmd.comp
|
||||
Set custom additional completion for current command.<br>
|
||||
**@param** *Function* `fn` completion generation function,
|
||||
invoked in the context of command instance.
|
||||
Accepts parameters:<br>
|
||||
- *Object* `opts` completion options<br>
|
||||
It can return promise or any other value treated as result.<br>
|
||||
**@returns** *COA.Cmd* `this` instance (for chainability)
|
||||
|
||||
#### Cmd.helpful
|
||||
Make command "helpful", i.e. add -h --help flags for print usage.<br>
|
||||
**@returns** *COA.Cmd* `this` instance (for chainability)
|
||||
|
||||
#### Cmd.completable
|
||||
Adds shell completion to command, adds "completion" subcommand, that makes all the magic.<br>
|
||||
Must be called only on root command.<br>
|
||||
**@returns** *COA.Cmd* `this` instance (for chainability)
|
||||
|
||||
#### Cmd.usage
|
||||
Build full usage text for current command instance.<br>
|
||||
**@returns** *String* `usage` text
|
||||
|
||||
#### Cmd.run
|
||||
Parse arguments from simple format like NodeJS process.argv
|
||||
and run ahead current program, i.e. call process.exit when all actions done.<br>
|
||||
**@param** *Array* `argv`<br>
|
||||
**@returns** *COA.Cmd* `this` instance (for chainability)
|
||||
|
||||
#### Cmd.invoke
|
||||
Invoke specified (or current) command using provided options and arguments.<br>
|
||||
**@param** *String|Array* `cmds` subcommand to invoke (optional)<br>
|
||||
**@param** *Object* `opts` command options (optional)<br>
|
||||
**@param** *Object* `args` command arguments (optional)<br>
|
||||
**@returns** *Q.Promise*
|
||||
|
||||
#### Cmd.reject
|
||||
Return reject of actions results promise.<br>
|
||||
Use in .act() for return with error.<br>
|
||||
**@param** *Object* `reason` reject reason<br>
|
||||
You can customize toString() method and exitCode property
|
||||
of reason object.<br>
|
||||
**@returns** *Q.promise* rejected promise
|
||||
|
||||
#### Cmd.end
|
||||
Finish chain for current subcommand and return parent command instance.<br>
|
||||
**@returns** *COA.Cmd* `parent` command
|
||||
|
||||
### Opt
|
||||
Option is a named entity. Options may have short and long keys for use from command line.<br>
|
||||
**@namespace**<br>
|
||||
**@class** Presents option
|
||||
|
||||
#### Opt.name
|
||||
Set a canonical option identifier to be used anywhere in the API.<br>
|
||||
**@param** *String* `_name` option name<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.title
|
||||
Set a long description for option to be used anywhere in text messages.<br>
|
||||
**@param** *String* `_title` option title<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.short
|
||||
Set a short key for option to be used with one hyphen from command line.<br>
|
||||
**@param** *String* `_short`<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.long
|
||||
Set a short key for option to be used with double hyphens from command line.<br>
|
||||
**@param** *String* `_long`<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.flag
|
||||
Make an option boolean, i.e. option without value.<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.arr
|
||||
Makes an option accepts multiple values.<br>
|
||||
Otherwise, the value will be used by the latter passed.<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.req
|
||||
Makes an option req.<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.only
|
||||
Makes an option to act as a command,
|
||||
i.e. program will exit just after option action.<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.val
|
||||
Set a validation (or value) function for argument.<br>
|
||||
Value from command line passes through before becoming available from API.<br>
|
||||
Using for validation and convertion simple types to any values.<br>
|
||||
**@param** *Function* `_val` validating function,
|
||||
invoked in the context of option instance
|
||||
and has one parameter with value from command line<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.def
|
||||
Set a default value for option.
|
||||
Default value passed through validation function as ordinary value.<br>
|
||||
**@param** *Object* `_def`<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.input
|
||||
Make option value inputting stream.
|
||||
It's add useful validation and shortcut for STDIN.
|
||||
**@returns** *{COA.Opt}* `this` instance (for chainability)
|
||||
|
||||
#### Opt.output
|
||||
Make option value outputing stream.<br>
|
||||
It's add useful validation and shortcut for STDOUT.<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.act
|
||||
Add action for current option command.
|
||||
This action is performed if the current option
|
||||
is present in parsed options (with any value).<br>
|
||||
**@param** *Function* `act` action function,
|
||||
invoked in the context of command instance
|
||||
and has the parameters:<br>
|
||||
- *Object* `opts` parsed options<br>
|
||||
- *Array* `args` parsed arguments<br>
|
||||
- *Object* `res` actions result accumulator<br>
|
||||
It can return rejected promise by Cmd.reject (in case of error)
|
||||
or any other value treated as result.<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.comp
|
||||
Set custom additional completion for current option.<br>
|
||||
**@param** *Function* `fn` completion generation function,
|
||||
invoked in the context of command instance.
|
||||
Accepts parameters:<br>
|
||||
- *Object* `opts` completion options<br>
|
||||
It can return promise or any other value treated as result.<br>
|
||||
**@returns** *COA.Opt* `this` instance (for chainability)
|
||||
|
||||
#### Opt.end
|
||||
Finish chain for current option and return parent command instance.<br>
|
||||
**@returns** *COA.Cmd* `parent` command
|
||||
|
||||
|
||||
### Arg
|
||||
Argument is a unnamed entity.<br>
|
||||
From command line arguments passed as list of unnamed values.
|
||||
|
||||
#### Arg.name
|
||||
Set a canonical argument identifier to be used anywhere in text messages.<br>
|
||||
**@param** *String* `_name` argument name<br>
|
||||
**@returns** *COA.Arg* `this` instance (for chainability)
|
||||
|
||||
#### Arg.title
|
||||
Set a long description for argument to be used anywhere in text messages.<br>
|
||||
**@param** *String* `_title` argument title<br>
|
||||
**@returns** *COA.Arg* `this` instance (for chainability)
|
||||
|
||||
#### Arg.arr
|
||||
Makes an argument accepts multiple values.<br>
|
||||
Otherwise, the value will be used by the latter passed.<br>
|
||||
**@returns** *COA.Arg* `this` instance (for chainability)
|
||||
|
||||
#### Arg.req
|
||||
Makes an argument req.<br>
|
||||
**@returns** *COA.Arg* `this` instance (for chainability)
|
||||
|
||||
#### Arg.val
|
||||
Set a validation (or value) function for argument.<br>
|
||||
Value from command line passes through before becoming available from API.<br>
|
||||
Using for validation and convertion simple types to any values.<br>
|
||||
**@param** *Function* `_val` validating function,
|
||||
invoked in the context of argument instance
|
||||
and has one parameter with value from command line<br>
|
||||
**@returns** *COA.Arg* `this` instance (for chainability)
|
||||
|
||||
#### Arg.def
|
||||
Set a default value for argument.
|
||||
Default value passed through validation function as ordinary value.<br>
|
||||
**@param** *Object* `_def`<br>
|
||||
**@returns** *COA.Arg* `this` instance (for chainability)
|
||||
|
||||
#### Arg.output
|
||||
Make argument value outputing stream.<br>
|
||||
It's add useful validation and shortcut for STDOUT.<br>
|
||||
**@returns** *COA.Arg* `this` instance (for chainability)
|
||||
|
||||
#### Arg.comp
|
||||
Set custom additional completion for current argument.<br>
|
||||
**@param** *Function* `fn` completion generation function,
|
||||
invoked in the context of command instance.
|
||||
Accepts parameters:<br>
|
||||
- *Object* `opts` completion options<br>
|
||||
It can return promise or any other value treated as result.<br>
|
||||
**@returns** *COA.Arg* `this` instance (for chainability)
|
||||
|
||||
#### Arg.end
|
||||
Finish chain for current option and return parent command instance.<br>
|
||||
**@returns** *COA.Cmd* `parent` command
|
316
assets_old/node_modules/coa/README.ru.md
generated
vendored
Normal file
316
assets_old/node_modules/coa/README.ru.md
generated
vendored
Normal file
|
@ -0,0 +1,316 @@
|
|||
# Command-Option-Argument
|
||||
[](http://travis-ci.org/veged/coa)
|
||||
|
||||
## Что это?
|
||||
|
||||
COA — парсер параметров командной строки, позволяющий извлечь максимум пользы от формального API вашей программы.
|
||||
Как только вы опишете определение в терминах команд, параметров и аргументов, вы автоматически получите:
|
||||
|
||||
* Справку для командной строки
|
||||
* API для использования программы как модуля в COA-совместимых программах
|
||||
* Автодополнение для командной строки
|
||||
|
||||
### Прочие возможности
|
||||
|
||||
* Широкий выбор настроек для параметров и аргументов, включая множественные значения, логические значения и обязательность параметров
|
||||
* Возможность асинхронного исполнения команд, используя промисы (используется библиотека [Q](https://github.com/kriskowal/q))
|
||||
* Простота использования существующих команд как подмодулей для новых команд
|
||||
* Комбинированная валидация и анализ сложных значений
|
||||
|
||||
## Примеры
|
||||
|
||||
````javascript
|
||||
require('coa').Cmd() // декларация команды верхнего уровня
|
||||
.name(process.argv[1]) // имя команды верхнего уровня, берем из имени программы
|
||||
.title('Жутко полезная утилита для командной строки') // название для использования в справке и сообщениях
|
||||
.helpful() // добавляем поддержку справки командной строки (-h, --help)
|
||||
.opt() // добавляем параметр
|
||||
.name('version') // имя параметра для использования в API
|
||||
.title('Version') // текст для вывода в сообщениях
|
||||
.short('v') // короткое имя параметра: -v
|
||||
.long('version') // длинное имя параметра: --version
|
||||
.flag() // параметр не требует ввода значения
|
||||
.act(function(opts) { // действия при вызове аргумента
|
||||
// результатом является вывод текстового сообщения
|
||||
return JSON.parse(require('fs').readFileSync(__dirname + '/package.json'))
|
||||
.version;
|
||||
})
|
||||
.end() // завершаем определение параметра и возвращаемся к определению верхнего уровня
|
||||
.cmd().name('subcommand').apply(require('./subcommand').COA).end() // загрузка подкоманды из модуля
|
||||
.cmd() // добавляем еще одну подкоманду
|
||||
.name('othercommand').title('Еще одна полезная подпрограмма').helpful()
|
||||
.opt()
|
||||
.name('input').title('input file, required')
|
||||
.short('i').long('input')
|
||||
.val(function(v) { // функция-валидатор, также может использоваться для трансформации значений параметров
|
||||
return require('fs').createReadStream(v) })
|
||||
.req() // параметр является обязательным
|
||||
.end() // завершаем определение параметра и возвращаемся к определению команды
|
||||
.end() // завершаем определение подкоманды и возвращаемся к определению команды верхнего уровня
|
||||
.run(process.argv.slice(2)); // разбираем process.argv и запускаем
|
||||
````
|
||||
|
||||
````javascript
|
||||
// subcommand.js
|
||||
exports.COA = function() {
|
||||
this
|
||||
.title('Полезная подпрограмма').helpful()
|
||||
.opt()
|
||||
.name('output').title('output file')
|
||||
.short('o').long('output')
|
||||
.output() // использовать стандартную настройку для параметра вывода
|
||||
.end()
|
||||
};
|
||||
````
|
||||
|
||||
## API
|
||||
|
||||
### Cmd
|
||||
Команда — сущность верхнего уровня. У команды могут быть определены параметры и аргументы.
|
||||
|
||||
#### Cmd.api
|
||||
Возвращает объект, который можно использовать в других программах. Подкоманды являются методами этого объекта.<br>
|
||||
**@returns** *{Object}*
|
||||
|
||||
#### Cmd.name
|
||||
Определяет канонический идентификатор команды, используемый в вызовах API.<br>
|
||||
**@param** *String* `_name` имя команды<br>
|
||||
**@returns** *COA.Cmd* `this` экземпляр команды (для поддержки цепочки методов)
|
||||
|
||||
#### Cmd.title
|
||||
Определяет название команды, используемый в текстовых сообщениях.<br>
|
||||
**@param** *String* `_title` название команды<br>
|
||||
**@returns** *COA.Cmd* `this` экземпляр команды (для поддержки цепочки методов)
|
||||
|
||||
#### Cmd.cmd
|
||||
Создает новую подкоманду или добавляет ранее определенную подкоманду к текущей команде.<br>
|
||||
**@param** *COA.Cmd* `[cmd]` экземпляр ранее определенной подкоманды<br>
|
||||
**@returns** *COA.Cmd* экземпляр новой или ранее определенной подкоманды
|
||||
|
||||
#### Cmd.opt
|
||||
Создает параметр для текущей команды.<br>
|
||||
**@returns** *COA.Opt* `new` экземпляр параметра
|
||||
|
||||
#### Cmd.arg
|
||||
Создает аргумент для текущей команды.<br>
|
||||
**@returns** *COA.Opt* `new` экземпляр аргумента
|
||||
|
||||
#### Cmd.act
|
||||
Добавляет (или создает) действие для текущей команды.<br>
|
||||
**@param** *Function* `act` функция,
|
||||
выполняемая в контексте экземпляра текущей команды
|
||||
и принимающая следующие параметры:<br>
|
||||
- *Object* `opts` параметры команды<br>
|
||||
- *Array* `args` аргументы команды<br>
|
||||
- *Object* `res` объект-аккумулятор результатов<br>
|
||||
Функция может вернуть проваленный промис из Cmd.reject (в случае ошибки)
|
||||
или любое другое значение, рассматриваемое как результат.<br>
|
||||
**@param** *{Boolean}* [force=false] флаг, назначающий немедленное исполнение вместо добавления к списку существующих действий<br>
|
||||
**@returns** *COA.Cmd* `this` экземпляр команды (для поддержки цепочки методов)
|
||||
|
||||
#### Cmd.apply
|
||||
Исполняет функцию с переданными аргументами в контексте экземпляра текущей команды.<br>
|
||||
**@param** *Function* `fn`<br>
|
||||
**@param** *Array* `args`<br>
|
||||
**@returns** *COA.Cmd* `this` экземпляр команды (для поддержки цепочки методов)
|
||||
|
||||
#### Cmd.comp
|
||||
Назначает кастомную функцию автодополнения для текущей команды.<br>
|
||||
**@param** *Function* `fn` функция-генератор автодополнения,
|
||||
исполняемая в контексте текущей команды.
|
||||
Принимает параметры:<br>
|
||||
- *Object* `opts` параметры<br>
|
||||
Может возвращать промис или любое другое значение, рассматриваемое как результат исполнения команды.<br>
|
||||
**@returns** *COA.Cmd* `this` экземпляр команды (для поддержки цепочки методов)
|
||||
|
||||
#### Cmd.helpful
|
||||
Ставит флаг поддержки справки командной строки, т.е. вызов команды с параметрами -h --help выводит справку по работе с командой.<br>
|
||||
**@returns** *COA.Cmd* `this` экземпляр команды (для поддержки цепочки методов)
|
||||
|
||||
#### Cmd.completable
|
||||
Добавляет поддержку автодополнения командной строки. Добавляется подкоманда "completion", которая выполняет все необходимые действия.<br>
|
||||
Может быть добавлен только для главной команды.<br>
|
||||
**@returns** *COA.Cmd* `this` экземпляр команды (для поддержки цепочки методов)
|
||||
|
||||
#### Cmd.usage
|
||||
Возвращает текст справки по использованию команды для текущего экземпляра.<br>
|
||||
**@returns** *String* `usage` Текст справки по использованию
|
||||
|
||||
#### Cmd.run
|
||||
Разбирает аргументы из значения, возвращаемого NodeJS process.argv,
|
||||
и запускает текущую программу, т.е. вызывает process.exit после завершения
|
||||
всех действий.<br>
|
||||
**@param** *Array* `argv`<br>
|
||||
**@returns** *COA.Cmd* `this` экземпляр команды (для поддержки цепочки методов)
|
||||
|
||||
#### Cmd.invoke
|
||||
Исполняет переданную (или текущую) команду с указанными параметрами и аргументами.<br>
|
||||
**@param** *String|Array* `cmds` подкоманда для исполнения (необязательно)<br>
|
||||
**@param** *Object* `opts` параметры, передаваемые команде (необязательно)<br>
|
||||
**@param** *Object* `args` аргументы, передаваемые команде (необязательно)<br>
|
||||
**@returns** *Q.Promise*
|
||||
|
||||
#### Cmd.reject
|
||||
Проваливает промисы, возращенные в действиях.<br>
|
||||
Используется в .act() для возврата с ошибкой.<br>
|
||||
**@param** *Object* `reason` причина провала<br>
|
||||
Вы можете определить метод toString() и свойство toString()
|
||||
объекта причины провала.<br>
|
||||
**@returns** *Q.promise* проваленный промис
|
||||
|
||||
#### Cmd.end
|
||||
Завершает цепочку методов текущей подкоманды и возвращает экземпляр родительской команды.<br>
|
||||
**@returns** *COA.Cmd* `parent` родительская команда
|
||||
|
||||
### Opt
|
||||
Параметр — именованная сущность. У параметра может быть определено короткое или длинное имя для использования из командной строки.<br>
|
||||
**@namespace**<br>
|
||||
**@class** Переданный параметр
|
||||
|
||||
#### Opt.name
|
||||
Определяет канонический идентификатор параметра, используемый в вызовах API.<br>
|
||||
**@param** *String* `_name` имя параметра<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.title
|
||||
Определяет описание для параметра, используемое в текстовых сообщениях.<br>
|
||||
**@param** *String* `_title` название параметра<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.short
|
||||
Назначает ключ для короткого имени параметра, передаваемого из командной строки с одинарным дефисом (например, `-v`).<br>
|
||||
**@param** *String* `_short`<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.long
|
||||
Назначает ключ для длинного имени параметра, передаваемого из командной строки с двойным дефисом (например, `--version`).<br>
|
||||
**@param** *String* `_long`<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.flag
|
||||
Помечает параметр как логический, т.е. параметр не имеющий значения.<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.arr
|
||||
Помечает параметр как принимающий множественные значения.<br>
|
||||
Иначе будет использовано последнее переданное значение параметра.<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.req
|
||||
Помечает параметр как обязательный.<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.only
|
||||
Интерпретирует параметр как команду,
|
||||
т.е. программа будет завершена сразу после выполнения параметра.<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.val
|
||||
Назначает функцию валидации (или трансформации значения) для значения параметра.<br>
|
||||
Значение, полученное из командной строки, передается в функцию-валидатор прежде чем оно станет доступно из API.<br>
|
||||
Используется для валидации и трансформации введенных данных.<br>
|
||||
**@param** *Function* `_val` функция валидации,
|
||||
исполняемая в контексте экземпляра параметра
|
||||
и принимающая в качестве единственного параметра значение, полученное
|
||||
из командной строки<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.def
|
||||
Назначает значение параметра по умолчанию. Это значение также передается
|
||||
в функцию валидации как обычное значение.<br>
|
||||
**@param** *Object* `_def`<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.input
|
||||
Помечает параметр как принимающий ввод пользователя. <br>
|
||||
Позволяет использовать валидацию для STDIN.<br>
|
||||
**@returns** *{COA.Opt}* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.output
|
||||
Помечает параметр как вывод.<br>
|
||||
Позволяет использовать валидацию для STDOUT.<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.act
|
||||
Добавляет (или создает) действие для текущего параметра команды.
|
||||
Это действие будет выполнено, если текущий параметр есть
|
||||
в списке полученных параметров (с любым значением).<br>
|
||||
**@param** *Function* `act` функция, выполняемая в контексте
|
||||
экземпляра текущей команды и принимающая следующие параметры:<br>
|
||||
- *Object* `opts` параметры команды<br>
|
||||
- *Array* `args` аргументы команды<br>
|
||||
- *Object* `res` объект-аккумулятор результатов<br>
|
||||
Функция может вернуть проваленный промис из Cmd.reject (в случае ошибки)
|
||||
или любое другое значение, рассматриваемое как результат.<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.comp
|
||||
Назначает кастомную функцию автодополнения для текущей команды.<br>
|
||||
**@param** *Function* `fn` функция-генератор автодоплнения, исполняемая в
|
||||
контексте экземпляра команды.
|
||||
Принимает параметры:<br>
|
||||
- *Object* `opts` параметры автодополнения<br>
|
||||
Может возвращать промис или любое другое значение, рассматриваемое как результат исполнения команды.<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр параметра (для поддержки цепочки методов)
|
||||
|
||||
#### Opt.end
|
||||
Завершает цепочку методов текущего параметра и возвращает экземпляр родительской команды.<br>
|
||||
**@returns** *COA.Cmd* `parent` родительская команда
|
||||
|
||||
|
||||
### Arg
|
||||
Аргумент — неименованная сущность.<br>
|
||||
Аргументы передаются из командной строки как список неименованных значений.
|
||||
|
||||
#### Arg.name
|
||||
Определяет канонический идентификатор аргумента, используемый в вызовах API.<br>
|
||||
**@param** *String* `_name` имя аргумента<br>
|
||||
**@returns** *COA.Arg* `this` экземпляр аргумента (для поддержки цепочки методов)
|
||||
|
||||
#### Arg.title
|
||||
Определяет описание для аргумента, используемое в текстовых сообщениях.<br>
|
||||
**@param** *String* `_title` описание аргумента<br>
|
||||
**@returns** *COA.Arg* `this` экземпляр аргумента (для поддержки цепочки методов)
|
||||
|
||||
#### Arg.arr
|
||||
Помечает аргумент как принимающий множественные значения.<br>
|
||||
Иначе будет использовано последнее переданное значение аргумента.<br>
|
||||
**@returns** *COA.Arg* `this` экземпляр аргумента (для поддержки цепочки методов)
|
||||
|
||||
#### Arg.req
|
||||
Помечает аргумент как обязательный.<br>
|
||||
**@returns** *COA.Arg* `this` экземпляр аргумента (для поддержки цепочки методов)
|
||||
|
||||
#### Arg.val
|
||||
Назначает функцию валидации (или трансформации значения) для аргумента.<br>
|
||||
Значение, полученное из командной строки, передается в функцию-валидатор прежде чем оно станет доступно из API.<br>
|
||||
Используется для валидации и трансформации введенных данных.<br>
|
||||
**@param** *Function* `_val` функция валидации,
|
||||
исполняемая в контексте экземпляра аргумента
|
||||
и принимающая в качестве единственного параметра значение, полученное
|
||||
из командной строки<br>
|
||||
**@returns** *COA.Opt* `this` экземпляр аргумента (для поддержки цепочки методов)
|
||||
|
||||
#### Arg.def
|
||||
Назначает дефолтное значение для аргумента. Дефолтное значение передается
|
||||
в функцию валидации как обычное значение.<br>
|
||||
**@param** *Object* `_def`<br>
|
||||
**@returns** *COA.Arg* `this` экземпляр аргумента (для поддержки цепочки методов)
|
||||
|
||||
#### Arg.output
|
||||
Помечает параметр как вывод.<br>
|
||||
Позволяет назначить валидацию для STDOUT.<br>
|
||||
**@returns** *COA.Arg* `this` экземпляр аргумента (для поддержки цепочки методов)
|
||||
|
||||
#### Arg.comp
|
||||
Назначает кастомную функцию автодополнения для текущего аргумента.<br>
|
||||
**@param** *Function* `fn` функция-генератор автодоплнения,
|
||||
исполняемая в контексте текущей команды.
|
||||
Принимает параметры:<br>
|
||||
- *Object* `opts` параметры
|
||||
Может возвращать промис или любое другое значение, рассматриваемое как результат исполнения команды.<br>
|
||||
**@returns** *COA.Arg* `this` экземпляр аргумента (для поддержки цепочки методов)
|
||||
|
||||
#### Arg.end
|
||||
Завершает цепочку методов текущего аргумента и возвращает экземпляр родительской команды.<br>
|
||||
**@returns** *COA.Cmd* `parent` родительская команда
|
74
assets_old/node_modules/coa/coa.d.ts
generated
vendored
Normal file
74
assets_old/node_modules/coa/coa.d.ts
generated
vendored
Normal file
|
@ -0,0 +1,74 @@
|
|||
/// <reference types="q"/>
|
||||
|
||||
export const Arg: undefined;
|
||||
|
||||
export const Opt: undefined;
|
||||
|
||||
export function Cmd(cmd?: classes.Cmd): classes.Cmd;
|
||||
|
||||
export namespace classes {
|
||||
class Arg {
|
||||
constructor(cmd: Cmd);
|
||||
name(name: string): Arg;
|
||||
title(title: string): Arg;
|
||||
arr(): Arg;
|
||||
req(): Arg;
|
||||
val(validation: (this: Arg, value: any) => boolean): Arg;
|
||||
def(def: any): Arg;
|
||||
output(): Arg;
|
||||
comp(fn: (opts: any) => any): Arg;
|
||||
end(): Cmd;
|
||||
apply(...args: any[]): Arg;
|
||||
input(): Arg;
|
||||
reject(...args: any[]): Arg;
|
||||
}
|
||||
|
||||
class Cmd {
|
||||
constructor(cmd?: Cmd);
|
||||
static create(cmd?: Cmd): Cmd;
|
||||
api(): any;
|
||||
name(name: string): Cmd;
|
||||
title(title: string): Cmd;
|
||||
cmd(cmd?: Cmd): Cmd;
|
||||
opt(): Opt;
|
||||
arg(): Arg;
|
||||
act(act: (opts: any, args: any[], res: any) => any, force?: boolean): Cmd;
|
||||
apply(fn: Function, args?: any[]): Cmd;
|
||||
comp(fs: (opts: any) => any): Cmd;
|
||||
helpful(): Cmd;
|
||||
completable(): Cmd;
|
||||
usage(): string;
|
||||
run(argv: string[]): Cmd;
|
||||
invoke(cmds?: string|string[], opts?: any, args?: any): Q.Promise<any>;
|
||||
reject(reason: any): Q.Promise<any>;
|
||||
end(): Cmd;
|
||||
do(argv: string[]): any;
|
||||
extendable(pattern?: string): Cmd;
|
||||
}
|
||||
|
||||
class Opt {
|
||||
constructor(cmd?: Cmd);
|
||||
name(name: string): Opt;
|
||||
title(title: string): Opt;
|
||||
short(short: string): Opt;
|
||||
long(long: string): Opt;
|
||||
flag(): Opt;
|
||||
arr(): Opt;
|
||||
req(): Opt;
|
||||
only(): Opt;
|
||||
val(validation: (this: Opt, value: any) => boolean): Opt;
|
||||
def(def: any): Opt;
|
||||
input(): Opt;
|
||||
output(): Opt;
|
||||
act(act: (opts: any, args: any[], res: any) => any): Opt;
|
||||
comp(fn: (opts: any) => any): Opt;
|
||||
end(): Cmd;
|
||||
apply(...args: any[]): void;
|
||||
reject(...args: any[]): void;
|
||||
}
|
||||
}
|
||||
|
||||
export namespace shell {
|
||||
function escape(w: string): string;
|
||||
function unescape(w: string): string;
|
||||
}
|
1
assets_old/node_modules/coa/index.js
generated
vendored
Normal file
1
assets_old/node_modules/coa/index.js
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports = require('./lib');
|
58
assets_old/node_modules/coa/lib/arg.js
generated
vendored
Normal file
58
assets_old/node_modules/coa/lib/arg.js
generated
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
'use strict';
|
||||
|
||||
const
|
||||
CoaParam = require('./coaparam'),
|
||||
chalk = require('chalk');
|
||||
|
||||
/**
|
||||
* Argument
|
||||
*
|
||||
* Unnamed entity. From command line arguments passed as list of unnamed values.
|
||||
*
|
||||
* @class Arg
|
||||
* @extends CoaParam
|
||||
*/
|
||||
module.exports = class Arg extends CoaParam {
|
||||
/**
|
||||
* @constructs
|
||||
* @param {COA.Cmd} cmd - parent command
|
||||
*/
|
||||
constructor(cmd) {
|
||||
super(cmd);
|
||||
|
||||
this._cmd._args.push(this);
|
||||
}
|
||||
|
||||
_saveVal(args, val) {
|
||||
this._val && (val = this._val(val));
|
||||
|
||||
const name = this._name;
|
||||
this._arr
|
||||
? (args[name] || (args[name] = [])).push(val)
|
||||
: (args[name] = val);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
_parse(arg, args) {
|
||||
return this._saveVal(args, arg);
|
||||
}
|
||||
|
||||
_checkParsed(opts, args) {
|
||||
return !args.hasOwnProperty(this._name);
|
||||
}
|
||||
|
||||
_usage() {
|
||||
const res = [];
|
||||
|
||||
res.push(chalk.magentaBright(this._name.toUpperCase()), ' : ', this._title);
|
||||
|
||||
this._req && res.push(' ', chalk.redBright('(required)'));
|
||||
|
||||
return res.join('');
|
||||
}
|
||||
|
||||
_requiredText() {
|
||||
return `Missing required argument:\n ${this._usage()}`;
|
||||
}
|
||||
};
|
493
assets_old/node_modules/coa/lib/cmd.js
generated
vendored
Normal file
493
assets_old/node_modules/coa/lib/cmd.js
generated
vendored
Normal file
|
@ -0,0 +1,493 @@
|
|||
/* eslint-disable class-methods-use-this */
|
||||
'use strict';
|
||||
|
||||
const
|
||||
UTIL = require('util'),
|
||||
PATH = require('path'),
|
||||
EOL = require('os').EOL,
|
||||
|
||||
Q = require('q'),
|
||||
chalk = require('chalk'),
|
||||
|
||||
CoaObject = require('./coaobject'),
|
||||
Opt = require('./opt'),
|
||||
Arg = require('./arg'),
|
||||
completion = require('./completion');
|
||||
|
||||
/**
|
||||
* Command
|
||||
*
|
||||
* Top level entity. Commands may have options and arguments.
|
||||
*
|
||||
* @namespace
|
||||
* @class Cmd
|
||||
* @extends CoaObject
|
||||
*/
|
||||
class Cmd extends CoaObject {
|
||||
/**
|
||||
* @constructs
|
||||
* @param {COA.Cmd} [cmd] parent command
|
||||
*/
|
||||
constructor(cmd) {
|
||||
super(cmd);
|
||||
|
||||
this._parent(cmd);
|
||||
this._cmds = [];
|
||||
this._cmdsByName = {};
|
||||
this._opts = [];
|
||||
this._optsByKey = {};
|
||||
this._args = [];
|
||||
this._api = null;
|
||||
this._ext = false;
|
||||
}
|
||||
|
||||
static create(cmd) {
|
||||
return new Cmd(cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns object containing all its subcommands as methods
|
||||
* to use from other programs.
|
||||
*
|
||||
* @returns {Object}
|
||||
*/
|
||||
get api() {
|
||||
// Need _this here because of passed arguments into _api
|
||||
const _this = this;
|
||||
this._api || (this._api = function () {
|
||||
return _this.invoke.apply(_this, arguments);
|
||||
});
|
||||
|
||||
const cmds = this._cmdsByName;
|
||||
Object.keys(cmds).forEach(cmd => { this._api[cmd] = cmds[cmd].api; });
|
||||
|
||||
return this._api;
|
||||
}
|
||||
|
||||
_parent(cmd) {
|
||||
this._cmd = cmd || this;
|
||||
|
||||
this.isRootCmd ||
|
||||
cmd._cmds.push(this) &&
|
||||
this._name &&
|
||||
(this._cmd._cmdsByName[this._name] = this);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
get isRootCmd() {
|
||||
return this._cmd === this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a canonical command identifier to be used anywhere in the API.
|
||||
*
|
||||
* @param {String} name - command name
|
||||
* @returns {COA.Cmd} - this instance (for chainability)
|
||||
*/
|
||||
name(name) {
|
||||
super.name(name);
|
||||
|
||||
this.isRootCmd ||
|
||||
(this._cmd._cmdsByName[name] = this);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create new or add existing subcommand for current command.
|
||||
*
|
||||
* @param {COA.Cmd} [cmd] existing command instance
|
||||
* @returns {COA.Cmd} new subcommand instance
|
||||
*/
|
||||
cmd(cmd) {
|
||||
return cmd?
|
||||
cmd._parent(this)
|
||||
: new Cmd(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create option for current command.
|
||||
*
|
||||
* @returns {COA.Opt} new option instance
|
||||
*/
|
||||
opt() {
|
||||
return new Opt(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create argument for current command.
|
||||
*
|
||||
* @returns {COA.Opt} new argument instance
|
||||
*/
|
||||
arg() {
|
||||
return new Arg(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add (or set) action for current command.
|
||||
*
|
||||
* @param {Function} act - action function,
|
||||
* invoked in the context of command instance
|
||||
* and has the parameters:
|
||||
* - {Object} opts - parsed options
|
||||
* - {String[]} args - parsed arguments
|
||||
* - {Object} res - actions result accumulator
|
||||
* It can return rejected promise by Cmd.reject (in case of error)
|
||||
* or any other value treated as result.
|
||||
* @param {Boolean} [force=false] flag for set action instead add to existings
|
||||
* @returns {COA.Cmd} - this instance (for chainability)
|
||||
*/
|
||||
act(act, force) {
|
||||
if(!act) return this;
|
||||
|
||||
(!this._act || force) && (this._act = []);
|
||||
this._act.push(act);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make command "helpful", i.e. add -h --help flags for print usage.
|
||||
*
|
||||
* @returns {COA.Cmd} - this instance (for chainability)
|
||||
*/
|
||||
helpful() {
|
||||
return this.opt()
|
||||
.name('help')
|
||||
.title('Help')
|
||||
.short('h')
|
||||
.long('help')
|
||||
.flag()
|
||||
.only()
|
||||
.act(function() {
|
||||
return this.usage();
|
||||
})
|
||||
.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds shell completion to command, adds "completion" subcommand,
|
||||
* that makes all the magic.
|
||||
* Must be called only on root command.
|
||||
*
|
||||
* @returns {COA.Cmd} - this instance (for chainability)
|
||||
*/
|
||||
completable() {
|
||||
return this.cmd()
|
||||
.name('completion')
|
||||
.apply(completion)
|
||||
.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow command to be extendable by external node.js modules.
|
||||
*
|
||||
* @param {String} [pattern] Pattern of node.js module to find subcommands at.
|
||||
* @returns {COA.Cmd} - this instance (for chainability)
|
||||
*/
|
||||
extendable(pattern) {
|
||||
this._ext = pattern || true;
|
||||
return this;
|
||||
}
|
||||
|
||||
_exit(msg, code) {
|
||||
return process.once('exit', function(exitCode) {
|
||||
msg && console[code === 0 ? 'log' : 'error'](msg);
|
||||
process.exit(code || exitCode || 0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Build full usage text for current command instance.
|
||||
*
|
||||
* @returns {String} usage text
|
||||
*/
|
||||
usage() {
|
||||
const res = [];
|
||||
|
||||
this._title && res.push(this._fullTitle());
|
||||
|
||||
res.push('', 'Usage:');
|
||||
|
||||
this._cmds.length
|
||||
&& res.push([
|
||||
'', '', chalk.redBright(this._fullName()), chalk.blueBright('COMMAND'),
|
||||
chalk.greenBright('[OPTIONS]'), chalk.magentaBright('[ARGS]')
|
||||
].join(' '));
|
||||
|
||||
(this._opts.length + this._args.length)
|
||||
&& res.push([
|
||||
'', '', chalk.redBright(this._fullName()),
|
||||
chalk.greenBright('[OPTIONS]'), chalk.magentaBright('[ARGS]')
|
||||
].join(' '));
|
||||
|
||||
res.push(
|
||||
this._usages(this._cmds, 'Commands'),
|
||||
this._usages(this._opts, 'Options'),
|
||||
this._usages(this._args, 'Arguments')
|
||||
);
|
||||
|
||||
return res.join(EOL);
|
||||
}
|
||||
|
||||
_usage() {
|
||||
return chalk.blueBright(this._name) + ' : ' + this._title;
|
||||
}
|
||||
|
||||
_usages(os, title) {
|
||||
if(!os.length) return;
|
||||
|
||||
return ['', title + ':']
|
||||
.concat(os.map(o => ` ${o._usage()}`))
|
||||
.join(EOL);
|
||||
}
|
||||
|
||||
_fullTitle() {
|
||||
return `${this.isRootCmd? '' : this._cmd._fullTitle() + EOL}${this._title}`;
|
||||
}
|
||||
|
||||
_fullName() {
|
||||
return `${this.isRootCmd? '' : this._cmd._fullName() + ' '}${PATH.basename(this._name)}`;
|
||||
}
|
||||
|
||||
_ejectOpt(opts, opt) {
|
||||
const pos = opts.indexOf(opt);
|
||||
if(pos === -1) return;
|
||||
|
||||
return opts[pos]._arr?
|
||||
opts[pos] :
|
||||
opts.splice(pos, 1)[0];
|
||||
}
|
||||
|
||||
_checkRequired(opts, args) {
|
||||
if(this._opts.some(opt => opt._only && opts.hasOwnProperty(opt._name))) return;
|
||||
|
||||
const all = this._opts.concat(this._args);
|
||||
let i;
|
||||
while(i = all.shift())
|
||||
if(i._req && i._checkParsed(opts, args))
|
||||
return this.reject(i._requiredText());
|
||||
}
|
||||
|
||||
_parseCmd(argv, unparsed) {
|
||||
unparsed || (unparsed = []);
|
||||
|
||||
let i,
|
||||
optSeen = false;
|
||||
while(i = argv.shift()) {
|
||||
i.indexOf('-') || (optSeen = true);
|
||||
|
||||
if(optSeen || !/^\w[\w-_]*$/.test(i)) {
|
||||
unparsed.push(i);
|
||||
continue;
|
||||
}
|
||||
|
||||
let pkg, cmd = this._cmdsByName[i];
|
||||
if(!cmd && this._ext) {
|
||||
if(this._ext === true) {
|
||||
pkg = i;
|
||||
let c = this;
|
||||
while(true) { // eslint-disable-line
|
||||
pkg = c._name + '-' + pkg;
|
||||
if(c.isRootCmd) break;
|
||||
c = c._cmd;
|
||||
}
|
||||
} else if(typeof this._ext === 'string')
|
||||
pkg = ~this._ext.indexOf('%s')?
|
||||
UTIL.format(this._ext, i) :
|
||||
this._ext + i;
|
||||
|
||||
let cmdDesc;
|
||||
try {
|
||||
cmdDesc = require(pkg);
|
||||
} catch(e) {
|
||||
// Dummy
|
||||
}
|
||||
|
||||
if(cmdDesc) {
|
||||
if(typeof cmdDesc === 'function') {
|
||||
this.cmd().name(i).apply(cmdDesc).end();
|
||||
} else if(typeof cmdDesc === 'object') {
|
||||
this.cmd(cmdDesc);
|
||||
cmdDesc.name(i);
|
||||
} else throw new Error('Error: Unsupported command declaration type, '
|
||||
+ 'should be a function or COA.Cmd() object');
|
||||
|
||||
cmd = this._cmdsByName[i];
|
||||
}
|
||||
}
|
||||
|
||||
if(cmd) return cmd._parseCmd(argv, unparsed);
|
||||
|
||||
unparsed.push(i);
|
||||
}
|
||||
|
||||
return { cmd : this, argv : unparsed };
|
||||
}
|
||||
|
||||
_parseOptsAndArgs(argv) {
|
||||
const opts = {},
|
||||
args = {},
|
||||
nonParsedOpts = this._opts.concat(),
|
||||
nonParsedArgs = this._args.concat();
|
||||
|
||||
let res, i;
|
||||
while(i = argv.shift()) {
|
||||
if(i !== '--' && i[0] === '-') {
|
||||
const m = i.match(/^(--\w[\w-_]*)=(.*)$/);
|
||||
if(m) {
|
||||
i = m[1];
|
||||
this._optsByKey[i]._flag || argv.unshift(m[2]);
|
||||
}
|
||||
|
||||
const opt = this._ejectOpt(nonParsedOpts, this._optsByKey[i]);
|
||||
if(!opt) return this.reject(`Unknown option: ${i}`);
|
||||
|
||||
if(Q.isRejected(res = opt._parse(argv, opts))) return res;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
i === '--' && (i = argv.splice(0));
|
||||
Array.isArray(i) || (i = [i]);
|
||||
|
||||
let a;
|
||||
while(a = i.shift()) {
|
||||
let arg = nonParsedArgs.shift();
|
||||
if(!arg) return this.reject(`Unknown argument: ${a}`);
|
||||
|
||||
arg._arr && nonParsedArgs.unshift(arg);
|
||||
if(Q.isRejected(res = arg._parse(a, args))) return res;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
opts : this._setDefaults(opts, nonParsedOpts),
|
||||
args : this._setDefaults(args, nonParsedArgs)
|
||||
};
|
||||
}
|
||||
|
||||
_setDefaults(params, desc) {
|
||||
for(const item of desc)
|
||||
item._def !== undefined &&
|
||||
!params.hasOwnProperty(item._name) &&
|
||||
item._saveVal(params, item._def);
|
||||
|
||||
return params;
|
||||
}
|
||||
|
||||
_processParams(params, desc) {
|
||||
const notExists = [];
|
||||
|
||||
for(const item of desc) {
|
||||
const n = item._name;
|
||||
|
||||
if(!params.hasOwnProperty(n)) {
|
||||
notExists.push(item);
|
||||
continue;
|
||||
}
|
||||
|
||||
const vals = Array.isArray(params[n])? params[n] : [params[n]];
|
||||
delete params[n];
|
||||
|
||||
let res;
|
||||
for(const v of vals)
|
||||
if(Q.isRejected(res = item._saveVal(params, v)))
|
||||
return res;
|
||||
}
|
||||
|
||||
return this._setDefaults(params, notExists);
|
||||
}
|
||||
|
||||
_parseArr(argv) {
|
||||
return Q.when(this._parseCmd(argv), p =>
|
||||
Q.when(p.cmd._parseOptsAndArgs(p.argv), r => ({
|
||||
cmd : p.cmd,
|
||||
opts : r.opts,
|
||||
args : r.args
|
||||
})));
|
||||
}
|
||||
|
||||
_do(inputPromise) {
|
||||
return Q.when(inputPromise, input => {
|
||||
return [this._checkRequired]
|
||||
.concat(input.cmd._act || [])
|
||||
.reduce((res, act) =>
|
||||
Q.when(res, prev => act.call(input.cmd, input.opts, input.args, prev)),
|
||||
undefined);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse arguments from simple format like NodeJS process.argv
|
||||
* and run ahead current program, i.e. call process.exit when all actions done.
|
||||
*
|
||||
* @param {String[]} argv - arguments
|
||||
* @returns {COA.Cmd} - this instance (for chainability)
|
||||
*/
|
||||
run(argv) {
|
||||
argv || (argv = process.argv.slice(2));
|
||||
|
||||
const cb = code =>
|
||||
res => res?
|
||||
this._exit(res.stack || res.toString(), (res.hasOwnProperty('exitCode')? res.exitCode : code) || 0) :
|
||||
this._exit();
|
||||
|
||||
Q.when(this.do(argv), cb(0), cb(1)).done();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke specified (or current) command using provided
|
||||
* options and arguments.
|
||||
*
|
||||
* @param {String|String[]} [cmds] - subcommand to invoke (optional)
|
||||
* @param {Object} [opts] - command options (optional)
|
||||
* @param {Object} [args] - command arguments (optional)
|
||||
* @returns {Q.Promise}
|
||||
*/
|
||||
invoke(cmds, opts, args) {
|
||||
cmds || (cmds = []);
|
||||
opts || (opts = {});
|
||||
args || (args = {});
|
||||
typeof cmds === 'string' && (cmds = cmds.split(' '));
|
||||
|
||||
if(arguments.length < 3 && !Array.isArray(cmds)) {
|
||||
args = opts;
|
||||
opts = cmds;
|
||||
cmds = [];
|
||||
}
|
||||
|
||||
return Q.when(this._parseCmd(cmds), p => {
|
||||
if(p.argv.length)
|
||||
return this.reject(`Unknown command: ${cmds.join(' ')}`);
|
||||
|
||||
return Q.all([
|
||||
this._processParams(opts, this._opts),
|
||||
this._processParams(args, this._args)
|
||||
]).spread((_opts, _args) =>
|
||||
this._do({
|
||||
cmd : p.cmd,
|
||||
opts : _opts,
|
||||
args : _args
|
||||
})
|
||||
.fail(res => (res && res.exitCode === 0)?
|
||||
res.toString() :
|
||||
this.reject(res)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient function to run command from tests.
|
||||
*
|
||||
* @param {String[]} argv - arguments
|
||||
* @returns {Q.Promise}
|
||||
*/
|
||||
Cmd.prototype.do = function(argv) {
|
||||
return this._do(this._parseArr(argv || []));
|
||||
};
|
||||
|
||||
module.exports = Cmd;
|
101
assets_old/node_modules/coa/lib/coaobject.js
generated
vendored
Normal file
101
assets_old/node_modules/coa/lib/coaobject.js
generated
vendored
Normal file
|
@ -0,0 +1,101 @@
|
|||
/* eslint-disable class-methods-use-this */
|
||||
'use strict';
|
||||
|
||||
const Q = require('q');
|
||||
|
||||
/**
|
||||
* COA Object
|
||||
*
|
||||
* Base class for all COA-related objects
|
||||
*
|
||||
* --------|-----|-----|-----
|
||||
* | Cmd | Opt | Arg
|
||||
* --------|-----|-----|-----
|
||||
* name | ✓ | ✓ | ✓
|
||||
* title | ✓ | ✓ | ✓
|
||||
* comp | ✓ | ✓ | ✓
|
||||
* reject | ✓ | ✓ | ✓
|
||||
* end | ✓ | ✓ | ✓
|
||||
* apply | ✓ | ✓ | ✓
|
||||
*
|
||||
* @class CoaObject
|
||||
*/
|
||||
module.exports = class CoaObject {
|
||||
constructor(cmd) {
|
||||
this._cmd = cmd;
|
||||
this._name = null;
|
||||
this._title = null;
|
||||
this._comp = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a canonical identifier to be used anywhere in the API.
|
||||
*
|
||||
* @param {String} name - command, option or argument name
|
||||
* @returns {COA.CoaObject} - this instance (for chainability)
|
||||
*/
|
||||
name(name) {
|
||||
this._name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a long description to be used anywhere in text messages.
|
||||
* @param {String} title - human readable entity title
|
||||
* @returns {COA.CoaObject} - this instance (for chainability)
|
||||
*/
|
||||
title(title) {
|
||||
this._title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set custom additional completion for current object.
|
||||
*
|
||||
* @param {Function} comp - completion generation function,
|
||||
* invoked in the context of object instance.
|
||||
* Accepts parameters:
|
||||
* - {Object} opts - completion options
|
||||
* It can return promise or any other value threated as a result.
|
||||
* @returns {COA.CoaObject} - this instance (for chainability)
|
||||
*/
|
||||
comp(comp) {
|
||||
this._comp = comp;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply function with arguments in a context of object instance.
|
||||
*
|
||||
* @param {Function} fn - body
|
||||
* @param {Array.<*>} args... - arguments
|
||||
* @returns {COA.CoaObject} - this instance (for chainability)
|
||||
*/
|
||||
apply(fn) {
|
||||
arguments.length > 1?
|
||||
fn.apply(this, [].slice.call(arguments, 1))
|
||||
: fn.call(this);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return reject of actions results promise with error code.
|
||||
* Use in .act() for return with error.
|
||||
* @param {Object} reason - reject reason
|
||||
* You can customize toString() method and exitCode property
|
||||
* of reason object.
|
||||
* @returns {Q.promise} rejected promise
|
||||
*/
|
||||
reject(reason) {
|
||||
return Q.reject(reason);
|
||||
}
|
||||
|
||||
/**
|
||||
* Finish chain for current subcommand and return parent command instance.
|
||||
* @returns {COA.Cmd} parent command
|
||||
*/
|
||||
end() {
|
||||
return this._cmd;
|
||||
}
|
||||
};
|
125
assets_old/node_modules/coa/lib/coaparam.js
generated
vendored
Normal file
125
assets_old/node_modules/coa/lib/coaparam.js
generated
vendored
Normal file
|
@ -0,0 +1,125 @@
|
|||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
|
||||
const CoaObject = require('./coaobject');
|
||||
|
||||
/**
|
||||
* COA Parameter
|
||||
*
|
||||
* Base class for options and arguments
|
||||
*
|
||||
* --------|-----|-----|-----
|
||||
* | Cmd | Opt | Arg
|
||||
* --------|-----|-----|-----
|
||||
* arr | | ✓ | ✓
|
||||
* req | | ✓ | ✓
|
||||
* val | | ✓ | ✓
|
||||
* def | | ✓ | ✓
|
||||
* input | | ✓ | ✓
|
||||
* output | | ✓ | ✓
|
||||
*
|
||||
* @class CoaParam
|
||||
* @extends CoaObject
|
||||
*/
|
||||
module.exports = class CoaParam extends CoaObject {
|
||||
constructor(cmd) {
|
||||
super(cmd);
|
||||
|
||||
this._arr = false;
|
||||
this._req = false;
|
||||
this._val = undefined;
|
||||
this._def = undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a param accepts multiple values.
|
||||
* Otherwise, the value will be used by the latter passed.
|
||||
*
|
||||
* @returns {COA.CoaParam} - this instance (for chainability)
|
||||
*/
|
||||
arr() {
|
||||
this._arr = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a param required.
|
||||
*
|
||||
* @returns {COA.CoaParam} - this instance (for chainability)
|
||||
*/
|
||||
req() {
|
||||
this._req = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a validation (or value) function for param.
|
||||
* Value from command line passes through before becoming available from API.
|
||||
* Using for validation and convertion simple types to any values.
|
||||
*
|
||||
* @param {Function} val - validating function,
|
||||
* invoked in the context of option instance
|
||||
* and has one parameter with value from command line.
|
||||
* @returns {COA.CoaParam} - this instance (for chainability)
|
||||
*/
|
||||
val(val) {
|
||||
this._val = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a default value for param.
|
||||
* Default value passed through validation function as ordinary value.
|
||||
*
|
||||
* @param {*} def - default value of function generator
|
||||
* @returns {COA.CoaParam} - this instance (for chainability)
|
||||
*/
|
||||
def(def) {
|
||||
this._def = def;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make option value inputting stream.
|
||||
* It's add useful validation and shortcut for STDIN.
|
||||
*
|
||||
* @returns {COA.CoaParam} - this instance (for chainability)
|
||||
*/
|
||||
input() {
|
||||
process.stdin.pause();
|
||||
return this
|
||||
.def(process.stdin)
|
||||
.val(function(v) {
|
||||
if(typeof v !== 'string')
|
||||
return v;
|
||||
|
||||
if(v === '-')
|
||||
return process.stdin;
|
||||
|
||||
const s = fs.createReadStream(v, { encoding : 'utf8' });
|
||||
s.pause();
|
||||
return s;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Make option value outputing stream.
|
||||
* It's add useful validation and shortcut for STDOUT.
|
||||
*
|
||||
* @returns {COA.CoaParam} - this instance (for chainability)
|
||||
*/
|
||||
output() {
|
||||
return this
|
||||
.def(process.stdout)
|
||||
.val(function(v) {
|
||||
if(typeof v !== 'string')
|
||||
return v;
|
||||
|
||||
if(v === '-')
|
||||
return process.stdout;
|
||||
|
||||
return fs.createWriteStream(v, { encoding : 'utf8' });
|
||||
});
|
||||
}
|
||||
};
|
176
assets_old/node_modules/coa/lib/completion.js
generated
vendored
Normal file
176
assets_old/node_modules/coa/lib/completion.js
generated
vendored
Normal file
|
@ -0,0 +1,176 @@
|
|||
'use strict';
|
||||
|
||||
const constants = require('constants');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const Q = require('q');
|
||||
|
||||
const shell = require('./shell');
|
||||
const escape = shell.escape;
|
||||
const unescape = shell.unescape;
|
||||
|
||||
/**
|
||||
* Most of the code adopted from the npm package shell completion code.
|
||||
* See https://github.com/isaacs/npm/blob/master/lib/completion.js
|
||||
*
|
||||
* @returns {COA.CoaObject}
|
||||
*/
|
||||
module.exports = function completion() {
|
||||
return this
|
||||
.title('Shell completion')
|
||||
.helpful()
|
||||
.arg()
|
||||
.name('raw')
|
||||
.title('Completion words')
|
||||
.arr()
|
||||
.end()
|
||||
.act((opts, args) => {
|
||||
if(process.platform === 'win32') {
|
||||
const e = new Error('shell completion not supported on windows');
|
||||
e.code = 'ENOTSUP';
|
||||
e.errno = constants.ENOTSUP;
|
||||
return this.reject(e);
|
||||
}
|
||||
|
||||
// if the COMP_* isn't in the env, then just dump the script
|
||||
if((process.env.COMP_CWORD == null)
|
||||
|| (process.env.COMP_LINE == null)
|
||||
|| (process.env.COMP_POINT == null)) {
|
||||
return dumpScript(this._cmd._name);
|
||||
}
|
||||
|
||||
console.error('COMP_LINE: %s', process.env.COMP_LINE);
|
||||
console.error('COMP_CWORD: %s', process.env.COMP_CWORD);
|
||||
console.error('COMP_POINT: %s', process.env.COMP_POINT);
|
||||
console.error('args: %j', args.raw);
|
||||
|
||||
// completion opts
|
||||
opts = getOpts(args.raw);
|
||||
|
||||
// cmd
|
||||
const parsed = this._cmd._parseCmd(opts.partialWords);
|
||||
return Q.when(complete(parsed.cmd, parsed.opts), compls => {
|
||||
console.error('filtered: %j', compls);
|
||||
return console.log(compls.map(escape).join('\n'));
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
function dumpScript(name) {
|
||||
const defer = Q.defer();
|
||||
|
||||
fs.readFile(path.resolve(__dirname, 'completion.sh'), 'utf8', function(err, d) {
|
||||
if(err) return defer.reject(err);
|
||||
d = d.replace(/{{cmd}}/g, path.basename(name)).replace(/^#!.*?\n/, '');
|
||||
|
||||
process.stdout.on('error', onError);
|
||||
process.stdout.write(d, () => defer.resolve());
|
||||
});
|
||||
|
||||
return defer.promise;
|
||||
|
||||
function onError(err) {
|
||||
// Darwin is a real dick sometimes.
|
||||
//
|
||||
// This is necessary because the "source" or "." program in
|
||||
// bash on OS X closes its file argument before reading
|
||||
// from it, meaning that you get exactly 1 write, which will
|
||||
// work most of the time, and will always raise an EPIPE.
|
||||
//
|
||||
// Really, one should not be tossing away EPIPE errors, or any
|
||||
// errors, so casually. But, without this, `. <(cmd completion)`
|
||||
// can never ever work on OS X.
|
||||
if(err.errno !== constants.EPIPE) return defer.reject(err);
|
||||
process.stdout.removeListener('error', onError);
|
||||
return defer.resolve();
|
||||
}
|
||||
}
|
||||
|
||||
function getOpts(argv) {
|
||||
// get the partial line and partial word, if the point isn't at the end
|
||||
// ie, tabbing at: cmd foo b|ar
|
||||
const line = process.env.COMP_LINE;
|
||||
const w = +process.env.COMP_CWORD;
|
||||
const point = +process.env.COMP_POINT;
|
||||
const words = argv.map(unescape);
|
||||
const word = words[w];
|
||||
const partialLine = line.substr(0, point);
|
||||
const partialWords = words.slice(0, w);
|
||||
|
||||
// figure out where in that last word the point is
|
||||
let partialWord = argv[w] || '';
|
||||
let i = partialWord.length;
|
||||
while(partialWord.substr(0, i) !== partialLine.substr(-1 * i) && i > 0) i--;
|
||||
|
||||
partialWord = unescape(partialWord.substr(0, i));
|
||||
partialWord && partialWords.push(partialWord);
|
||||
|
||||
return {
|
||||
line,
|
||||
w,
|
||||
point,
|
||||
words,
|
||||
word,
|
||||
partialLine,
|
||||
partialWords,
|
||||
partialWord
|
||||
};
|
||||
}
|
||||
|
||||
function complete(cmd, opts) {
|
||||
let optWord, optPrefix,
|
||||
compls = [];
|
||||
|
||||
// Complete on cmds
|
||||
if(opts.partialWord.indexOf('-'))
|
||||
compls = Object.keys(cmd._cmdsByName);
|
||||
// Complete on required opts without '-' in last partial word
|
||||
// (if required not already specified)
|
||||
//
|
||||
// Commented out because of uselessness:
|
||||
// -b, --block suggest results in '-' on cmd line;
|
||||
// next completion suggest all options, because of '-'
|
||||
//.concat Object.keys(cmd._optsByKey).filter (v) -> cmd._optsByKey[v]._req
|
||||
else {
|
||||
// complete on opt values: --opt=| case
|
||||
const m = opts.partialWord.match(/^(--\w[\w-_]*)=(.*)$/);
|
||||
if(m) {
|
||||
optWord = m[1];
|
||||
optPrefix = optWord + '=';
|
||||
} else
|
||||
// complete on opts
|
||||
// don't complete on opts in case of --opt=val completion
|
||||
// TODO: don't complete on opts in case of unknown arg after commands
|
||||
// TODO: complete only on opts with arr() or not already used
|
||||
// TODO: complete only on full opts?
|
||||
compls = Object.keys(cmd._optsByKey);
|
||||
}
|
||||
|
||||
// complete on opt values: next arg case
|
||||
opts.partialWords[opts.w - 1].indexOf('-') || (optWord = opts.partialWords[opts.w - 1]);
|
||||
|
||||
// complete on opt values: completion
|
||||
let opt;
|
||||
optWord
|
||||
&& (opt = cmd._optsByKey[optWord])
|
||||
&& !opt._flag
|
||||
&& opt._comp
|
||||
&& (compls = Q.join(compls,
|
||||
Q.when(opt._comp(opts),
|
||||
(c, o) => c.concat(o.map(v => (optPrefix || '') + v)))));
|
||||
|
||||
// TODO: complete on args values (context aware, custom completion?)
|
||||
|
||||
// custom completion on cmds
|
||||
cmd._comp && (compls = Q.join(compls, Q.when(cmd._comp(opts)), (c, o) => c.concat(o)));
|
||||
|
||||
// TODO: context aware custom completion on cmds, opts and args
|
||||
// (can depend on already entered values, especially options)
|
||||
|
||||
return Q.when(compls, complitions => {
|
||||
console.error('partialWord: %s', opts.partialWord);
|
||||
console.error('compls: %j', complitions);
|
||||
return compls.filter(c => c.indexOf(opts.partialWord) === 0);
|
||||
});
|
||||
}
|
43
assets_old/node_modules/coa/lib/completion.sh
generated
vendored
Normal file
43
assets_old/node_modules/coa/lib/completion.sh
generated
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env bash
|
||||
###-begin-{{cmd}}-completion-###
|
||||
#
|
||||
# {{cmd}} command completion script
|
||||
#
|
||||
# Installation: {{cmd}} completion >> ~/.bashrc (or ~/.zshrc)
|
||||
# Or, maybe: {{cmd}} completion > /usr/local/etc/bash_completion.d/{{cmd}}
|
||||
#
|
||||
|
||||
COMP_WORDBREAKS=${COMP_WORDBREAKS/=/}
|
||||
COMP_WORDBREAKS=${COMP_WORDBREAKS/@/}
|
||||
export COMP_WORDBREAKS
|
||||
|
||||
if complete &>/dev/null; then
|
||||
_{{cmd}}_completion () {
|
||||
local si="$IFS"
|
||||
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$COMP_CWORD" \
|
||||
COMP_LINE="$COMP_LINE" \
|
||||
COMP_POINT="$COMP_POINT" \
|
||||
{{cmd}} completion -- "${COMP_WORDS[@]}" \
|
||||
2>/dev/null)) || return $?
|
||||
IFS="$si"
|
||||
}
|
||||
complete -F _{{cmd}}_completion {{cmd}}
|
||||
elif compctl &>/dev/null; then
|
||||
_{{cmd}}_completion () {
|
||||
local cword line point words si
|
||||
read -Ac words
|
||||
read -cn cword
|
||||
let cword-=1
|
||||
read -l line
|
||||
read -ln point
|
||||
si="$IFS"
|
||||
IFS=$'\n' reply=($(COMP_CWORD="$cword" \
|
||||
COMP_LINE="$line" \
|
||||
COMP_POINT="$point" \
|
||||
{{cmd}} completion -- "${words[@]}" \
|
||||
2>/dev/null)) || return $?
|
||||
IFS="$si"
|
||||
}
|
||||
compctl -K _{{cmd}}_completion {{cmd}}
|
||||
fi
|
||||
###-end-{{cmd}}-completion-###
|
14
assets_old/node_modules/coa/lib/index.js
generated
vendored
Normal file
14
assets_old/node_modules/coa/lib/index.js
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
const
|
||||
Cmd = require('./cmd'),
|
||||
Opt = require('./opt'),
|
||||
Arg = require('./arg'),
|
||||
shell = require('./shell');
|
||||
|
||||
module.exports = {
|
||||
Cmd : Cmd.create,
|
||||
Opt : Opt.create,
|
||||
Arg : Arg.create,
|
||||
classes : { Cmd, Opt, Arg },
|
||||
shell,
|
||||
require
|
||||
};
|
155
assets_old/node_modules/coa/lib/opt.js
generated
vendored
Normal file
155
assets_old/node_modules/coa/lib/opt.js
generated
vendored
Normal file
|
@ -0,0 +1,155 @@
|
|||
'use strict';
|
||||
|
||||
const
|
||||
Q = require('q'),
|
||||
|
||||
CoaParam = require('./coaparam'),
|
||||
chalk = require('chalk');
|
||||
|
||||
/**
|
||||
* Option
|
||||
*
|
||||
* Named entity. Options may have short and long keys for use from command line.
|
||||
*
|
||||
* @namespace
|
||||
* @class Opt
|
||||
* @extends CoaParam
|
||||
*/
|
||||
module.exports = class Opt extends CoaParam {
|
||||
/**
|
||||
* @constructs
|
||||
* @param {COA.Cmd} cmd - parent command
|
||||
*/
|
||||
constructor(cmd) {
|
||||
super(cmd);
|
||||
|
||||
this._short = null;
|
||||
this._long = null;
|
||||
this._flag = false;
|
||||
this._only = false;
|
||||
this._cmd._opts.push(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a short key for option to be used with one hyphen from command line.
|
||||
*
|
||||
* @param {String} short - short name
|
||||
* @returns {COA.Opt} - this instance (for chainability)
|
||||
*/
|
||||
short(short) {
|
||||
this._short = short;
|
||||
this._cmd._optsByKey[`-${short}`] = this;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a short key for option to be used with double hyphens from command line.
|
||||
*
|
||||
* @param {String} long - long name
|
||||
* @returns {COA.Opt} - this instance (for chainability)
|
||||
*/
|
||||
long(long) {
|
||||
this._long = long;
|
||||
this._cmd._optsByKey[`--${long}`] = this;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an option boolean, i.e. option without value.
|
||||
*
|
||||
* @returns {COA.Opt} - this instance (for chainability)
|
||||
*/
|
||||
flag() {
|
||||
this._flag = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes an option to act as a command,
|
||||
* i.e. program will exit just after option action.
|
||||
*
|
||||
* @returns {COA.Opt} - this instance (for chainability)
|
||||
*/
|
||||
only() {
|
||||
this._only = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add action for current option command.
|
||||
* This action is performed if the current option
|
||||
* is present in parsed options (with any value).
|
||||
*
|
||||
* @param {Function} act - action function,
|
||||
* invoked in the context of command instance
|
||||
* and has the parameters:
|
||||
* - {Object} opts - parsed options
|
||||
* - {Array} args - parsed arguments
|
||||
* - {Object} res - actions result accumulator
|
||||
* It can return rejected promise by Cmd.reject (in case of error)
|
||||
* or any other value treated as result.
|
||||
* @returns {COA.Opt} - this instance (for chainability)
|
||||
*/
|
||||
act(act) {
|
||||
// Need function here for arguments
|
||||
const opt = this;
|
||||
this._cmd.act(function(opts) {
|
||||
if(!opts.hasOwnProperty(opt._name)) return;
|
||||
|
||||
const res = act.apply(this, arguments);
|
||||
if(!opt._only) return res;
|
||||
|
||||
return Q.when(res, out => this.reject({
|
||||
toString : () => out.toString(),
|
||||
exitCode : 0
|
||||
}));
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
_saveVal(opts, val) {
|
||||
this._val && (val = this._val(val));
|
||||
|
||||
const name = this._name;
|
||||
this._arr
|
||||
? (opts[name] || (opts[name] = [])).push(val)
|
||||
: (opts[name] = val);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
_parse(argv, opts) {
|
||||
return this._saveVal(opts, this._flag ? true : argv.shift());
|
||||
}
|
||||
|
||||
_checkParsed(opts) {
|
||||
return !opts.hasOwnProperty(this._name);
|
||||
}
|
||||
|
||||
_usage() {
|
||||
const res = [],
|
||||
nameStr = this._name.toUpperCase();
|
||||
|
||||
if(this._short) {
|
||||
res.push('-', chalk.greenBright(this._short));
|
||||
this._flag || res.push(' ' + nameStr);
|
||||
res.push(', ');
|
||||
}
|
||||
|
||||
if(this._long) {
|
||||
res.push('--', chalk.green(this._long));
|
||||
this._flag || res.push('=' + nameStr);
|
||||
}
|
||||
|
||||
res.push(' : ', this._title);
|
||||
|
||||
this._req && res.push(' ', chalk.redBright('(required)'));
|
||||
|
||||
return res.join('');
|
||||
}
|
||||
|
||||
_requiredText() {
|
||||
return `Missing required option:\n ${this._usage()}`;
|
||||
}
|
||||
};
|
14
assets_old/node_modules/coa/lib/shell.js
generated
vendored
Normal file
14
assets_old/node_modules/coa/lib/shell.js
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
module.exports = { escape, unescape };
|
||||
|
||||
function unescape(w) {
|
||||
w = w.charAt(0) === '"'
|
||||
? w.replace(/^"|([^\\])"$/g, '$1')
|
||||
: w.replace(/\\ /g, ' ');
|
||||
|
||||
return w.replace(/\\("|'|\$|`|\\)/g, '$1');
|
||||
}
|
||||
|
||||
function escape(w) {
|
||||
w = w.replace(/(["'$`\\])/g,'\\$1');
|
||||
return w.match(/\s+/) ? `"${w}"` : w;
|
||||
}
|
53
assets_old/node_modules/coa/package.json
generated
vendored
Normal file
53
assets_old/node_modules/coa/package.json
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
{
|
||||
"name": "coa",
|
||||
"description": "Command-Option-Argument: Yet another parser for command line options.",
|
||||
"version": "2.0.2",
|
||||
"homepage": "http://github.com/veged/coa",
|
||||
"author": "Sergey Berezhnoy <veged@ya.ru> (http://github.com/veged)",
|
||||
"maintainers": [
|
||||
"Sergey Berezhnoy <veged@ya.ru> (http://github.com/veged)",
|
||||
"Sergey Belov <peimei@ya.ru> (http://github.com/arikon)"
|
||||
],
|
||||
"contributors": [
|
||||
"Sergey Belov <peimei@ya.ru> (http://github.com/arikon)"
|
||||
],
|
||||
"files": [
|
||||
"lib/",
|
||||
"index.js",
|
||||
"coa.d.ts",
|
||||
"README.ru.md"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/veged/coa.git"
|
||||
},
|
||||
"directories": {
|
||||
"lib": "./lib"
|
||||
},
|
||||
"dependencies": {
|
||||
"@types/q": "^1.5.1",
|
||||
"chalk": "^2.4.1",
|
||||
"q": "^1.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"chai": "~1.7.2",
|
||||
"coveralls": "^2.11.16",
|
||||
"eslint": "^4.15.0",
|
||||
"eslint-config-pedant": "^1.0.0",
|
||||
"mocha": "~1.21.4",
|
||||
"nyc": "^10.1.2"
|
||||
},
|
||||
"scripts": {
|
||||
"clean": "rm -r .nyc_output coverage",
|
||||
"coverage": "nyc --reporter=text --reporter=html mocha; echo; echo 'Open coverage/index.html file in your browser'",
|
||||
"coveralls": "nyc report --reporter=text-lcov | coveralls",
|
||||
"lint": "eslint .",
|
||||
"pretest": "npm run lint",
|
||||
"test": "nyc mocha"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4.0"
|
||||
},
|
||||
"types": "./coa.d.ts",
|
||||
"license": "MIT"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue