-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.go
50 lines (43 loc) · 1003 Bytes
/
util.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
47
48
49
50
package snippets
import (
"log"
"github.com/blufor/glsnip/sources"
"github.com/spf13/viper"
gitlab "github.com/xanzy/go-gitlab"
)
// Reads the configured sources and presents them as the API
// request types.
//
func gatherData(src []sources.Source) (snips []*gitlab.SnippetFile) {
for _, f := range src {
path := f.Path()
content, err := f.Content()
if err != nil {
log.Printf("Failed to read content from %s: %v", path, err)
continue
}
err = f.Close()
if err != nil {
log.Printf("Failed to close the file %s: %v", path, err)
continue
}
snips = append(snips, &gitlab.SnippetFile{
FilePath: &path,
Content: &content,
})
}
return
}
// Translates CLI options to the `gitlab.VisibilityValue`
// interface types.
//
func visibility(c *viper.Viper) gitlab.VisibilityValue {
switch {
case c.GetBool("internal"):
return gitlab.InternalVisibility
case c.GetBool("public"):
return gitlab.PublicVisibility
default:
return gitlab.PrivateVisibility
}
}