Skip to content

Commit

Permalink
add --render-path flag for entropy render
Browse files Browse the repository at this point in the history
  • Loading branch information
gabotechs committed Feb 10, 2024
1 parent 246c3b2 commit 723b954
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cmd/entropy.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

var noBrowserOpen bool
var enableGui bool
var renderPath string

func EntropyCmd() *cobra.Command {
cmd := &cobra.Command{
Expand Down Expand Up @@ -37,13 +38,15 @@ func EntropyCmd() *cobra.Command {
NoOpen: noBrowserOpen,
EnableGui: enableGui,
LoadCallbacks: graph.NewStdErrCallbacks[*language.FileInfo](),
RenderPath: renderPath,
})
return err
},
}

cmd.Flags().BoolVar(&noBrowserOpen, "no-browser-open", false, "Disable the automatic browser open while rendering entropy")
cmd.Flags().BoolVar(&enableGui, "enable-gui", false, "Enables a GUI for changing rendering settings")
cmd.Flags().StringVar(&renderPath, "render-path", "", "Sets the output path of the rendered html file")

return cmd
}
8 changes: 7 additions & 1 deletion internal/entropy/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const ReplacePrefix = "const DATA = "
type RenderConfig struct {
NoOpen bool
EnableGui bool
RenderPath string
LoadCallbacks graph.LoadCallbacks[*language.FileInfo]
}

Expand All @@ -35,7 +36,12 @@ func Render(files []string, parser graph.NodeParser[*language.FileInfo], cfg Ren
return err
}
rendered := bytes.ReplaceAll(index, []byte(ToReplace), append([]byte(ReplacePrefix), marshaled...))
temp := filepath.Join(os.TempDir(), "index.html")
var temp string
if cfg.RenderPath != "" {
temp = cfg.RenderPath
} else {
temp = filepath.Join(os.TempDir(), "index.html")
}
err = os.WriteFile(temp, rendered, os.ModePerm)
if err != nil {
return err
Expand Down

0 comments on commit 723b954

Please sign in to comment.