From e9979a7f921b877dc5ad86a5a945fb98115b04f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Jim=C3=A9nez=20Pascual?= Date: Thu, 2 Mar 2023 00:18:32 +0100 Subject: [PATCH 1/2] Respect newlines in package comments Closes #358 --- mage/main_test.go | 16 +++++++++++----- parse/parse.go | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/mage/main_test.go b/mage/main_test.go index 07e598e..810e827 100644 --- a/mage/main_test.go +++ b/mage/main_test.go @@ -593,7 +593,9 @@ func TestList(t *testing.T) { } actual := stdout.String() expected := ` -This is a comment on the package which should get turned into output with the list of targets. +This is a comment on the package which should get turned into output with the +list of targets. + Targets: somePig* This is the synopsis for SomePig. @@ -629,7 +631,9 @@ func TestListWithColor(t *testing.T) { os.Setenv(mg.TargetColorEnv, mg.Cyan.String()) expectedPlainText := ` -This is a comment on the package which should get turned into output with the list of targets. +This is a comment on the package which should get turned into output with the +list of targets. + Targets: somePig* This is the synopsis for SomePig. @@ -642,8 +646,8 @@ Targets: // in the middle and join with a normal string for the target names, // otherwise the single backslash would be taken literally and encoded as \\ expectedColorizedText := "" + - "This is a comment on the package which should get turned into output with the list of targets.\n" + - "\n" + + "This is a comment on the package which should get turned into output with the\nlist of targets.\n" + + "\n\n" + "Targets:\n" + " \x1b[36msomePig*\x1b[0m This is the synopsis for SomePig.\n" + " \x1b[36mtestVerbose\x1b[0m \n" + @@ -730,7 +734,9 @@ func TestIgnoreDefault(t *testing.T) { } actual := stdout.String() expected := ` -This is a comment on the package which should get turned into output with the list of targets. +This is a comment on the package which should get turned into output with the +list of targets. + Targets: somePig* This is the synopsis for SomePig. diff --git a/parse/parse.go b/parse/parse.go index 3421669..110a98c 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -247,7 +247,7 @@ func Package(path string, files []string) (*PkgInfo, error) { pi := &PkgInfo{ AstPkg: pkg, DocPkg: p, - Description: toOneLine(p.Doc), + Description: p.Doc, } setNamespaces(pi) From 2728635f350cde8d21ee2badc1149bb59ae7a4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Jim=C3=A9nez=20Pascual?= Date: Thu, 2 Mar 2023 12:35:34 +0100 Subject: [PATCH 2/2] Mimic go doc behaviour --- parse/parse.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parse/parse.go b/parse/parse.go index 110a98c..521e6eb 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -247,7 +247,7 @@ func Package(path string, files []string) (*PkgInfo, error) { pi := &PkgInfo{ AstPkg: pkg, DocPkg: p, - Description: p.Doc, + Description: string(p.Text(p.Doc)), } setNamespaces(pi)