-
-
Notifications
You must be signed in to change notification settings - Fork 580
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
Add the option to add flags to custom commands, fixes #2491 #2493
Conversation
c3cf910
to
f3fde92
Compare
The failure in CircleCI is in https://app.circleci.com/pipelines/github/drud/ddev/2744/workflows/36fa626d-ad99-4c90-a739-670728b3ab85/jobs/27496 - You can run |
Yeah thanks! I've added more go extensions to VS Code which should also solve this issue :) |
@rfay examples to test the flags can be found in the tests as starting point |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor change requests.
Have you looked at the performance impact at all? ddev is already doing way too much with these commands every time ddev is executed, which is already worrisome.
I do see a persistent failure, didn't debug it, it's the fail that's breaking the tests:
Error 'invalid character '[' looking for beginning of object key string', command 'test' contains an invalid flags definition '{[{"Name":"test","Shorthand":"t","Usage":"Usage of test"}]', skipping add flags of /Users/rfay/workspace/d9composer/.ddev/.global_commands/web/test
No, I did not. But saw this behavior during the development which is really not so nice. I have an idea how we can improve this situation but I first have to check if this works at all. Should be done in a next or prior change imho.
Should be fixed now. |
I created this global web command named "test"
But
|
I did the same like you and get this expectet output:
There is a error in the JSON, the starting
Did you really not get an error message like me? That would mean you somehow use the wrong binary... BTW I've tested with project and global commands, same result. |
OK. I took that from https://github.com/gilbertsoft/ddev/blob/21082e1b30b802728df129530884dd182b16f600/cmd/ddev/cmd/testdata/TestCustomCommands/project_commands/host/testhostcmdflags#L5, and I must have messed it up somehow. I'm not entirely sure that people will be comfortable with json here but I'm OK to go with it. I'll take another look when the tests pass. |
Yeah, this one was buggy and made the tests failing :(
I'm open for other ideas here but it seems to be the easiest. And nowadays people should be able to write such simple JSON. To support less experienced people I added the whole validation thing which outputs as clear as possible error messages for user misstakes... That's why I'm wondering you did not see / post the error message which should have pointed you to the wrong JSON definition yesterday. |
Two good and working examples can be found here: |
Those links aren't helpful, sorry. Must be a copy/paste problem? Please link to code in your fork rather than to a files diff in PR. Here's what https://github.com/drud/ddev/pull/2493/files#diff-8d9431d2887832d2de5cfd81bbfe6495R48 results in: |
Links are fine but the browser jumps here to the wrong line. Here the two examples I'd like to show you:
The annotation in the second one is not useful, it was meant for testing only. But the enhanced docs have a link to spf13 where this is explained if you like to test it. It's for autocompletion only so not so imortant in the first place but I thought if somebody likes to use it e.g. to define possible file extensions for a file name paramter... |
|
||
#### Flags | ||
|
||
`Flags` is used for the help message. All defined flags here are listed with their shorthand if available. It has to be encoded according the following definition: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a bit stronger. I know you're planning another PR or two, so let's not delay this one, but when you next work on commands, let's make this say something like "THIS DOES NOT DEFINE THE FLAG HANDLING, ONLY WHAT COMES OUT IN THE HELP"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, agree...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good! Thanks for all the great work on this.
The Problem/Issue/Bug:
More and more bundled custom commands are providing flags but there is not option to describe this flags in the custom command using the cobra definition which prints the flags for a command.
How this PR Solves The Problem:
A new option Flags is recognized now to describe the flags with a JSON comment in the custom command.
Example:
## Flags: [{"Name":"test","Shorthand":"t","Usage":"Usage of test"}]
The Shorthand is optional and can be omitted.
Manual Testing Instructions:
Create a new custom command and add a flags definition to the comment header see above or the detailed explanation in the docs.
Automated Testing Overview:
The provided tests fully cover all cases including errors and panics.
Related Issue Link(s):
Closes #2491
Release/Deployment notes:
Nothing special is needed.