-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcmd_createitem.go
59 lines (41 loc) · 1.05 KB
/
cmd_createitem.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
package main
import (
"fmt"
"log"
"strings"
common "github.com/apiheat/akamai-cli-common/v4"
service "github.com/apiheat/go-edgegrid/v6/service/netlistv2"
"github.com/urfave/cli/v2"
)
func cmdAddItemsToNetlist(c *cli.Context) error {
return addItemsToNetlist(c)
}
func addItemsToNetlist(c *cli.Context) error {
var itemsToAdd []string
//TODO: fix
// common.VerifyArgumentByName(c, "id")
//We are not using from-file so we need to validate arguments
if c.String("from-file") == "" {
//TODO: fix
// common.VerifyArgumentByName(c, "items")
//Add out items to slice
itemsToAdd = strings.Split(c.String("items"), ",")
} else {
var errReadFile error
path := c.String("from-file")
itemsToAdd, errReadFile = readLinesFromFile(path)
if errReadFile != nil {
log.Fatal(errReadFile)
}
}
editListOpts := service.NetworkListsOptionsv2{
List: itemsToAdd,
}
netLists, err := apiClient.AddNetworkListElement(c.String("id"), editListOpts)
if err != nil {
fmt.Println(err)
return err
}
common.OutputJSON(netLists)
return nil
}