@@ -5,7 +5,10 @@ SPDX-License-Identifier: BSD-2-Clause
55package cmd
66
77import (
8+ "errors"
9+ "fmt"
810 "os"
11+ "path/filepath"
912
1013 log "github.com/sirupsen/logrus"
1114
@@ -64,11 +67,19 @@ var createEndpointCmd = &cobra.Command{
6467 }
6568
6669 if importPath != "" {
67- err := importYaml (importPath , "create" )
68- if err != nil {
69- log .Fatalln ("Failed to import Endpoint" , err )
70+ yamlFilePaths := getYamlFilePaths (importPath )
71+ if len (yamlFilePaths ) == 0 {
72+ log .Warnln ("No YAML files were found in" , importPath )
73+ }
74+ for _ , yamlFilePath := range yamlFilePaths {
75+ yamlFileName := filepath .Base (yamlFilePath )
76+ err := importYaml (yamlFilePath , "create" )
77+ if err != nil {
78+ log .Warnln ("Failed to import" , yamlFilePath , "as Endpoint" , err )
79+ } else {
80+ fmt .Println ("Imported" , yamlFileName , "successfully - Endpoint created." )
81+ }
7082 }
71- log .Println ("Imported successfully, Endpoint created." )
7283 }
7384 },
7485}
@@ -79,20 +90,30 @@ var updateEndpointCmd = &cobra.Command{
7990 Short : "Update an Endpoint" ,
8091 Long : `Update an Endpoint by importing the YAML specification
8192
82- Update from YAML
83- cs-cli update endpoint --importPath "/Users/sammcgeown/Desktop/updated-endpoint.yaml"
93+ Update from a YAML file
94+ cs-cli update endpoint --importPath "/Users/sammcgeown/cs-cli/endpoints/updated-endpoint.yaml"
95+ Update from a folder of YAML files
96+ cs-cli update endpoint --importPath "/Users/sammcgeown/cs-cli/endpoints"
8497 ` ,
8598 Run : func (cmd * cobra.Command , args []string ) {
8699 if err := ensureTargetConnection (); err != nil {
87100 log .Fatalln (err )
88101 }
89102
90103 if importPath != "" {
91- err := importYaml (importPath , "update" )
92- if err != nil {
93- log .Fatalln ("Failed to import Endpoint" , err )
104+ yamlFilePaths := getYamlFilePaths (importPath )
105+ if len (yamlFilePaths ) == 0 {
106+ log .Warnln ("No YAML files were found in" , importPath )
107+ }
108+ for _ , yamlFilePath := range yamlFilePaths {
109+ yamlFileName := filepath .Base (yamlFilePath )
110+ err := importYaml (yamlFilePath , "apply" )
111+ if err != nil {
112+ log .Warnln ("Failed to import" , yamlFilePath , "as Endpoint" , err )
113+ } else {
114+ fmt .Println ("Imported" , yamlFileName , "successfully - Endpoint updated." )
115+ }
94116 }
95- log .Println ("Imported successfully, Endpoint updated." )
96117 }
97118 },
98119}
@@ -101,19 +122,36 @@ var updateEndpointCmd = &cobra.Command{
101122var deleteEndpointCmd = & cobra.Command {
102123 Use : "endpoint" ,
103124 Short : "Delete an Endpoint" ,
104- Long : `Delete an Endpoint with a specific Endpoint ID
125+ Long : `Delete an Endpoint with a specific Endpoint ID or Name
105126
106127 ` ,
128+ Args : func (cmd * cobra.Command , args []string ) error {
129+ if id != "" && name != "" {
130+ return errors .New ("please specify either endpoint name or endpoint id" )
131+ }
132+ if id == "" && name == "" {
133+ return errors .New ("please specify endpoint name or endpoint id" )
134+ }
135+
136+ return nil
137+ },
107138 Run : func (cmd * cobra.Command , args []string ) {
108139 if err := ensureTargetConnection (); err != nil {
109140 log .Fatalln (err )
110141 }
142+ if name != "" {
143+ response , err := getEndpoint (id , name , project , typename , export , exportPath )
144+ if err != nil {
145+ log .Fatalln (err )
146+ }
147+ id = response [0 ].ID
148+ }
111149
112150 response , err := deleteEndpoint (id )
113151 if err != nil {
114152 log .Println ("Unable to delete Endpoint: " , err )
115153 }
116- log .Println ("Endpoint with id " + response .ID + " deleted" )
154+ fmt .Println ("Endpoint with id " + response .ID + " deleted" )
117155 },
118156}
119157
@@ -136,6 +174,6 @@ func init() {
136174 // Delete
137175 deleteCmd .AddCommand (deleteEndpointCmd )
138176 deleteEndpointCmd .Flags ().StringVarP (& id , "id" , "i" , "" , "ID of the Endpoint to delete" )
139- deleteEndpointCmd .MarkFlagRequired ( "id " )
177+ deleteEndpointCmd .Flags (). StringVarP ( & name , "name" , "n" , "" , "Name of the Endpoint to delete " )
140178
141179}
0 commit comments