fix(pkg): remove flogger
This commit is contained in:
parent
7966b42169
commit
b634834a3e
41
cmd/root.go
41
cmd/root.go
@ -5,7 +5,6 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/go-flucky/flucky/pkg/logger"
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/volker-raschek/docker-hub-description-updater/pkg/hub"
|
"github.com/volker-raschek/docker-hub-description-updater/pkg/hub"
|
||||||
"github.com/volker-raschek/docker-hub-description-updater/pkg/types"
|
"github.com/volker-raschek/docker-hub-description-updater/pkg/types"
|
||||||
@ -17,9 +16,6 @@ var (
|
|||||||
dockerHubPassword string
|
dockerHubPassword string
|
||||||
dockerHubRepository string
|
dockerHubRepository string
|
||||||
file string
|
file string
|
||||||
|
|
||||||
loglevel string
|
|
||||||
flogger logger.Logger = logger.NewDefaultLogger(logger.LogLevelDebug)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
@ -27,50 +23,30 @@ var rootCmd = &cobra.Command{
|
|||||||
Short: "docker hub description updater (dhdu)",
|
Short: "docker hub description updater (dhdu)",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
switch loglevel {
|
|
||||||
case "debug":
|
|
||||||
flogger = logger.NewDefaultLogger(logger.LogLevelDebug)
|
|
||||||
break
|
|
||||||
case "info":
|
|
||||||
flogger = logger.NewDefaultLogger(logger.LogLevelDebug)
|
|
||||||
break
|
|
||||||
case "warn":
|
|
||||||
flogger = logger.NewDefaultLogger(logger.LogLevelDebug)
|
|
||||||
break
|
|
||||||
case "error":
|
|
||||||
flogger = logger.NewDefaultLogger(logger.LogLevelDebug)
|
|
||||||
break
|
|
||||||
case "fatal":
|
|
||||||
flogger = logger.NewDefaultLogger(logger.LogLevelDebug)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
hub.SetLogger(flogger)
|
|
||||||
|
|
||||||
if len(dockerHubUser) <= 0 {
|
if len(dockerHubUser) <= 0 {
|
||||||
flogger.Fatal("No user defined over flags")
|
log.Fatalf("No user defined over flags")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dockerHubPassword) <= 0 {
|
if len(dockerHubPassword) <= 0 {
|
||||||
flogger.Fatal("No password defined over flags")
|
log.Fatalf("No password defined over flags")
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dockerHubNamespace) <= 0 {
|
if len(dockerHubNamespace) <= 0 {
|
||||||
flogger.Debug("No namespace defined over flags: Use docker username instead")
|
log.Printf("No namespace defined over flags: Use docker username %v instead", dockerHubUser)
|
||||||
dockerHubNamespace = dockerHubUser
|
dockerHubNamespace = dockerHubUser
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(dockerHubRepository) <= 0 {
|
if len(dockerHubRepository) <= 0 {
|
||||||
flogger.Fatal("No repository defined over flags")
|
log.Fatalf("No repository defined over flags")
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := os.Stat(file); os.IsNotExist(err) && len(file) <= 0 {
|
if _, err := os.Stat(file); os.IsNotExist(err) && len(file) <= 0 {
|
||||||
flogger.Fatal("Can not find file: %v", file)
|
log.Fatalf("Can not find file: %v", file)
|
||||||
}
|
}
|
||||||
|
|
||||||
flogger.Debug("Read file %v", file)
|
|
||||||
f, err := ioutil.ReadFile(file)
|
f, err := ioutil.ReadFile(file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
flogger.Fatal("Can not read file %v: %v", file, err)
|
log.Fatalf("Can not read file %v: %v", file, err)
|
||||||
}
|
}
|
||||||
fullDescription := string(f)
|
fullDescription := string(f)
|
||||||
|
|
||||||
@ -79,7 +55,6 @@ var rootCmd = &cobra.Command{
|
|||||||
Password: dockerHubPassword,
|
Password: dockerHubPassword,
|
||||||
}
|
}
|
||||||
|
|
||||||
flogger.Debug("Get Token")
|
|
||||||
token, err := hub.GetToken(loginCredentials)
|
token, err := hub.GetToken(loginCredentials)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%v", err)
|
log.Fatalf("%v", err)
|
||||||
@ -91,7 +66,6 @@ var rootCmd = &cobra.Command{
|
|||||||
FullDescription: fullDescription,
|
FullDescription: fullDescription,
|
||||||
}
|
}
|
||||||
|
|
||||||
flogger.Debug("Send Repository Patch")
|
|
||||||
_, err = hub.PatchRepository(repository, token)
|
_, err = hub.PatchRepository(repository, token)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%v", err)
|
log.Fatalf("%v", err)
|
||||||
@ -104,13 +78,10 @@ var rootCmd = &cobra.Command{
|
|||||||
func Execute(version string) {
|
func Execute(version string) {
|
||||||
rootCmd.Version = version
|
rootCmd.Version = version
|
||||||
|
|
||||||
rootCmd.Flags().StringVarP(&loglevel, "loglevel", "l", "info", "Loglevel, possible values: debug, info, warn, error, fatal")
|
|
||||||
|
|
||||||
rootCmd.Flags().StringVarP(&dockerHubNamespace, "namespace", "n", "", "Docker Hub Namespace (default \"username\")")
|
rootCmd.Flags().StringVarP(&dockerHubNamespace, "namespace", "n", "", "Docker Hub Namespace (default \"username\")")
|
||||||
rootCmd.Flags().StringVarP(&dockerHubPassword, "password", "p", "", "Docker Hub Password")
|
rootCmd.Flags().StringVarP(&dockerHubPassword, "password", "p", "", "Docker Hub Password")
|
||||||
rootCmd.Flags().StringVarP(&dockerHubRepository, "repository", "r", "", "Docker Hub Repository")
|
rootCmd.Flags().StringVarP(&dockerHubRepository, "repository", "r", "", "Docker Hub Repository")
|
||||||
rootCmd.Flags().StringVarP(&dockerHubUser, "username", "u", "", "Docker Hub Username")
|
rootCmd.Flags().StringVarP(&dockerHubUser, "username", "u", "", "Docker Hub Username")
|
||||||
|
|
||||||
rootCmd.Flags().StringVarP(&file, "file", "f", "./README.md", "File which should be uploaded as docker hub description")
|
rootCmd.Flags().StringVarP(&file, "file", "f", "./README.md", "File which should be uploaded as docker hub description")
|
||||||
|
|
||||||
rootCmd.Execute()
|
rootCmd.Execute()
|
||||||
|
@ -11,18 +11,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/volker-raschek/docker-hub-description-updater/pkg/types"
|
"github.com/volker-raschek/docker-hub-description-updater/pkg/types"
|
||||||
"github.com/volker-raschek/go-logger/pkg/logger"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
dockerHubAPI = "https://hub.docker.com/v2"
|
dockerHubAPI = "https://hub.docker.com/v2"
|
||||||
flogger logger.Logger
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
flogger = logger.NewSilentLogger()
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetRepository(namespace string, name string, token *types.Token) (*types.Repository, error) {
|
func GetRepository(namespace string, name string, token *types.Token) (*types.Repository, error) {
|
||||||
|
|
||||||
if len(namespace) <= 0 {
|
if len(namespace) <= 0 {
|
||||||
@ -166,7 +160,3 @@ func PatchRepository(repository *types.Repository, token *types.Token) (*types.R
|
|||||||
|
|
||||||
return patchedRepository, nil
|
return patchedRepository, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func SetLogger(l logger.Logger) {
|
|
||||||
flogger = l
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user