just icon indicating copy to clipboard operation
just copied to clipboard

Hyphenated option is not supported (needs docs)

Open fadzlan opened this issue 6 years ago • 7 comments

Lets say we have the following file

const { task, option, logger, argv } = require('just-task');
const { spawn } = require('child_process');

option('no-cache', { default: false });

task('sayhello', function() {
  logger.info(argv());
});

and we were to run npx just sayhello --no-cache, we will got the following result

[4:17:16 PM] ■ started 'sayhello'
[4:17:16 PM] ■ { _: [ 'sayhello' ],
  cache: false,
  'no-cache': false,
  noCache: false,
  '$0': 'node_modules/.bin/just' }
[4:17:16 PM] ■ finished 'sayhello' in 0.01s

if we instead run with npx just sayhello --noCache, it will then registers

[4:20:01 PM] ■ started 'sayhello'
[4:20:01 PM] ■ { _: [ 'sayhello' ],
  noCache: true,
  'no-cache': true,
  '$0': 'node_modules/.bin/just' }
[4:20:01 PM] ■ finished 'sayhello' in 0.01s

It seems this is coming from yargs parser on this issue https://github.com/yargs/yargs-parser/issues/92 which since have been solved in the current version.

Would there be plan to update the yargs dependency in the project to the current version?

fadzlan avatar Jul 16 '19 08:07 fadzlan

It's actually that the word "no" has a special meaning in the yargs world. It indicates the opposite of the flag and would result in a false. Maybe try another set of words in your options?

kenotron avatar Jul 31 '19 17:07 kenotron

what about this

$ npx just sayhello --Cache=false

@kenotron thoughts?

anikethsaha avatar Jul 31 '19 17:07 anikethsaha

Well,I have added the following

option('first-name', { default: 'world' });

and ran the following with the result

$ npx just sayhello --first-name
[4:23:00 PM] ■ started 'sayhello'
[4:23:00 PM] ■ { _: [ 'sayhello' ],
  'first-name': true,
  firstName: true,
  'no-cache': false,
  noCache: false,
  '$0': 'node_modules/.bin/just' }
[4:23:00 PM] ■ finished 'sayhello' in 0.01s

so yes, it seems the word no itself has certain significance

fadzlan avatar Aug 02 '19 08:08 fadzlan

Wow, I'm running into the same issue. My options is called no-fork. If I change it to xy-fork it works. no seems to have a special meaning that interferes with the parsing.

sorenlouv avatar Aug 07 '19 17:08 sorenlouv

yeah, this is the same rule as what yargs provides. You can look at what all the options allowed are: http://yargs.js.org/docs/#api-optionkey-opt

I need to document this :P

kenotron avatar Aug 18 '19 17:08 kenotron

Documentation needed (reopened)

kenotron avatar Aug 18 '19 17:08 kenotron

Issues seem to have gone stale.

github-actions[bot] avatar Mar 08 '20 00:03 github-actions[bot]