66
77 "github.com/everettraven/synkr/pkg/builtins"
88 "github.com/everettraven/synkr/pkg/engine"
9+ "github.com/everettraven/synkr/pkg/printers"
910 "github.com/spf13/cobra"
1011 "go.starlark.net/starlark"
1112 "go.starlark.net/syntax"
@@ -14,31 +15,42 @@ import (
1415func NewSynkrCommand () * cobra.Command {
1516 eng := & engine.Engine {}
1617 var configFile string
18+ var outputFormat string
1719
1820 cmd := & cobra.Command {
19- Use : "synkr [-c configFile] " ,
21+ Use : "synkr" ,
2022 Short : "synkr is an engine for syncing work items based on a Starlark configuration" ,
2123 Args : cobra .ExactArgs (0 ),
2224 RunE : func (cmd * cobra.Command , args []string ) error {
23- return run (cmd .Context (), eng , configFile )
25+ return run (cmd .Context (), eng , configFile , outputFormat )
2426 },
2527 }
2628
2729 cmd .Flags ().StringVarP (& configFile , "config" , "c" , "synkr.star" , "configures the Starlark file to be processed for configuration" )
30+ cmd .Flags ().StringVarP (& outputFormat , "output" , "o" , "markdown" , "configures the output format. Allowed values are [markdown, json]" )
2831
2932 return cmd
3033}
3134
32- func run (ctx context.Context , eng * engine.Engine , configFile string ) error {
33- thread , err := configureEngine (eng , configFile )
35+ func run (ctx context.Context , eng * engine.Engine , configFile , output string ) error {
36+ thread , err := configureEngine (eng , configFile , output )
3437 if err != nil {
3538 return fmt .Errorf ("configuring engine: %w" , err )
3639 }
3740
3841 return eng .Run (ctx , thread )
3942}
4043
41- func configureEngine (eng * engine.Engine , configFile string ) (* starlark.Thread , error ) {
44+ func configureEngine (eng * engine.Engine , configFile , output string ) (* starlark.Thread , error ) {
45+ switch output {
46+ case "markdown" :
47+ eng .SetPrinter (& printers.Markdown {})
48+ case "json" :
49+ eng .SetPrinter (& printers.JSON {})
50+ default :
51+ return nil , fmt .Errorf ("unknown output format %q" , output )
52+ }
53+
4254 globals := starlark.StringDict {}
4355
4456 builtins .Github (globals , eng )
0 commit comments