-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_get.go
56 lines (45 loc) · 1.22 KB
/
user_get.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
/*
Copyright © 2022 PlusServer GmbH
*/
package cmd
import (
"context"
"fmt"
"os"
"github.com/pluscloudopen/reseller-cli/v2/pkg/openapi"
"github.com/spf13/cobra"
)
// listCmd represents the list command
var userGetCmd = &cobra.Command{
Use: "get",
Short: "Get a user",
Long: `Get a user`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
fmt.Println("Please specify the id of the user")
os.Exit(1)
}
if len(args) > 1 {
fmt.Println("Please only specify the id of the user")
os.Exit(1)
}
psOsClient := fetchPsOpenStackClientOrDie()
ctx := context.Background()
resp, err := psOsClient.GetUser(ctx, args[0])
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
printUsers([]openapi.CreatedOpenStackUser{*resp})
},
}
func init() {
userCmd.AddCommand(userGetCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// listCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// listCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}