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

Allow multiline examples for custom commands #2495

Merged
merged 6 commits into from Sep 16, 2020

Conversation

gilbertsoft
Copy link
Member

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 run ddev [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:

Comment on lines +105 to +114
### 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

Copy link
Member Author

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.

Comment on lines +5 to +11
"os"
osexec "os/exec"
"path/filepath"
"strings"
"testing"
"time"

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

@rfay rfay left a 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 ")
Copy link
Member

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.

Copy link
Member Author

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.

@rfay rfay merged commit 079351f into ddev:master Sep 16, 2020
@gilbertsoft gilbertsoft deleted the multiline-examples branch September 16, 2020 22:24
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.

None yet

2 participants