-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcli.go
127 lines (111 loc) · 3.14 KB
/
cli.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
func dumpVersionsCmd() *cobra.Command {
var productName string
cmd := &cobra.Command{
Use: "dump-versions [product]",
Short: "Dump marketplace catalog data for all product versions to the all-versions.yaml YAML file",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
productName = args[0]
return dumpVersions(productName)
},
}
return cmd
}
func addVersionCmd() *cobra.Command {
var noOp bool
cmd := &cobra.Command{
Use: "push-version [product] [version]",
Short: "Push local state of the product version's YAML file into a new version",
Args: cobra.ExactArgs(2),
RunE: func(_ *cobra.Command, args []string) error {
productName := args[0]
version := args[1]
return pushNewVersion(productName, noOp, version)
},
}
cmd.Flags().BoolVar(&noOp, "no-op", false, "Print the changeset JSON to stdout without creating the changeset")
return cmd
}
func dumpProductCmd() *cobra.Command {
var productName string
cmd := &cobra.Command{
Use: "dump [product]",
Short: "Dump marketplace catalog data for a product to a YAML file",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
productName = args[0]
return dumpProduct(productName)
},
}
return cmd
}
func listProductsCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "list [product-type]",
Short: "List all my AWS Marketplace products of a given type, or 'all' for all types",
Long: `List AWS Marketplace products. You can specify a product type or 'all'.
Valid product types are:
- ServerProduct
- ContainerProduct
- DataProduct
- MachinelearningProduct
- SaaSProduct
- ServiceProduct
- SolutionProduct
- SupportProduct`,
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
productType := args[0]
return listProducts(productType)
},
}
return cmd
}
func updateProductCmd() *cobra.Command {
var productName string
var noOp bool
cmd := &cobra.Command{
Use: "update [product]",
Short: "Update a product's information based on the data provided in its local YAML representation",
Args: cobra.ExactArgs(1),
RunE: func(_ *cobra.Command, args []string) error {
productName = args[0]
return updateProduct(productName, noOp)
},
}
cmd.Flags().BoolVar(&noOp, "no-op", false, "Print the changeset JSON to stdout without creating the changeset")
return cmd
}
func cloneProductCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "clone [product] [src-version] [dst-version]",
Short: "Copy the YAML data from the src version to the dst version",
Args: cobra.ExactArgs(3),
RunE: func(_ *cobra.Command, args []string) error {
productName, srcVersion, dstVersion := args[0], args[1], args[2]
return cloneProductVersion(productName, srcVersion, dstVersion)
},
}
return cmd
}
func mainFunc() {
rootCmd := &cobra.Command{Use: "aws-marketplace-cli"}
rootCmd.AddCommand(
listProductsCmd(),
dumpProductCmd(),
updateProductCmd(),
dumpVersionsCmd(),
addVersionCmd(),
cloneProductCmd(),
)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}