Skip to content
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

Adds sort to command usage help output #1256

Merged
merged 28 commits into from Feb 1, 2019

Conversation

trevorlinton
Copy link
Contributor

When showing the usage (if no command is available) the order of commands isn't sorted, this might be a undesirable and could be put into a config setting, but I'd like to see the tolerance to default to sorted rather than as-defined.

@bcoe
Copy link
Member

bcoe commented Dec 19, 2018

@trevorlinton the nice thing about not applying sorting, is folks can control the ordering of commands by definition order.

my concern with this change is it would break a lot of downstream consumers of yargs, and would need to be a breaking change; and I feel we'd need to then introduce an API method that allowed people to control the sorting of commands (as they'd now always be sorted, and folks might be picky).

@boneskull any opinion?

@trevorlinton
Copy link
Contributor Author

can I add it as an optional config (disabled by default?) the particular issue I'm under is I don't have control with the timing when new commands are registered, so the ordering can at times be random.

@bcoe
Copy link
Member

bcoe commented Dec 19, 2018

@trevorlinton that's an interesting requirement; I'd be open to this, I've been chatting with @cspotcode about adding the ability to configure compiler settings with a flag like .yargsConfig which would pass config to the yargs-parser; what if we allowed certain yargs settings in the non-parser layer to be configured with this too, e.g., sort-commands which defaults to false.

FYI, I think you can use String.localeCompare() to perform the sortinng.

lib/usage.js Outdated Show resolved Hide resolved
yargs.js Outdated Show resolved Hide resolved
lib/usage.js Outdated Show resolved Hide resolved
@bcoe
Copy link
Member

bcoe commented Jan 28, 2019

@trevorlinton see #1262, I'm comfortable with sort-commands being a configuration option that can be passed to yargs via parserConfiguration.

@trevorlinton
Copy link
Contributor Author

@evocateur @bcoe I added in the sort-commands based on the work done in #1262 is there a common branch I can do a PR/rebase into on yargs? otherwise I'm going to be pulling in all the commits/changes from #1262 and our merges become very similar (or, alternatively, merge #1262 first and leave this be until then).

@bcoe
Copy link
Member

bcoe commented Jan 28, 2019

@trevorlinton I'll get #1262 landed ASAP, and then you can rebase against master 👍

Copy link
Contributor

@evocateur evocateur left a comment

Choose a reason for hiding this comment

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

LGTM pending rebase

bcoe added a commit that referenced this pull request Jan 30, 2019
@bcoe
Copy link
Member

bcoe commented Jan 30, 2019

@trevorlinton thanks for your patience, if you don't mind rebasing I'll give this a final review 👍

one note, we'll want to make sure we document the new API method configuration options appropriately.

@trevorlinton
Copy link
Contributor Author

@bcoe I've rebased on master, you can review the file changes, it may be prudent to squash this merge considering all of the conflicts/rebasing that occurred by merging in a unmerged PR and diverging. I've added some notes in api.md on the config option, but I'm not sure how we should document this properly, I'm hoping what's there is good enough or now.

Copy link
Member

@bcoe bcoe left a comment

Choose a reason for hiding this comment

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

This is looking great 👍 just a few minor requests for edits.

Thank you for taking this work on.

docs/api.md Outdated
@@ -1151,8 +1151,13 @@ for details of this object

<a name="parserConfiguration"></a>.parserConfiguration(obj)
------------
`parserConfiguration()` allows you to configure yargs. See [yargs-parser's configuration](https://github.com/yargs/yargs-parser#configuration) for
settings specific to `yargs-parser`.
`parserConfiguration()` allows you to configure yargs-parser.
Copy link
Member

Choose a reason for hiding this comment

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

let's make this:

"parserConfiguration() allows you to configure advanced yargs features:"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

docs/api.md Outdated
settings specific to `yargs-parser`.
`parserConfiguration()` allows you to configure yargs-parser.

An object of options should be passed in.
Copy link
Member

Choose a reason for hiding this comment

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

let's change this to:

obj accepts the following configuration options:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@trevorlinton
Copy link
Contributor Author

@bcoe I've made the changes to the docs requested.

@bcoe bcoe merged commit 6916ce9 into yargs:master Feb 1, 2019
@bcoe
Copy link
Member

bcoe commented Feb 1, 2019

@trevorlinton 👍 thank you; I'm excited that we now have a way to configure edge-case output options for folks (just like we do with the parser).

@trevorlinton trevorlinton deleted the sort-command-usage branch February 1, 2019 19:18
@bcoe
Copy link
Member

bcoe commented Feb 2, 2019

@trevorlinton please try:

npm i yargs@next

and let me know if it does the trick for you.

@bcoe
Copy link
Member

bcoe commented Feb 12, 2019

this is now available in yargs@13.1.0.

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.

None yet

4 participants