Skip to content

Conversation

@rossiam
Copy link
Collaborator

@rossiam rossiam commented Nov 10, 2025

First of two parts for adding topic and sub-command help to each command's help.

This PR adds:

  • adds a command-util module to help get topic and sub-command information for a given command.
  • adds a help module:
    • takes over code generating API docs notes
    • also moved itemInputHelpText here which generates help for use with the item-input module
    • added a new buildEpilog which will build an epilog for use with yargs' .epilog which supports a variety of things we like to put in the help output
  • converts a handful of commands to use buildEpilog

The second part of this will:

  • convert the remaining commands to use buildEpilog
  • remove the leftover code in the api-command module

@rossiam rossiam requested a review from a team November 10, 2025 19:23
@changeset-bot
Copy link

changeset-bot bot commented Nov 10, 2025

⚠️ No Changeset found

Latest commit: 1e27610

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

'create an invite from prompted input for the specified channel',
],
])
.epilog(buildEpilog({ command }))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is an example of a command that doesn't strictly need an update. Since it's a leaf command and doesn't use any notes or have any API docs, this effectively does nothing. (The buildEpilog function in this case returns an empty string which yargs is happy to ignore, or maybe it appends it, either having the same effect. 😄)

I'm kind of leaning towards including this in even these cases but I could be convinced otherwise. The main reason to add it would be that if we don't and a command gets sub-commands added, we will have to remember to update the parent command with an epilog.

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with including it even in cases like this, mostly for the reason you mentioned but also to keep everything consistent.


it('returns direct, and only direct, sub-commands and topics for devices', () => {
const result = findTopicsAndSubcommands('devices')
expect(result.topics).toStrictEqual(['devices::history'])
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this line useful given the line below that tests for strictEqual of the whole thing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It is not. That was leftover from when I was debugging broken tests and I forgot to remove it. Fixed now.

})

it('includes note from formattedNotes', () => {
expect(buildEpilog({ command: 'test', formattedNotes: 'formatted node' })).toBe('Notes:\nformatted node')
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't matter, of course, but "node" or "note"?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It matters to me! Fixed.

findTopicsAndSubcommandsMock.mockReturnValueOnce({ topics: ['test::topic'], subCommands: [] })

expect(buildEpilog({ command: 'test', formattedNotes: 'formatted node' }))
.toBe('Notes:\nformatted node\n\nTopics:\n test::topic')
Copy link
Contributor

Choose a reason for hiding this comment

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

Note/node here too

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed here too.

'create an invite from prompted input for the specified channel',
],
])
.epilog(buildEpilog({ command }))
Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with including it even in cases like this, mostly for the reason you mentioned but also to keep everything consistent.

@rossiam rossiam merged commit 082dcc3 into SmartThingsCommunity:yargs Nov 11, 2025
4 checks passed
@rossiam rossiam deleted the add-topics-to-help branch November 11, 2025 16:09
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