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
Allow multiline examples for custom commands #2495
Conversation
b3d2197
to
8db5efc
Compare
### Annotations supported | ||
|
||
The custom commands support various annotations in the header which are used to provide additional information about the command to the user: | ||
|
||
* Description | ||
* Usage | ||
* Example (use `\n` to force a line break) | ||
* ProjectTypes | ||
* OSTypes | ||
|
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 whole section will be changed again with #2493 . There I will provide an extended description of all annotations.
c989e47
to
e74029a
Compare
"os" | ||
osexec "os/exec" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
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 change was not really intended but made by the linter of VS Code. And looking at other packages this looks like a best practise to place interal packages on the top and gh imports afterwards.
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.
I always let goland put them where they belong. That's probably what you're seeing.
I doubt you should be using any linter beyond gofmt, which I think also organizes them.
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.
No, gofmt does not organize them as I've seen with my tests. I'm wondering about the difference we have here between your editor and VS Code
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.
Fantastic improvement, thanks! I manually tested and it did great, and the code looks great.
@@ -108,7 +108,7 @@ func addCustomCommands(rootCmd *cobra.Command) error { | |||
usage = val | |||
} | |||
if val, ok := directives["Example"]; ok { | |||
example = val | |||
example = " " + strings.ReplaceAll(val, `\n`, "\n ") |
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.
I wish there was an easier way to do this (for the command writer) but I'm fine with this. It's far easier to parse things as lines than otherwise.
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.
Yeah same thought. There are ways but I guess this is the easiest solution also for the users.
The Problem/Issue/Bug:
Currently the examples section of a custom command does only support a one line description which ends in confusing examples. Examples in multiple line is highly desirable.
How this PR Solves The Problem:
This patch introduces the possibility of using
\n
in the examples to force a line break.Manual Testing Instructions:
Change the examples comment and use
\n
to force a new line and runddev [command] -h
to see the new output.Automated Testing Overview:
The line breaks and fromatting are tested in a new test to avoid regressions.
Related Issue Link(s):
Release/Deployment notes: