Skip to content

Commit

Permalink
Improving graph plan logging
Browse files Browse the repository at this point in the history
  • Loading branch information
kellrott committed Mar 27, 2024
1 parent 47b6317 commit d93c3ad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
10 changes: 8 additions & 2 deletions cmd/graphplan/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package graphplan

import (
"log"
"path/filepath"

"github.com/bmeg/sifter/graphplan"
"github.com/bmeg/sifter/logger"
"github.com/bmeg/sifter/playbook"
"github.com/spf13/cobra"
)

var outScriptDir = ""
var outDataDir = "./"
var objectExclude = []string{}
var verbose bool = false

// Cmd is the declaration of the command line
var Cmd = &cobra.Command{
Expand All @@ -20,6 +21,10 @@ var Cmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

if verbose {
logger.Init(true, false)
}

scriptPath, _ := filepath.Abs(args[0])

/*
Expand All @@ -44,7 +49,7 @@ var Cmd = &cobra.Command{
&pb, outScriptDir, outDataDir, objectExclude,
)
if err != nil {
log.Printf("Error: %s\n", err)
logger.Error("Parse Error", "error", err)
}
}
}
Expand All @@ -55,6 +60,7 @@ var Cmd = &cobra.Command{

func init() {
flags := Cmd.Flags()
flags.BoolVarP(&verbose, "verbose", "v", verbose, "Verbose logging")
flags.StringVarP(&outScriptDir, "dir", "C", outScriptDir, "Change Directory for script base")
flags.StringVarP(&outDataDir, "out", "o", outDataDir, "Change output Directory")
flags.StringArrayVarP(&objectExclude, "exclude", "x", objectExclude, "Object Exclude")
Expand Down
12 changes: 7 additions & 5 deletions graphplan/build_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package graphplan

import (
"fmt"
"log"
"os"
"path/filepath"
"text/template"

"github.com/bmeg/sifter/evaluate"
"github.com/bmeg/sifter/logger"
"github.com/bmeg/sifter/playbook"
"github.com/bmeg/sifter/task"
)
Expand Down Expand Up @@ -117,21 +117,23 @@ func NewGraphBuild(pb *playbook.Playbook, scriptOutDir, dataDir string, objectEx
}

if len(gb.Objects) > 0 {
log.Printf("Found %d objects", len(gb.Objects))
tmpl, err := template.New("graphscript").Parse(graphScript)
if err != nil {
panic(err)
}

outfile, err := os.Create(filepath.Join(scriptOutDir, fmt.Sprintf("%s.yaml", pb.Name)))
outPath := filepath.Join(scriptOutDir, fmt.Sprintf("%s.yaml", pb.Name))
outfile, err := os.Create(outPath)
if err != nil {
fmt.Printf("Error: %s\n", err)
logger.Error("File Error", "error", err)
}

logger.Info("Summary", "ObjectFound", len(gb.Objects), "outPath", outPath)

err = tmpl.Execute(outfile, gb)
outfile.Close()
if err != nil {
fmt.Printf("Error: %s\n", err)
logger.Error("Template Error", "error", err)
}
}
return nil
Expand Down

0 comments on commit d93c3ad

Please sign in to comment.