From e229ef966285166ad51e965053ab52820e8df006 Mon Sep 17 00:00:00 2001 From: Piotr Nestorow Date: Wed, 3 Jul 2024 16:43:05 +0200 Subject: [PATCH 1/2] Format also concepts Signed-off-by: Piotr Nestorow --- cmd/format.go | 5 +++-- formatter/formatter.go | 10 ++++++++++ util/fileUtils.go | 5 +++++ version/version.go | 2 +- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/format.go b/cmd/format.go index 340680a85..242f001bf 100644 --- a/cmd/format.go +++ b/cmd/format.go @@ -14,8 +14,8 @@ import ( var formatCmd = &cobra.Command{ Use: "format [flags] [args]", - Short: "Formats the specified spec files", - Long: `Formats the specified spec files.`, + Short: "Formats the specified spec and/or concept files", + Long: `Formats the specified spec and/or concept files.`, Example: " gauge format specs/", Run: func(cmd *cobra.Command, args []string) { if err := config.SetProjectRoot(args); err != nil { @@ -23,6 +23,7 @@ var formatCmd = &cobra.Command{ } loadEnvAndReinitLogger(cmd) formatter.FormatSpecFilesIn(getSpecsDir(args)[0]) + formatter.FormatConceptFilesIn(getSpecsDir(args)[0]) }, DisableAutoGenTag: true, } diff --git a/formatter/formatter.go b/formatter/formatter.go index 2d5c7a5fd..6d7fe66eb 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -288,3 +288,13 @@ func FormatSpecFilesIn(filesLocation string) { os.Exit(1) } } + +func FormatConceptFilesIn(filesLocation string) { + conceptFiles := util.FindConceptFiles([]string{filesLocation}) + conceptsDictionary := gauge.NewConceptDictionary() + parser.AddConcepts(conceptFiles, conceptsDictionary) + conceptMap := FormatConcepts(conceptsDictionary) + for file, formatted := range conceptMap { + common.SaveFile(file, formatted, true) + } +} \ No newline at end of file diff --git a/util/fileUtils.go b/util/fileUtils.go index 913f11995..54005ecbc 100644 --- a/util/fileUtils.go +++ b/util/fileUtils.go @@ -193,6 +193,11 @@ func findConceptFiles(paths []string) []string { return conceptFiles } +// Exported (public) function that calls the unexported function +func FindConceptFiles(paths []string) []string { + return findConceptFiles(paths) +} + // GetConceptFiles It returns the list of concept files // It returns concept files from gauge_concepts_dir if present // It returns concept files from projectRoot otherwise diff --git a/version/version.go b/version/version.go index 370ef02e9..7a649b450 100644 --- a/version/version.go +++ b/version/version.go @@ -14,7 +14,7 @@ import ( ) // CurrentGaugeVersion represents the current version of Gauge -var CurrentGaugeVersion = &Version{1, 6, 7} +var CurrentGaugeVersion = &Version{1, 6, 8} // BuildMetadata represents build information of current release (e.g, nightly build information) var BuildMetadata = "" From 4171a21e737adcf9ded43502833f542dc8995ce7 Mon Sep 17 00:00:00 2001 From: Piotr Nestorow Date: Thu, 4 Jul 2024 09:40:21 +0200 Subject: [PATCH 2/2] Added error management for FormatConceptFilesIn Signed-off-by: Piotr Nestorow --- formatter/formatter.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/formatter/formatter.go b/formatter/formatter.go index 6d7fe66eb..e47217100 100644 --- a/formatter/formatter.go +++ b/formatter/formatter.go @@ -292,9 +292,22 @@ func FormatSpecFilesIn(filesLocation string) { func FormatConceptFilesIn(filesLocation string) { conceptFiles := util.FindConceptFiles([]string{filesLocation}) conceptsDictionary := gauge.NewConceptDictionary() - parser.AddConcepts(conceptFiles, conceptsDictionary) + if _, errs, e := parser.AddConcepts(conceptFiles, conceptsDictionary); len(errs) > 0 { + for _, err := range errs { + logger.Errorf(false, "Concept parse failure: %s %s", conceptFiles[0], err) + } + if e != nil { + logger.Errorf(false, "Concept failure: %s %s", conceptFiles[0], e) + os.Exit(1) + } + } conceptMap := FormatConcepts(conceptsDictionary) for file, formatted := range conceptMap { - common.SaveFile(file, formatted, true) + e := common.SaveFile(file, formatted, true) + if e != nil { + logger.Errorf(false, "Concept file save failure: %s", e) + os.Exit(1) + } + } } \ No newline at end of file