Skip to content

Commit c01957f

Browse files
feat(feeds): add feeds import cli support (#192)
* feat(feeds): add feeds import cli support * chore(feeds): named import * feat(feeds): add feeds import cli support
1 parent f6d466a commit c01957f

File tree

11 files changed

+458
-49
lines changed

11 files changed

+458
-49
lines changed

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
> - The command invocation is `stream-cli chat [verb-noun] [args] [options]` instead of `stream [verb:noun] [args] [options]`. The most obvious change is using dash instead of colon. We also added the `chat` keyword to preserve domain for our other product [Feeds](https://getstream.io/activity-feeds/).
1111
> - The 1.0.0 Go version's feature set is matching the old one. But if you miss anything, feel free to open an issue.
1212
13-
Stream's Command Line Interface (CLI) makes it easy to create and manage your [Stream](https://getstream.io) apps directly from the terminal. Currently, only Chat is supported; however, the ability to manage Feeds will be coming soon.
13+
Stream's Command Line Interface (CLI) makes it easy to create and manage your [Stream](https://getstream.io) apps directly from the terminal. It supports both Chat and Feeds, including a unified `import` command for data imports.
1414

1515
# 📚 Documentation
1616
The full documentation is deployed to [GitHub Pages](https://getstream.github.io/stream-cli/).
@@ -85,13 +85,19 @@ stream-cli version 1.0.0
8585
Basic commands use the following syntax:
8686

8787
```shell
88-
$ stream-cli [chat|feeds] [command] [args] [options]
88+
$ stream-cli [chat|import] [command] [args] [options]
8989
```
9090

91-
Example:
91+
Examples:
9292

9393
```shell
9494
$ stream-cli chat get-channel -t messaging -i redteam
95+
96+
# Import data into Chat
97+
$ stream-cli import chat upload-import data.json --mode insert
98+
99+
# Import data into Feeds
100+
$ stream-cli import feeds upload-import data.json
95101
```
96102

97103
The `--help` keyword is available every step of the way. Examples:
@@ -100,6 +106,9 @@ The `--help` keyword is available every step of the way. Examples:
100106
$ stream-cli --help
101107
$ stream-cli chat --help
102108
$ stream-cli chat get-channel --help
109+
$ stream-cli import --help
110+
$ stream-cli import chat --help
111+
$ stream-cli import feeds --help
103112
```
104113

105114
# 💬 Auto completion

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ go 1.23
44

55
require (
66
github.com/AlecAivazis/survey/v2 v2.3.4
7+
github.com/GetStream/getstream-go/v4 v4.0.4
78
github.com/GetStream/stream-chat-go/v8 v8.3.0
89
github.com/MakeNowJust/heredoc v1.0.0
910
github.com/cheynewallace/tabby v1.1.1
@@ -14,6 +15,8 @@ require (
1415
github.com/spf13/viper v1.11.0
1516
)
1617

18+
require github.com/golang-jwt/jwt/v5 v5.2.1
19+
1720
require (
1821
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
1922
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -38,12 +41,12 @@ require (
3841
github.com/spf13/afero v1.8.2 // indirect
3942
github.com/spf13/cast v1.5.0 // indirect
4043
github.com/spf13/jwalterweatherman v1.1.0 // indirect
41-
github.com/stretchr/testify v1.7.1
44+
github.com/stretchr/testify v1.9.0
4245
github.com/subosito/gotenv v1.2.0 // indirect
4346
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f // indirect
4447
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
4548
golang.org/x/text v0.3.8 // indirect
4649
gopkg.in/ini.v1 v1.66.4 // indirect
4750
gopkg.in/yaml.v2 v2.4.0 // indirect
48-
gopkg.in/yaml.v3 v3.0.0 // indirect
51+
gopkg.in/yaml.v3 v3.0.1 // indirect
4952
)

go.sum

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ github.com/AlecAivazis/survey/v2 v2.3.4 h1:pchTU9rsLUSvWEl2Aq9Pv3k0IE2fkqtGxazsk
4040
github.com/AlecAivazis/survey/v2 v2.3.4/go.mod h1:hrV6Y/kQCLhIZXGcriDCUBtB3wnN7156gMXJ3+b23xM=
4141
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
4242
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
43+
github.com/GetStream/getstream-go/v4 v4.0.4 h1:nkD/s42M+06eOpa4m8n38ukumqxX4LlCAEzrRU27kmw=
44+
github.com/GetStream/getstream-go/v4 v4.0.4/go.mod h1:A5hd7TxT8nSZBWazr4403j05dqP0F8pt7vi8YAJj+9M=
4345
github.com/GetStream/stream-chat-go/v8 v8.3.0 h1:mFtQZ0PkcCXMPjCDlnZcex3roOvE+UOaxBcNdq3o62s=
4446
github.com/GetStream/stream-chat-go/v8 v8.3.0/go.mod h1:frj3A1yv9mjyWlGNwaZKnXcX9JYYTPWSDqzyOFeHPac=
4547
github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=
@@ -81,6 +83,8 @@ github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2
8183
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
8284
github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo=
8385
github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0=
86+
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
87+
github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
8488
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
8589
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
8690
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -134,6 +138,8 @@ github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLe
134138
github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
135139
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
136140
github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
141+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
142+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
137143
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
138144
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
139145
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
@@ -149,6 +155,8 @@ github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:
149155
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
150156
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
151157
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
158+
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
159+
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
152160
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
153161
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
154162
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
@@ -219,8 +227,9 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
219227
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
220228
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
221229
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
222-
github.com/stretchr/testify v1.7.1 h1:5TQK59W5E3v0r2duFAb7P95B6hEeOyEnHRa8MjYSMTY=
223230
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
231+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
232+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
224233
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
225234
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
226235
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
@@ -529,8 +538,8 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
529538
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
530539
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
531540
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
532-
gopkg.in/yaml.v3 v3.0.0 h1:hjy8E9ON/egN1tAYqKb61G10WtihqetD4sz2H+8nIeA=
533-
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
541+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
542+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
534543
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
535544
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
536545
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
@@ -540,4 +549,4 @@ honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9
540549
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
541550
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
542551
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
543-
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
552+
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=

pkg/cmd/chat/imports/imports.go

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package imports
22

33
import (
4-
"context"
5-
"net/http"
6-
"os"
74
"path/filepath"
85
"time"
96

@@ -23,44 +20,16 @@ func NewCmds() []*cobra.Command {
2320
}
2421
}
2522

26-
func uploadToS3(ctx context.Context, filename, url string) error {
27-
data, err := os.Open(filename)
28-
if err != nil {
29-
return err
30-
}
31-
defer data.Close()
32-
33-
stat, err := data.Stat()
34-
if err != nil {
35-
return err
36-
}
37-
38-
req, err := http.NewRequestWithContext(ctx, "PUT", url, data)
39-
if err != nil {
40-
return err
41-
}
42-
req.Header.Set("Content-Type", "application/json")
43-
req.ContentLength = stat.Size()
44-
45-
resp, err := http.DefaultClient.Do(req)
46-
if err != nil {
47-
return err
48-
}
49-
defer resp.Body.Close()
50-
51-
return nil
52-
}
53-
5423
func uploadCmd() *cobra.Command {
5524
cmd := &cobra.Command{
5625
Use: "upload-import [filename] --mode [upsert|insert] --output-format [json|tree]",
5726
Short: "Upload an import",
5827
Example: heredoc.Doc(`
5928
# Uploads an import and prints it as JSON
60-
$ stream-cli chat upload-import data.json --mode insert
29+
$ stream-cli import chat upload-import data.json --mode insert
6130
6231
# Uploads an import and prints it as a browsable tree
63-
$ stream-cli chat upload-import data.json --mode insert --output-format tree
32+
$ stream-cli import chat upload-import data.json --mode insert --output-format tree
6433
`),
6534
Args: cobra.ExactArgs(1),
6635
RunE: func(cmd *cobra.Command, args []string) error {
@@ -87,7 +56,7 @@ func uploadCmd() *cobra.Command {
8756
return err
8857
}
8958

90-
if err := uploadToS3(cmd.Context(), filename, createImportURLResp.UploadURL); err != nil {
59+
if err := utils.UploadToS3(cmd.Context(), filename, createImportURLResp.UploadURL); err != nil {
9160
return err
9261
}
9362
createImportResp, err := c.CreateImport(cmd.Context(), createImportURLResp.Path, mode, opts...)
@@ -114,10 +83,10 @@ func getCmd() *cobra.Command {
11483
Short: "Get import",
11584
Example: heredoc.Doc(`
11685
# Returns an import and prints it as JSON
117-
$ stream-cli chat get-import dcb6e366-93ec-4e52-af6f-b0c030ad5272
86+
$ stream-cli import chat get-import dcb6e366-93ec-4e52-af6f-b0c030ad5272
11887
11988
# Returns an import and prints it as JSON, and wait for it to complete
120-
$ stream-cli chat get-import dcb6e366-93ec-4e52-af6f-b0c030ad5272 --watch
89+
$ stream-cli import chat get-import dcb6e366-93ec-4e52-af6f-b0c030ad5272 --watch
12190
`),
12291
Args: cobra.ExactArgs(1),
12392
RunE: func(cmd *cobra.Command, args []string) error {
@@ -164,10 +133,10 @@ func listCmd() *cobra.Command {
164133
Short: "List imports",
165134
Example: heredoc.Doc(`
166135
# List all imports as json (default)
167-
$ stream-cli chat list-imports
136+
$ stream-cli import chat list-imports
168137
169138
# List all imports as browsable tree
170-
$ stream-cli chat list-imports --output-format tree
139+
$ stream-cli import chat list-imports --output-format tree
171140
`),
172141
RunE: func(cmd *cobra.Command, args []string) error {
173142
c, err := config.GetConfig(cmd).GetClient(cmd)

pkg/cmd/chat/root.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/GetStream/stream-cli/pkg/cmd/chat/device"
1010
"github.com/GetStream/stream-cli/pkg/cmd/chat/events"
1111
"github.com/GetStream/stream-cli/pkg/cmd/chat/file"
12-
"github.com/GetStream/stream-cli/pkg/cmd/chat/imports"
1312
"github.com/GetStream/stream-cli/pkg/cmd/chat/message"
1413
"github.com/GetStream/stream-cli/pkg/cmd/chat/push"
1514
"github.com/GetStream/stream-cli/pkg/cmd/chat/reaction"
@@ -29,7 +28,6 @@ func NewRootCmd() *cobra.Command {
2928
cmd.AddCommand(device.NewCmds()...)
3029
cmd.AddCommand(events.NewCmds()...)
3130
cmd.AddCommand(file.NewCmds()...)
32-
cmd.AddCommand(imports.NewCmds()...)
3331
cmd.AddCommand(message.NewCmds()...)
3432
cmd.AddCommand(user.NewCmds()...)
3533
cmd.AddCommand(push.NewCmds()...)

0 commit comments

Comments
 (0)