art: Move ListOutput under utils

This commit is contained in:
Ettore Di Giacinto
2022-08-18 13:14:12 +00:00
committed by Itxaka
parent 212cf5132a
commit 8518a3752e
2 changed files with 21 additions and 18 deletions

View File

@@ -2,7 +2,6 @@ package github
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"log" "log"
"net/http" "net/http"
@@ -10,7 +9,6 @@ import (
"github.com/google/go-github/v40/github" "github.com/google/go-github/v40/github"
"golang.org/x/oauth2" "golang.org/x/oauth2"
"gopkg.in/yaml.v1"
) )
func newHTTPClient(ctx context.Context, token string) *http.Client { func newHTTPClient(ctx context.Context, token string) *http.Client {
@@ -49,19 +47,3 @@ func FindReleases(ctx context.Context, token, slug string) ([]string, error) {
} }
return versions, nil return versions, nil
} }
func ListOutput(rels []string, output string) []string {
switch strings.ToLower(output) {
case "yaml":
d, _ := yaml.Marshal(rels)
return []string{string(d)}
case "json":
d, _ := json.Marshal(rels)
return []string{string(d)}
default:
for _, r := range rels {
fmt.Println(r)
}
return rels
}
}

View File

@@ -1,8 +1,13 @@
package utils package utils
import ( import (
"encoding/json"
"fmt"
"math/rand" "math/rand"
"strings"
"time" "time"
"gopkg.in/yaml.v1"
) )
func init() { func init() {
@@ -18,3 +23,19 @@ func RandStringRunes(n int) string {
} }
return string(b) return string(b)
} }
func ListOutput(rels []string, output string) []string {
switch strings.ToLower(output) {
case "yaml":
d, _ := yaml.Marshal(rels)
return []string{string(d)}
case "json":
d, _ := json.Marshal(rels)
return []string{string(d)}
default:
for _, r := range rels {
fmt.Println(r)
}
return rels
}
}