-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (58 loc) · 1.52 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"fmt"
"log"
"os"
"github.com/spf13/cobra"
"github.com/daolis/toolsconfig"
"github.com/daolis/toolsconfig/commands"
)
var rootCmd = &cobra.Command{
Use: "example",
Short: "My example tool",
}
var testCmd = &cobra.Command{
Use: "test",
Short: "my first command",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Execute test command")
configuration, err := toolsconfig.NewToolConfiguration(
toolsconfig.UpdateConfig(false),
toolsconfig.RequiredServer("testserver.io"),
toolsconfig.RequiredSubscription("testSubscription01"))
if err != nil {
// required values missing
var configErr *toolsconfig.ConfigError
if errors.As(err, &configErr) {
missingCredentials := configErr.Missing
fmt.Println("Values missing:", missingCredentials)
}
return
}
repoCredentials, err := configuration.GetServerCredentials("testserver.io")
if err != nil {
log.Fatal(err)
}
fmt.Println("Credentials for testserver.io")
fmt.Println("Username:", repoCredentials.Username)
fmt.Println("Password:", repoCredentials.Password)
},
}
func main() {
err := rootCmd.Execute()
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
func init() {
toolsconfig.ConfigFileLocation(".", "unittestconfig.yaml")
rootCmd.AddCommand(testCmd)
commands.AddToRootCommand(rootCmd, commands.WithRunFunctions(
func(cmd *cobra.Command, args []string) {
fmt.Println("Execute root command")
fmt.Println("To see the credentials run with parameter 'test'")
},
))
}