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

FEATURE: Introduce --help flag option for existing CLI commands #3367

Merged
merged 4 commits into from
Nov 4, 2024

Conversation

crydotsnake
Copy link
Member

Upgrade instructions

None

Review instructions

This change introduces a new way of using the help function for existing Flow/Neos CLI commands.

Currently you always used:

./flow help user:create

With this change it is possible to use the new --help flag as an alternative at the end of a CLI command:

./flow user:create --help

But of course the first way will also still work!

Demo

336868613-915b3726-15bc-477a-aa53-d61682f04836.mov

Checklist

  • Code follows the PSR-2 coding style
  • Tests have been created, run and adjusted as needed
  • The PR is created against the lowest maintained branch
  • Reviewer - PR Title is brief but complete and starts with FEATURE|TASK|BUGFIX
  • Reviewer - The first section explains the change briefly for change-logs
  • Reviewer - Breaking Changes are marked with !!! and have upgrade-instructions

@crydotsnake
Copy link
Member Author

crydotsnake commented Jun 11, 2024

Open TODOs

I'm still thinking about if i could implement this better.

Also i still have to think about how to improve the description for the --help flag. Because it is not even with the other options. It looks different because the description for the --help attribute is implemented in the HelpCommandController. And not like the others directly in the method signature.

WindowsTerminal_48GwdZh4d2

And also the tests needs to be adjusted.

@crydotsnake crydotsnake changed the title FEATURE: Introduce help flag option for existing CLI commands FEATURE: Introduce --help flag option for existing CLI commands Jun 11, 2024
@crydotsnake crydotsnake changed the base branch from 8.3 to 8.4 June 14, 2024 13:39
@jonnitto
Copy link
Member

As it is not possible to combine --help with other options, I would remove the description.

@@ -118,6 +118,14 @@ public function build($commandLine): Request
$request = new Request();
$request->setControllerObjectName(HelpCommandController::class);

// @TODO: Can this be implemented even better/cleaner?
Copy link
Member

Choose a reason for hiding this comment

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

I don't really see how, AFAIK we do not have a concept for such global things, but I'd say whatever next thing we want to implement that is global (-v(v(v)) maybe???) we can then think about a better structure.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree

Copy link
Member

@kitsunet kitsunet left a comment

Choose a reason for hiding this comment

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

I like it, pretty simple really, I would approve but wonder if we shouldn't safeguard users who actually used help as argument in their command because that would be pretty breaking for them.

@crydotsnake
Copy link
Member Author

but wonder if we shouldn't safeguard users who actually used help as argument in their command because that would be pretty breaking for them.

Good point! i havent thought about this so far.. How could we best do this?

@crydotsnake
Copy link
Member Author

but wonder if we shouldn't safeguard users who actually used help as argument in their command because that would be pretty breaking for them.

@kitsunet Do you maybe have an idea, how we could solve this the best way?

@crydotsnake crydotsnake marked this pull request as ready for review September 1, 2024 16:40
@dlubitz
Copy link
Contributor

dlubitz commented Sep 2, 2024

I think @kitsunet is right and we can't provide safely this global flag without potentially breaking dedicated help arguments of the commands.

Comment on lines 121 to 126
if (is_array($commandLine) && in_array('--help', $commandLine, true)) {
$request->setControllerCommandName('help');
$request->setArguments(['commandIdentifier' => $commandLine[0]]);
$request->setControllerObjectName(HelpCommandController::class);
return $request;
}
Copy link
Member

@mhsdesign mhsdesign Sep 2, 2024

Choose a reason for hiding this comment

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

i would put this logic at below line 155 of $commandIdentifier so we can use this variable and also use $rawCommandLineArguments meaning we support the $commandLine being a string possibly.

Also the case flow --help will with this implementation result in an error as there is no command id named --help. The general help should be shown i suppose.

In the end this will make --help an reserved argument and we have to agree on that (which is likely but still breaking? so !!!?)

Also this raw lookup against --help seems a little hacky. Like flow does support this short notation of boolean parameters but --help=true or --help=false are technically possible and will now still end up being passed to the final controller do we want that?

Copy link
Member Author

Choose a reason for hiding this comment

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

i would put this logic at below line 155 of $commandIdentifier so we can use this variable and also use $rawCommandLineArguments meaning we support the $commandLine being a string possibly.

So my check should also check if $rawCommandLineArguments is a string? Dont fully understand what you mean.

Also the case flow --help will with this implementation result in an error as there is no command id named --help. The general help should be shown i suppose.

100%. Is there a way to trigger the default flow help via PHP?

@bwaidelich
Copy link
Member

Thanks for this contribution. This is a feature that I'm missing forever. It's small, but it really enhances UX.

If you're concerned about existing commands with a --help argument we could target 9.0.
But maybe we can easily detect these cases and ignore the global flag for those?

Lastly, I agree to @mhsdesign's comments about the check against --help – but personally I would be OK with that if the choice is hacky but working or not at all :)

@crydotsnake
Copy link
Member Author

crydotsnake commented Sep 5, 2024

Thanks for this contribution. This is a feature that I'm missing forever. It's small, but it really enhances UX.

If you're concerned about existing commands with a --help argument we could target 9.0. But maybe we can easily detect these cases and ignore the global flag for those?

Lastly, I agree to @mhsdesign's comments about the check against --help – but personally I would be OK with that if the choice is hacky but working or not at all :)

But maybe we can easily detect these cases and ignore the global flag for those?

Yes, that would be awesome. As i think this is really a good improvement.

@robertlemke
Copy link
Member

I wonder if there's actually any Flow application out there which implemented its own --help argument. And even if there is, I think it would be totally fine if this new feature would just override the custom implementation and that's it. It shouldn't cause an error, but I personally would be totally fine, if the custom argument implementation would just be ignored.

In that sense, what's missing to get this into 8.4? I'd love to have it in soon, so we can making plans for a release.

@mhsdesign
Copy link
Member

Yeah sorry i didnt meant to side track it with asking what happens if --help is a real argument.

In the end this will make --help an reserved argument and we have to agree on that (which is likely but still breaking? so !!!?)

But by that i was just trying to make a point that some things are not thought out yet ^^

i would put this logic at below line 155 of $commandIdentifier so we can use this variable and also use $rawCommandLineArguments meaning we support the $commandLine being a string possibly.

Also the case flow --help will with this implementation result in an error as there is no command id named --help. The general help should be shown i suppose.

...

Also this raw lookup against --help seems a little hacky. Like flow does support this short notation of boolean parameters but --help=true or --help=false are technically possible and will now still end up being passed to the final controller do we want that?

And the other points are still valid imo and have not been tackled.

- allows `flow --help`
- restricts that no command controller uses `$help` as custom option
- remove duplicate set `HelpCommandController`
- centralise $firstArgument "parsing"
- respect that $commandLine could be a string

Does not handle `flow cache:list --help=true` as this might be bungus
Copy link
Member

@robertlemke robertlemke left a comment

Choose a reason for hiding this comment

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

Generally fine, but the "--help" help text doesn't fit well into the rest of the description, because there's no indentation:

image

I'll push a fix in a minute ...

@robertlemke
Copy link
Member

It now adds the following at the bottom of the general help screen (list of commands):
image

And the command-specific help looks like this:
image

Let's merge this?

Copy link
Member

@mhsdesign mhsdesign left a comment

Choose a reason for hiding this comment

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

btw in b9fc7ea i also adjusted a few things earlier:

  • allows flow --help
  • restricts that no command controller uses $help as custom option
  • remove duplicate set HelpCommandController
  • centralise $firstArgument "parsing"
  • respect that $commandLine could be a string

Does not handle flow cache:list --help=true as this might be bungus :D

... so definitely +1 and tested this ... and if youre all okay with my RuntimeException('The option --help is reserved ...') then lets have it :)

Neos.Flow/Classes/Cli/RequestBuilder.php Show resolved Hide resolved
@robertlemke robertlemke merged commit 99c3682 into neos:8.4 Nov 4, 2024
7 checks passed
@crydotsnake
Copy link
Member Author

Thanks u both! @mhsdesign @robertlemke ❤️ Sorry i havent continue working on that 😅

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

Successfully merging this pull request may close these issues.

7 participants