{"action":"created","issue":{"url":"https://api.github.com/repos/bcoe/yargs/issues/345","labels_url":"https://api.github.com/repos/bcoe/yargs/issues/345/labels{/name}","comments_url":"https://api.github.com/repos/bcoe/yargs/issues/345/comments","events_url":"https://api.github.com/repos/bcoe/yargs/issues/345/events","html_url":"https://github.com/bcoe/yargs/issues/345","id":125891744,"number":345,"title":"parse boolean argument wrong","user":{"login":"kerryChen95","id":1589388,"avatar_url":"https://avatars.githubusercontent.com/u/1589388?v=3","gravatar_id":"","url":"https://api.github.com/users/kerryChen95","html_url":"https://github.com/kerryChen95","followers_url":"https://api.github.com/users/kerryChen95/followers","following_url":"https://api.github.com/users/kerryChen95/following{/other_user}","gists_url":"https://api.github.com/users/kerryChen95/gists{/gist_id}","starred_url":"https://api.github.com/users/kerryChen95/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kerryChen95/subscriptions","organizations_url":"https://api.github.com/users/kerryChen95/orgs","repos_url":"https://api.github.com/users/kerryChen95/repos","events_url":"https://api.github.com/users/kerryChen95/events{/privacy}","received_events_url":"https://api.github.com/users/kerryChen95/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2016-01-11T08:07:47Z","updated_at":"2016-01-14T16:09:33Z","closed_at":null,"body":"build.js:\r\n```\r\nlet argv = require('yargs')\r\n  .options({\r\n    noWatch: {\r\n      demand: false,\r\n      default: false,\r\n      type: 'boolean',\r\n    },\r\n  })\r\n  .argv\r\n\r\nconsole.log('argv.noWatch: ' + argv.noWatch)\r\nconsole.log('argv[\"no-watch\"]: ' + argv['no-watch'])\r\nconsole.log('argv.watch: ' + argv.watch)\r\n```\r\n\r\n---\r\n\r\n```\r\n$ node build --no-watch\r\nargv.noWatch: false\r\nargv[\"no-watch\"]: undefined\r\nargv.watch: false\r\n```\r\nI think `argv.noWatch` should be true, `argv[\"no-watch\"]` should be true, isn't it?\r\n\r\n---\r\n```\r\n$ node build --noWatch\r\nargv.noWatch: true\r\nargv[\"no-watch\"]: undefined\r\nargv.watch: undefined\r\n```\r\nI think `argv[\"no-watch\"]` should be true, `argv.watch` should be false, or `argv.watch` is undefined for both commands `node build --no-watch` and `node build --noWatch` \r\n\r\n---\r\nVersion info:\r\nyargs@3.31.0\r\nnode@v4.2.2"},"comment":{"url":"https://api.github.com/repos/bcoe/yargs/issues/comments/171685089","html_url":"https://github.com/bcoe/yargs/issues/345#issuecomment-171685089","issue_url":"https://api.github.com/repos/bcoe/yargs/issues/345","id":171685089,"user":{"login":"maxrimue","id":7421183,"avatar_url":"https://avatars.githubusercontent.com/u/7421183?v=3","gravatar_id":"","url":"https://api.github.com/users/maxrimue","html_url":"https://github.com/maxrimue","followers_url":"https://api.github.com/users/maxrimue/followers","following_url":"https://api.github.com/users/maxrimue/following{/other_user}","gists_url":"https://api.github.com/users/maxrimue/gists{/gist_id}","starred_url":"https://api.github.com/users/maxrimue/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maxrimue/subscriptions","organizations_url":"https://api.github.com/users/maxrimue/orgs","repos_url":"https://api.github.com/users/maxrimue/repos","events_url":"https://api.github.com/users/maxrimue/events{/privacy}","received_events_url":"https://api.github.com/users/maxrimue/received_events","type":"User","site_admin":false},"created_at":"2016-01-14T16:09:33Z","updated_at":"2016-01-14T16:09:33Z","body":"@kerryChen95 yargs does support option names like `some-option`, here, we only have the problem that your option's name starts with `no`, which makes yargs parse as I describe above. Usually, you can also apply aliases to options, say you have an option called `some-option` and also want to support the name `someOption`, you could write code like this:\r\n```javascript\r\nlet argv = require('yargs')\r\n  .options({\r\n    someOption: {\r\n      alias: 'some-option',\r\n      type: 'boolean' //Could be any type\r\n    },\r\n  })\r\n  .argv\r\n```\r\nNow, both of these commands would make both `argv['some-option']` and `argv['someOption`] equal to `true`:\r\n```shell\r\nnode build --some-option\r\n```\r\nand\r\n```shell\r\nnode build --someOption\r\n```   \r\n   \r\nThe only problem you would have is that the name `no-watch` starts with `no`, so you would have to type `--no-watch`, which means yargs would parse it as `watch = false` again. I would recommend you to use @bcoe's code:\r\n```javascript\r\nlet argv = require('yargs')\r\n  .options({\r\n    watch: {\r\n      default: true,\r\n      type: 'boolean'\r\n    },\r\n  })\r\n  .argv\r\n``` \r\nThis way, if you type:\r\n```shell\r\nnode build --no-watch\r\n```\r\n`argv['watch']` will equal `false`, and if you don't add `--no-watch` to the command, `argv['watch']` will equal `true`. Does this solve your issue?"}}