Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Yord committed Jun 17, 2020
2 parents 2801b78 + 680e8cb commit 7e67ee9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
18 changes: 14 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "shargs-repl",
"version": "0.2.0",
"version": "0.3.0",
"description": "A REPL using shargs commands",
"keywords": [
"shargs",
Expand Down
20 changes: 7 additions & 13 deletions src/repl/replEval.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,15 @@ const replEval = (parser, commands) => {
const parse = parser(commands)

return (cmd, context, filename, callback) => {
const {errs, args} = parse(cmd)
const { errs, args } = parse(cmd)

const strings = Object.entries(args).map(([key, value]) => {
const cmd = commands.opts.find(_ => _.args.includes(key)) || {action: _ => ''}
const action = cmd.action || (_ => '')
return action(value)
Object.entries(args).forEach(([key, value]) => {
const cmd = commands.opts.find(_ => _.args.includes(key)) || { action: _ => undefined }
const action = cmd.action || (_ => undefined)

action(value, errs)
})

const output = (
errs.length > 0 ? errs.map(({code, msg}) => `${code}: ${msg}`).join('\n')
: strings.join('\n')
)

console.log(output)


callback(null, undefined);
}
}
Expand Down

0 comments on commit 7e67ee9

Please sign in to comment.