Skip to content

Commit

Permalink
Format concept files added (#2566)
Browse files Browse the repository at this point in the history
* Format also concepts

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Added error management for FormatConceptFilesIn

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

* Version update

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>

---------

Signed-off-by: Piotr Nestorow <piotr.nestorow@systemverification.com>
  • Loading branch information
PiotrNestor authored Jan 29, 2025
1 parent aa99220 commit a25e079
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ 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 {
exit(err, cmd.UsageString())
}
loadEnvAndReinitLogger(cmd)
formatter.FormatSpecFilesIn(getSpecsDir(args)[0])
formatter.FormatConceptFilesIn(getSpecsDir(args)[0])
},
DisableAutoGenTag: true,
}
Expand Down
22 changes: 22 additions & 0 deletions formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,25 @@ func FormatSpecFilesIn(filesLocation string) {
os.Exit(1)
}
}

func FormatConceptFilesIn(filesLocation string) {
conceptFiles := util.FindConceptFiles([]string{filesLocation})
conceptsDictionary := gauge.NewConceptDictionary()
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 {
e := common.SaveFile(file, formatted, true)
if e != nil {
logger.Errorf(false, "Concept file save failure: %s", e)
os.Exit(1)
}
}
}
5 changes: 5 additions & 0 deletions util/fileUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a25e079

Please # to comment.