dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.63k stars 278 forks source link

variadic argument parsing error #270

Closed disarticulate closed 5 years ago

disarticulate commented 7 years ago

"vorpal": "^1.12.0"

const vorpal = require('vorpal')()

vorpal
  .command('sync [args...]')
  .option('-n, --next',`Run next sync command and record log as [args...]`)
  .action(function({ args, options }, callback) {
    console.log(args, options)
  })
vorpal
  .delimiter(`torrents > `)
  .show()

vorpal.execSync('sync -n geodocr [magnetURI:7c9408e8166cf290c9a5a82792d9b590894ab06f] > magnet:?xt=urn:btih:7c9408e8166cf290c9a5areadline.js:101506f&dn=undefined&tr=wss%3A%2F%2Fgeodocr.com%2Ftracker&tr=wss%3A%2F%2Fmeleor.thenovel.org%2Ftracker')
    throw new Error('vorpal._exec was called with an undefined command.');
    ^

Error: vorpal._exec was called with an undefined command.
    at Vorpal.vorpal._exec (/home/cy/geodocr/node_modules/vorpal/dist/vorpal.js:787:11)
    at Vorpal.vorpal._execQueueItem (/home/cy/geodocr/node_modules/vorpal/dist/vorpal.js:751:17)
    at Vorpal.vorpal.execSync (/home/cy/geodocr/node_modules/vorpal/dist/vorpal.js:719:15)
    at Object.<anonymous> (/home/cy/geodocr/tests/node.geodocr.torrents.magnetURI.js:13:8)
    at Module._compile (module.js:569:30)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:503:32)
    at tryModuleLoad (module.js:466:12)
    at Function.Module._load (module.js:458:3)
    at Function.Module.runMain (module.js:605:10)

Not sure where the parsing gets confused.

milesj commented 7 years ago

Try wrapping your arguments in quotes.

mdouglass commented 6 years ago

Ran into this same error today, it does not appear to be a quoting issue. Simplified the sample above as follows:

const vorpal = require('vorpal')()

try {
  vorpal.execSync('ok')
  console.log('PASS: ok worked')
} catch (e) {
  console.log('FAIL: ok failed', e.stack)
}

try {
  vorpal.execSync('undefine')
  console.log('PASS: undefine worked')
} catch (e) {
  console.log('FAIL: undefine failed', e.stack)
}

I would expect that would output PASS twice in a row. But it actually does PASS for the first and FAIL for the second:

> temp@1.0.0 start /Users/mdouglass/kixeye/km/server/temp
> node index.js

  Invalid Command. Showing Help:

  Commands:

    help [command...]  Provides help for a given command.
    exit               Exits application.

PASS: ok worked
FAIL: undefine failed Error: vorpal._exec was called with an undefined command.
    at Vorpal.vorpal._exec (/Users/mdouglass/kixeye/km/server/temp/node_modules/vorpal/dist/vorpal.js:787:11)
    at Vorpal.vorpal._execQueueItem (/Users/mdouglass/kixeye/km/server/temp/node_modules/vorpal/dist/vorpal.js:751:17)
    at Vorpal.vorpal.execSync (/Users/mdouglass/kixeye/km/server/temp/node_modules/vorpal/dist/vorpal.js:719:15)
    at Object.<anonymous> (/Users/mdouglass/kixeye/km/server/temp/index.js:13:10)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:744:10)

Tested with Node v10.3.0, npm v6.1.0

mdouglass commented 6 years ago

Error is being thrown at https://github.com/dthree/vorpal/blob/master/dist/vorpal.js#L834