New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash on second call to help command #776
Comments
Add a root command to which all additional commands are added as subcommands. Temporarily disable the `--help` and `--version` options, as they cause the bot to crash. Refs yargs/yargs#776
Add a root command to which all additional commands are added as subcommands. Temporarily disable the `--help` and `--version` options, as they cause the bot to crash. Refs yargs/yargs#776
@scriptdaemon hoping to spend a few hours hacking on yargs tomorrow, sorry that it's taken me a while to get to this. This gives a pretty good starting point, have you made any more headway -- I'd love to work on getting a minimal failing test around this behavior. |
I'm wondering if it might have something to do with the |
@scriptdaemon, we're getting pretty close to landing the 7.x branch of yargs -- I think it would be good to test against this, everything defaults to global now; the distinction between global and local was confusing folks. |
I don't have a lot of time at the moment to look more into this, but a quick test crashes the bot (without
Code: latest from Commands issued: The code works using |
We're starting to enforce argument patterns in the API, it looks like we're
too aggressive for wrap():
https://github.com/yargs/yargs/pull/767/files#diff-6dd17733300c85ca1a41786abcb4a1c9R682
Do you think we should explicitly require a null? Or treat empt as no wrap?
I can see an argument both ways -- I lean towards allowing undefined.
…On Saturday, February 18, 2017, Kenneth Williams ***@***.***> wrote:
I don't have a lot of time at the moment to look more into this, but a
quick test crashes the bot (without help() or version()) with this error:
/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/lib/argsert.js:22
throw Error('Not enough arguments provided. Expected ' + parsed.demanded.length +
^
Error: Not enough arguments provided. Expected 1 but received 0.
at module.exports (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/lib/argsert.js:22:11)
at Object.Yargs.self.wrap (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/yargs.js:682:5)
at Object.builder (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/lib/steam-bot.js:63:17)
at Object.self.runCommand (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/lib/command.js:149:35)
at Object.Yargs.self._parseArgs (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/yargs.js:983:28)
at Object.Yargs.self.parse (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/node_modules/yargs/yargs.js:527:23)
at SteamBot.exec (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/lib/steam-bot.js:115:18)
at SteamUser.SteamBot._client.on (/mnt/c/Users/kwilliams/Documents/Projects/cheevobot/lib/steam-bot.js:40:12)
at emitThree (events.js:116:13)
at SteamUser.emit (events.js:195:7)
Code: latest from https://github.com/scriptdaemon/cheevobot
Commands issued: !ch uptime, !ch dice, !ch dice 3d6
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#776 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAL4MYXJxr2pGe5nZGeQPetxKHpycVuyks5rd2_ngaJpZM4L3cmR>
.
|
Oh, I see. I don't have a preference either way, as long as it's documented. I'll test again tomorrow with a value specified. |
@bcoe Sorry "tomorrow" kinda became "the day after tomorrow." Strange, but it appears I was wrong. It works fine (without Probably unrelated (so I can open another issue if needed): |
@scriptdaemon I managed to reproduce the issue with Perhaps you could take that branch for a spin. As for the issue with
'use strict'
// Node packaged modules
const yargs = require('./yargs')
const parser = yargs()
parser.command({
command: '!ch', // config.get('cmd'),
description: 'test desc', // config.get('description'),
builder: yargs => {
yargs.command('dice', '', () => {}, () => {
console.log('dice')
})
yargs.command('uptime', '', () => {}, () => {
console.log('uptime')
})
yargs.help()
yargs.strict()
yargs.version()
}
})
parser.parse('!ch uptime', {}, (err, argv, output) => {
if (err && !output) throw err
if (output) {
console.log(output)
}
})
parser.parse('!ch dice', {}, (err, argv, output) => {
if (err && !output) throw err
if (output) {
console.log(output)
}
}) works like a charm on the branch I have open. |
@bcoe That fixes the Updating your code like so: 'use strict'
// Node packaged modules
const yargs = require('yargs')
const parser = yargs()
parser.command({
command: '!ch', // config.get('cmd'),
description: 'test desc', // config.get('description'),
builder: yargs => {
yargs.command('dice', '', () => {}, () => {
console.log('dice')
})
yargs.command('uptime', '', () => {}, () => {
console.log('uptime')
})
yargs.help()
yargs.strict()
yargs.version()
}
})
parser.parse('!ch uptime', { 'test': 'test' }, (err, argv, output) => {
if (err && !output) throw err
if (output) {
console.log(output)
}
})
parser.parse('!ch dice', { 'test': 'test' }, (err, argv, output) => {
if (err && !output) throw err
if (output) {
console.log(output)
}
}) Gives me:
|
@scriptdaemon ah, that makes sense: strict mode requires that all options observed are known about ... this would work:
It seems like to simplify this use-case though, we should add all keys provided in context to the list of known arguments? |
@scriptdaemon mind opening another issue for this, and I'll fix this in a separate branch. |
@scriptdaemon I think we've addressed the issues you were bumping into in this thread? let me know if there's still anything giving you trouble, and we can open a new issue. |
EDIT: The same error occurs doing anything a second time when using
help()
.Version:
6.6.0
Error:
Code:
Steps to produce:
The text was updated successfully, but these errors were encountered: