/
show_dataset.go
79 lines (65 loc) · 1.92 KB
/
show_dataset.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
70
71
72
73
74
75
76
77
78
79
package command
import (
"fmt"
"os"
"text/tabwriter"
client "github.com/ds3lab/easeml/client/go/easemlclient"
"github.com/ghodss/yaml"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var showDatasetCmd = &cobra.Command{
Use: "dataset id",
Short: "Shows dataset given its id.",
Long: ``,
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if apiKey == "" {
apiKey = viper.GetString("api-key")
}
serverAddress := viper.GetString("server-address")
context := client.Context{ServerAddress: serverAddress, UserCredentials: client.APIKeyCredentials{APIKey: apiKey}}
id := ""
if len(args) > 0 {
id = args[0]
}
result, err := context.GetDatasetByID(id)
if err != nil {
fmt.Println(err.Error())
return
}
w := tabwriter.NewWriter(os.Stdout, 0, 8, 3, ' ', 0)
fmt.Fprintf(w, "ID:\t%s\n", result.ID)
fmt.Fprintf(w, "NAME:\t%s\n", result.Name)
fmt.Fprintf(w, "STATUS:\t%s\n", result.Status)
if result.StatusMessage != "" {
fmt.Fprintf(w, "STATUS MESSAGE:\t%s\n", result.StatusMessage)
}
fmt.Fprintf(w, "SOURCE:\t%s\n", result.Source)
fmt.Fprintf(w, "SOURCE ADDRESS:\t%s\n", result.SourceAddress)
fmt.Fprintf(w, "CREATION TIME:\t%s\n", result.CreationTime)
w.Flush()
if result.Description != "" {
fmt.Printf("DESCRIPTION:\n\n%s\n", result.Description)
}
if result.SchemaIn != "" {
ymlSchemaIn, err := yaml.JSONToYAML([]byte(result.SchemaIn))
if err != nil {
fmt.Printf("INPUT SCHEMA: (format error: %s)\n%s\n", err, result.SchemaIn)
} else {
fmt.Printf("INPUT SCHEMA:\n\n%s\n", string(ymlSchemaIn))
}
}
if result.SchemaOut != "" {
ymlSchemaOut, err := yaml.JSONToYAML([]byte(result.SchemaOut))
if err != nil {
fmt.Printf("OUTPUT SCHEMA: (format error: %s)\n%s\n", err, result.SchemaOut)
} else {
fmt.Printf("OUTPUT SCHEMA:\n\n%s\n", string(ymlSchemaOut))
}
}
},
}
func init() {
showCmd.AddCommand(showDatasetCmd)
}