question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Boolean flags override even when not specified

See original GitHub issue

When Yargs defaults are specified, they provide the value as flags to the command constructor. This means that when flags, command overrides, lerna json options and legacy options are merged, the flags will take precedence over any thing else because they have a value.

This can easily be reproduced by simply trying to use stream: true in the lerna.json. If you remove the option from, for example, RunCommand it works. Similarly, if you rename it from boolean to string, it continues to work. So it seems that while _.defaults() is doing the right thing (because false is a value, where undefined is not), providing a default that is considered a “value”, will break anything following the durable option convention.

Expected Behavior

Durable options should take precedence over Yargs defaults.

Current Behavior

Defaults override user-defined values not specified as flags.

Possible Solution

After digging a bit deeper, it seems that all we really have to do to get around this is to specify default: undefined to any option that is a boolean and doesn’t already have a default (because they default to false. When _.defaults() is called, they will then be overridden if they’re not specified by the user.

Steps to Reproduce

  1. Put stream: true in the lerna.json
  2. Run a command that should stream.
  3. It won’t stream.

Context

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
treshugartcommented, Jun 26, 2017

Wrote a test to confirm:

it("should prefer durable options over yargs defaults", () => {
  // yargs does this when default values are specified
  const instance = new TestBCommand([], {
    testOption: false,
    testOption2: 1
  }, testDir);
  expect(instance.options.testOption).toBe("b");
  expect(instance.options.testOption2).toBe("b");
});
0reactions
lock[bot]commented, Dec 28, 2018

This thread has been automatically locked because there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow boolean literals as values for flags · Issue #1649 - GitHub
Here is my suggestion for how to parse boolean flags: ... With clap 3.2, you can now override the bool behavior with #[clap(action...
Read more >
launching Activity only once(First app use) Using Boolean flags
In your Activity @Override protected void onResume() { super.onResume(); if (SettingsManager.getBoolean(this, SettingsManager.
Read more >
CommandLine 2.0 Library Manual - Documentation - LLVM
Powerful: The CommandLine library supports many different types of arguments, from simple boolean flags to scalars arguments (strings, integers, enums, ...
Read more >
View - Android Developers
To implement a custom view, you will usually begin by providing overrides for some of the standard methods that the framework calls on...
Read more >
abseil / The Abseil Flags Library
We refer to this flag type as an “optional flag.” An optional flag is either “valueless”, holding no value of type T (indicating...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found