Skip to content

Feature/better help output for negated options#104

Open
joaotavora wants to merge 2 commits intocacjs:mainfrom
joaotavora:feature/better-help-output-for-negated-options
Open

Feature/better help output for negated options#104
joaotavora wants to merge 2 commits intocacjs:mainfrom
joaotavora:feature/better-help-output-for-negated-options

Conversation

@joaotavora
Copy link
Copy Markdown

Two commits here. The first is completely orthogonal to this, you can skip it, but I couldn't resist.

The second one implements the idea briefly discussed. I added a test. See the commit messages for details.

By the way, you have some very intrusive git hooks setup. Whenever I do a commit, it takes 7 seconds to run the tests. Plus, something in the hooks runs a some kind of process behind the scenes that substantially reformat the whole file, changing my commit, including parts of the file I didn't even touch. I do not want to author those formatting changes (at least not as a part of this PR). It's totally fine to want a certain formatting, but IMO it's a bad idea to attribute those to people wanting to add specific features or fix specific bugs. Just my opinion.

Even doing a rebase to get rid of them was complicated, I had to completely wipe out .git/hooks to be able to function properly.

Other than that, fantastic nifty little project you have here, congratulations!

Probably doesn't make any practical difference, since this is only
used for the Command array, but less lines of code :-)

* src/utils.ts (findLongest)
Not only doesn't show the `(default: true)` for negated options, which
was quite confusing, but merges them with the line describing the
affirmative case.

Added a new test.  Since it relies on help output, it is a bit
brittle, like the other "snapshot"-based ones.  I didn't the same
execa snapshot for this because it would make a test take a lot longer
to run (becasue spawns a process).

* README.md (Options): Mention [no-]foo syntax.

* src/Command.ts (outputHelp): Consider options with negated
counterparts when printing.

* src/__test__/index.test.ts ('negated option help output'): New test.
if (o.negated) return 0
const l = o.rawName.length
// '5' is the length of '[no-]'. As to the 1, I have no clue...
return negatedOpts[o.name] ? l + 5 + 1 : l
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to add 1 then?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's needed, but I don't know why :-D Try taking it out. It didn't work when I tested...

Copy link
Copy Markdown
Author

@joaotavora joaotavora Feb 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you take out the 1, not sure if the unit test will show the bug, but if you hand-test with some affirmative and negated options you'll see it, I think.

I understand that adding a "mysterious 1" to your codebase is silly. If you want I'll investigate the real reason, and type that into the comment.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, a failing test would be nice.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants