Skip to content

Commit 6f1c957

Browse files
author
Robin Radic
committed
upd
1 parent 9f2a126 commit 6f1c957

20 files changed

+313
-25
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ src/**/*.js.map
1111
/console.iml
1212
/bin
1313
/gulpfile.js
14+
/vpproject

.nyc_output/4dc3205058f65d44995fec56c161e72b.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

gulpfile.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as fs from "fs-extra";
33
import * as tsc from "gulp-typescript";
44
import { resolve } from "path";
55
import * as _ from 'lodash'
6-
6+
import * as ts from 'typescript'
77
const c = {
88
src : [ 'src/**/*.ts' ],
99
fileName : 'console',
@@ -18,11 +18,6 @@ let parsedNode = cli.resolve()
1818
1919
cli.handle(parsedNode);`
2020

21-
const tsProject = {
22-
lib : tsc.createProject("tsconfig.json", { module: "es2015", declaration: true, typescript: require("typescript") }),
23-
src : tsc.createProject("tsconfig.json", { typescript: require("typescript") }),
24-
test: tsc.createProject("tsconfig.json", { typescript: require("typescript") })
25-
};
2621

2722

2823
const
@@ -41,6 +36,12 @@ const
4136
ghPages = require("gulp-gh-pages")
4237
;
4338

39+
const tsProject = {
40+
lib : tsc.createProject("tsconfig.json", { module: "es2015", declaration: true, typescript: ts }),
41+
src : tsc.createProject("tsconfig.json", { typescript: ts}),
42+
test: tsc.createProject("tsconfig.json", { target: "es6", sourceMap: true, typescript: ts })
43+
};
44+
4445
gulp.task('clean', [ 'clean:src', 'clean:build' ]);
4546

4647
gulp.task('clean:build', () => gulp.src([ 'dist', 'dts', 'es', 'lib', 'umd', 'coverage', '.publish', 'docs' ]).pipe(clean()));
@@ -98,13 +99,13 @@ gulp.task("build:src", () => {
9899

99100
gulp.task("build:test", () => {
100101
return gulp.src([
101-
"spec/**/*.ts"
102+
"tests/**/*.ts"
102103
])
103104
.pipe(tsProject.test())
104105
.on("error", function (err) {
105106
process.exit(1);
106107
})
107-
.js.pipe(gulp.dest("spec/"));
108+
.js.pipe(gulp.dest("tests/"));
108109
});
109110

110111
gulp.task("build", (cb) => {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@radic/console",
3-
"version": "0.0.13",
3+
"version": "0.0.12",
44
"description": "Console ",
55
"main": "src/index.js",
66
"typings": "lib/index.d.ts",
@@ -26,7 +26,7 @@
2626
},
2727
"dependencies": {
2828
"@radic/console-colors": "^0.9.5",
29-
"@radic/util": "^1.7.5",
29+
"@radic/util": "^1.7.3",
3030
"archy": "^1.0.0",
3131
"async": "^2.4.0",
3232
"axios": "^0.16.1",

src/core/Cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class Cli {
6868

6969
this.events.fire(new CliParseEvent(config, this.globalOptions))
7070
let transformedOptions = transformOptions(this.globalOptions);
71+
transformedOptions.configuration = this.config('parser.yargs')
7172
let result = parser(config.args, transformedOptions) as YargsParserArgv;
7273
this.events.fire(new CliParsedEvent(config, result, this.globalOptions))
7374
this._parsedCommands.push(config);
@@ -106,6 +107,7 @@ export class Cli {
106107
this.events.fire(new CliExecuteCommandParseEvent(config, optionConfigs))
107108

108109
let transformedOptions = transformOptions(this.globalOptions.concat(optionConfigs));
110+
transformedOptions.configuration = this.config('parser.yargs')
109111
let argv = parser(config.args, transformedOptions) as YargsParserArgv;
110112

111113
if ( ! isAlwaysRun )

src/defaults.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const defaults = {
2727
'camel-case-expansion' : true,
2828
'dot-notation' : true,
2929
'parse-numbers' : true,
30-
'boolean-negation' : true,
30+
'boolean-negation' : false,
3131
'duplicate-arguments-array': true,
3232
'flatten-duplicate-arrays' : true
3333
},
@@ -84,8 +84,9 @@ export const defaults = {
8484
return <CommandArgumentConfig> cloneDeep({
8585
position: index,
8686
name : null,
87-
desc : '',
87+
description : '',
8888
alias : null,
89+
type: 'string',
8990
required: false,
9091
variadic: false,
9192
default: null

src/helpers/Help.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ export class CommandDescriptionHelper {
152152
].join('');
153153
row.push(name)
154154

155-
row.push(arg.desc || '')
155+
row.push(arg.description || '')
156156

157157
let type = [
158158
'[',

src/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface CommandArgumentConfig {
2020
alias?: string | null
2121
required?: boolean
2222
variadic?: boolean
23-
desc?: string
23+
description?: string
2424
type?: string
2525
default?:any | null
2626
}

src/utils.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function prepareArguments<T extends CommandConfig = CommandConfig>(config
5252
//https://regex101.com/r/vSqbuK/1
5353

5454
let name = config.name.replace(/\[\]/g, '__')
55-
let argumentPattern = /[{|\[](.*?)[}|\]]/gm
55+
let argumentPattern = /[{\[](.*)[}\]]/gm
5656
if ( argumentPattern.test(name) ) {
5757
if ( name.match(argumentPattern) === null )
5858
return config
@@ -77,7 +77,7 @@ export function prepareArguments<T extends CommandConfig = CommandConfig>(config
7777
if ( hasAlias ) exp += '\\/(.*?)'
7878
if ( hasType ) exp += ':(.*?)'
7979
if ( isArray ) exp += '__'
80-
if ( hasDefault ) exp += '='
80+
if ( hasDefault ) exp += '=(.*?)'
8181
if ( hasDesc ) exp += '@(.*?)'
8282
exp += '$'
8383

@@ -89,9 +89,14 @@ export function prepareArguments<T extends CommandConfig = CommandConfig>(config
8989
if ( hasAlias ) arg.alias = res[ $ ++ ];
9090
if ( hasType ) arg.type = res[ $ ++ ]
9191
if ( hasDefault ) arg.default = res[ $ ++ ]
92-
if ( hasDesc ) arg.desc = res[ $ ++ ]
92+
if ( hasDesc ) arg.description = res[ $ ++ ]
9393
if ( isArray ) arg.variadic = true;
9494

95+
if(hasDefault){
96+
// console.dir({name, matches,original,exp,arg})
97+
arg.default = JSON.parse(arg.default);
98+
}
99+
95100
args.push(arg);
96101
})
97102
config.arguments = args;
@@ -205,21 +210,24 @@ export function parseArguments(argv_: string[], args: CommandArgumentConfig[] =
205210
let res = {};
206211
args.forEach(arg => {
207212
let val: any = argv_[ arg.position ];
208-
// val = transformArgumentType<any>(val, arg);
209213

210214
if ( ! val && arg.required ) {
211215
invalid.push(arg.name);
212216
}
213-
// val = transformArgumentType()
217+
214218
if ( arg.variadic ) {
215-
if ( ! res[ arg.name ] ) {
216-
res[ arg.name ] = [ val ];
217-
} else {
218-
res[ arg.name ].push(val)
219+
val = argv_.slice(arg.position, argv_.length);
220+
if(arg.default && val.length === 0){
221+
val = JSON.parse(arg.default);
219222
}
220-
} else {
221-
res[ arg.name ] = val;
222223
}
224+
225+
if(!val && arg.default){
226+
val = JSON.parse(arg.default)
227+
}
228+
229+
res[ arg.name ] = transformArgumentType(val, arg);
230+
223231
if ( arg.alias ) {
224232
res[ arg.alias ] = res[ arg.name ];
225233
}

0 commit comments

Comments
 (0)