Skip to content

Commit 3d0f311

Browse files
authored
feat(cdsctl): add action import from URL (#3770) (#3771)
close #3770 Signed-off-by: Benjamin Coenen <[email protected]>
1 parent 40594f6 commit 3d0f311

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

cli/cdsctl/action.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6+
"io"
67
"io/ioutil"
78
"os"
89
"path"
910
"reflect"
11+
"regexp"
1012
"strings"
1113

1214
"github.com/spf13/cobra"
@@ -156,18 +158,29 @@ cdsctl action import myAction.yml`,
156158

157159
func actionImportRun(v cli.Values) error {
158160
path := v.GetString("path")
159-
f, err := os.Open(path)
160-
if err != nil {
161-
return err
162-
}
163-
defer f.Close()
161+
var contentFile io.Reader
162+
var err error
164163

165-
var format = "yaml"
164+
format := "yaml"
166165
if strings.HasSuffix(path, ".json") {
167166
format = "json"
168167
}
169168

170-
if errImport := client.ActionImport(f, format); errImport != nil {
169+
if isURL, _ := regexp.MatchString(`http[s]?:\/\/(.*)`, path); isURL {
170+
contentFile, _, err = exportentities.OpenURL(path, format)
171+
if err != nil {
172+
return err
173+
}
174+
} else {
175+
f, err := os.Open(path)
176+
if err != nil {
177+
return err
178+
}
179+
defer f.Close()
180+
contentFile = f
181+
}
182+
183+
if errImport := client.ActionImport(contentFile, format); errImport != nil {
171184
return errImport
172185
}
173186

0 commit comments

Comments
 (0)