-
Notifications
You must be signed in to change notification settings - Fork 0
/
repository_format.go
46 lines (37 loc) · 921 Bytes
/
repository_format.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package view
import (
"encoding/json"
"fmt"
"io"
"github.com/kyoh86/gogh/v2"
)
type RepositoryPrinter interface {
Print(p gogh.Repository) error
Close() error
}
type RepositoryFuncPrinter func(gogh.Repository) error
func (f RepositoryFuncPrinter) Print(r gogh.Repository) error {
return f(r)
}
func (f RepositoryFuncPrinter) Close() error {
return nil
}
func NewRepositorySpecPrinter(w io.Writer) RepositoryPrinter {
return RepositoryFuncPrinter(func(r gogh.Repository) error {
fmt.Fprintln(w, r.Spec.String())
return nil
})
}
func NewRepositoryURLPrinter(w io.Writer) RepositoryPrinter {
return RepositoryFuncPrinter(func(r gogh.Repository) error {
fmt.Fprintln(w, r.URL)
return nil
})
}
func NewRepositoryJSONPrinter(w io.Writer) RepositoryPrinter {
return RepositoryFuncPrinter(func(r gogh.Repository) error {
buf, _ := json.Marshal(r)
fmt.Fprintln(w, string(buf))
return nil
})
}