Skip to content

Commit

Permalink
check if flags are set
Browse files Browse the repository at this point in the history
  • Loading branch information
rxbn committed Jul 6, 2021
1 parent f064c90 commit d3de505
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/containeroo/dologen

go 1.16

require github.com/spf13/pflag v1.0.5 // indirect
require github.com/spf13/pflag v1.0.5
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,32 @@ import (
"encoding/base64"
"fmt"
flag "github.com/spf13/pflag"
"os"
)

func main() {
username := flag.StringP("username", "u", "", "username for docker registry")
password := flag.StringP("password", "p", "", "password for docker registry")
server := flag.StringP("server", "s", "", "docker registry server")
base64Output := flag.BoolP("base64", "b", false, "output result in base64 encoding")
base64Output := flag.BoolP("base64", "b", false, "output result base64 encoded")
flag.Parse()

if *username == "" {
fmt.Println("username cannot be empty!")
flag.Usage()
os.Exit(1)
}
if *password == "" {
fmt.Println("password cannot be empty!")
flag.Usage()
os.Exit(1)
}
if *server == "" {
fmt.Println("server cannot be empty!")
flag.Usage()
os.Exit(1)
}

auth := base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", *username, *password)))

result := fmt.Sprintf("{\"auths\":{\"%s\":{\"username\":\"%s\",\"password\":\"%s\",\"auth\":\"%s\"}}}", *server, *username, *password, auth)
Expand Down

0 comments on commit d3de505

Please sign in to comment.