forked from nacos-group/nacos-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_config.go
More file actions
43 lines (35 loc) · 1.1 KB
/
get_config.go
File metadata and controls
43 lines (35 loc) · 1.1 KB
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
package cmd
import (
"fmt"
"github.com/nov11/nacos-cli/internal/help"
"github.com/spf13/cobra"
)
var getConfigCmd = &cobra.Command{
Use: "config-get [dataId] [group]",
Short: "Get a specific configuration",
Long: help.ConfigGet.FormatForCLI("nacos-cli"),
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
dataID := args[0]
group := args[1]
// Create Nacos client
nacosClient := mustNewNacosClient()
// Get config
fmt.Printf("Fetching config: %s (%s)...\n\n", dataID, group)
content, err := nacosClient.GetConfig(dataID, group)
checkError(err)
if content == "" {
fmt.Println("Configuration not found")
return
}
// Display content
fmt.Println("═══════════════════════════════════════")
fmt.Printf("Data ID: %s\n", dataID)
fmt.Printf("Group: %s\n", group)
fmt.Println("═══════════════════════════════════════")
fmt.Println(content)
},
}
func init() {
rootCmd.AddCommand(getConfigCmd)
}