mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 14:14:17 +00:00
Pass writer to executeArg to make code easier to test
This commit is contained in:
parent
b7304db99e
commit
85c0cde9c7
1 changed files with 4 additions and 4 deletions
8
main.go
8
main.go
|
@ -102,18 +102,18 @@ func readerFromArg(s string) (*Source, error) {
|
|||
|
||||
func execute(cmd *cobra.Command, args []string) error {
|
||||
if len(args) == 0 {
|
||||
return executeArg(cmd, "")
|
||||
return executeArg(cmd, "", os.Stdout)
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
if err := executeArg(cmd, arg); err != nil {
|
||||
if err := executeArg(cmd, arg, os.Stdout); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func executeArg(cmd *cobra.Command, arg string) error {
|
||||
func executeArg(cmd *cobra.Command, arg string, w io.Writer) error {
|
||||
// create an io.Reader from the markdown source in cli-args
|
||||
src, err := readerFromArg(arg)
|
||||
if err != nil {
|
||||
|
@ -180,7 +180,7 @@ func executeArg(cmd *cobra.Command, arg string) error {
|
|||
return c.Run()
|
||||
}
|
||||
|
||||
fmt.Print(content)
|
||||
fmt.Fprint(w, content)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue