Skip to content

Commit

Permalink
Modify fromArgs to pass rawCommand to command args
Browse files Browse the repository at this point in the history
  • Loading branch information
Yord committed Jun 15, 2020
1 parent 1aac778 commit 3bb73b8
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const lexer = lexerSync({
opts: [restrictToOnly]
})

const parser = parserSync({
const parser = cmd => rawCommand => parserSync({
toArgv,
opts: [restrictToOnly],
fromArgs
})
fromArgs: fromArgs(rawCommand)
})(cmd)(rawCommand)

module.exports = {
lexer,
Expand All @@ -25,9 +25,18 @@ function toArgv (str) {
}
}

function fromArgs ({errs, args}) {
return {
function fromArgs (rawCommandNewline) {
const rawCommand = rawCommandNewline.replace('\n', '')

const addRawCommand = cmd => (
Object
.entries(cmd)
.map(([key, obj]) => [key, {...obj, rawCommand}])
.reduce((obj, [key, val]) => ({...obj, [key]: val}), {})
)

return ({errs, args}) => ({
errs,
args: typeof args[1] === 'undefined' ? args[0] : {...args[1], _: args[0]._}
}
args: typeof args[1] === 'undefined' ? args[0] : {...addRawCommand(args[1]), _: args[0]._}
})
}

0 comments on commit 3bb73b8

Please sign in to comment.