Skip to content

help: simplify implementation of help subsystem #1139

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

elhimov
Copy link
Contributor

@elhimov elhimov commented Apr 3, 2025

Following changes are applied:

  • the main help command is implemented in a way similar to the other
    commands (choice between internal and external variation of the
    command is handled with the common handler cmd.RunModuleFunc)
  • help for every external command is tied to a command itself over
    cmd.SetHelp function rather than add separate help subcommand to
    the main help command (it allows to obtain help for internal and
    external commands uniformly)
  • corresponding Cobra commands are created for all available external
    commands rather than only for the invoked one (being combined with
    the uniform handling mentioned above it allows to make implementation
    of the internal variation of help command trivial)
  • external commands are also implemented over the common handler
    cmd.RunModuleFunc to reduce code duplication

I didn't forget about:

  • Well-written commit messages (see documentation how to write a commit message)

Related issues:

Closes #1136

@elhimov elhimov added the full-ci Enables full ci tests label Apr 4, 2025
@dmyger
Copy link
Collaborator

dmyger commented Apr 9, 2025

display external commands only in top level help

It was fixed with PR #1132

@elhimov elhimov force-pushed the elhimov/gh-1136-display-external-commands-only-in-top-level-help branch from 6fc697a to a8ce4a8 Compare April 17, 2025 06:22
@elhimov elhimov changed the title help: display external commands only in top level help help: reimplemented help subsytem Apr 17, 2025
@elhimov elhimov force-pushed the elhimov/gh-1136-display-external-commands-only-in-top-level-help branch 2 times, most recently from 85da23c to 5a70d95 Compare April 18, 2025 14:16
@elhimov elhimov marked this pull request as ready for review April 18, 2025 14:16
@elhimov
Copy link
Contributor Author

elhimov commented Apr 18, 2025

display external commands only in top level help

It was fixed with PR #1132

Initially I assumed to solve this task in 2 steps: first refactor help-related code and then fix the mentioned problem. Since the problem part is fixed I adjusted labels to turn bug-task into refactoring-task.

@elhimov elhimov changed the title help: reimplemented help subsytem help: simplify implementation of help subsystem Apr 18, 2025
Copy link
Contributor

@oleg-jukovec oleg-jukovec left a comment

Choose a reason for hiding this comment

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

Для внешнего пользователя что-то изменилось?

@elhimov elhimov force-pushed the elhimov/gh-1136-display-external-commands-only-in-top-level-help branch from 5a70d95 to 623c32e Compare April 21, 2025 12:41
@elhimov
Copy link
Contributor Author

elhimov commented Apr 21, 2025

Для внешнего пользователя что-то изменилось?

Комплишн у хелпа теперь работает и для сложных команд. То есть раньше варианты предлагались только для топ-команд, теперь если набрать tt help replicaset и нажать tab, будут предложены его подкоманды (работает для всех уровней вложенности).

Наверное лучше было бы отдельным реквестом это изменение делать. И по-хорошему подкрепить тестами, чтобы потом регрессий не допускать.

@oleg-jukovec
Copy link
Contributor

Для внешнего пользователя что-то изменилось?

Комплишн у хелпа теперь работает и для сложных команд. То есть раньше варианты предлагались только для топ-команд, теперь если набрать tt help replicaset и нажать tab, будут предложены его подкоманды (работает для всех уровней вложенности).

Наверное лучше было бы отдельным реквестом это изменение делать. И по-хорошему подкрепить тестами, чтобы потом регрессий не допускать.

Давайте тогда отобразим это в CHANGELOG.md.

DisableFlagParsing: true,
}
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
cmd.Print(manifest.Help)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It won't work that way because, now and in the near future: manifest.Help == "".
Need a check, if the manifest.Help string is empty, then call an external command with the --help flag.
But this should only be done when the user has requested help for such external command, without this, all modules should not be asked about this information on every start of tt.

Copy link
Contributor Author

@elhimov elhimov May 5, 2025

Choose a reason for hiding this comment

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

Sorry, but it seems that I'm missing something.
I see following flow now:

modules.GetModulesInfo
    makeManifest()    <- for each discovered module
        readManifest()  or  fillManifest()

readManifest() looks like modern approach and it gets "Help" directly from the manifest file. And according to:

	if mf.Help == "" {
		return mf, fmt.Errorf("help field is mandatory for module Manifest")
	}

"Help" field is mandatory, because any returned error leads to skipping the module.

fillManifest() looks like an approach that provides a kind of backward compatibility. It fills "Help" field by calling external module with --help and it is executed unconditionally for every external module at tt start.

Finally it means that if external module entry exists its Help field is filled properly, so I just use it. Is it wrong or are we going to change this behavior in the nearest future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I've just found that under fillManifest() the corresponding external module is executed with the --description flag, not --help. Anyway it seems we get .Help field from its output, so it confuses me even more )

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea, it does cause a bit of an embarrassment, but that kind of history has been drawn out since the previous revision of the modules.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@elhimov elhimov force-pushed the elhimov/gh-1136-display-external-commands-only-in-top-level-help branch from 623c32e to 9d68797 Compare May 7, 2025 12:18
@elhimov elhimov requested a review from dmyger May 7, 2025 12:19
@elhimov
Copy link
Contributor Author

elhimov commented May 7, 2025

Наверное лучше было бы отдельным реквестом это изменение делать. И по-хорошему подкрепить тестами, чтобы потом регрессий не допускать.

Давайте тогда отобразим это в CHANGELOG.md.

Убрал эти изменения отсюда, сделаю отдельным реквестом.

Following changes are applied:
- the main help command is implemented in a way similar to the other
  commands (choice between internal and external variation of the
  command is handled with the common handler cmd.RunModuleFunc)
- help for every external command is tied to a command itself over
  cmd.SetHelp function rather than add separate help subcommand to
  the main help command (it allows to obtain help for internal and
  external commands uniformly)
- corresponding Cobra commands are created for all available external
  commands rather than only for the invoked one (being combined with
  the uniform handling mentioned above it allows to make implementation
  of the internal variation of help command trivial)
- external commands are also implemented over the common handler
  cmd.RunModuleFunc to reduce code duplication

Close #1136
@elhimov elhimov force-pushed the elhimov/gh-1136-display-external-commands-only-in-top-level-help branch from 9d68797 to c866f03 Compare May 10, 2025 11:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
full-ci Enables full ci tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

help: need to simplify help-related code
4 participants