Skip to content

Commit f934889

Browse files
authored
upload file with directives (#85)
* upload file with directives * linters fixes
1 parent 441a050 commit f934889

File tree

30 files changed

+161
-96
lines changed

30 files changed

+161
-96
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ _linter:
6868
go install github.com/mgechev/[email protected]
6969

7070
lint:
71+
golangci-lint run ./... && \
7172
revive -config .revive.toml ./...
7273

7374
_mockery-install:

cmd/cmd_root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewRootCmd() *cobra.Command {
3030
rootCmd := &cobra.Command{
3131
Use: "smartling-cli",
3232
Short: "Manage translation files using Smartling CLI.",
33-
Version: "2.2",
33+
Version: "2.3",
3434
Long: `Manage translation files using Smartling CLI.
3535
Complete documentation is available at https://www.smartling.com`,
3636
PersistentPreRun: func(cmd *cobra.Command, _ []string) {

cmd/files/delete/cmd_delete_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ func TestNewDeleteCmd(t *testing.T) {
1717
filesSrv := srvmocks.NewMockService(t)
1818
uriArg := "https://example.com:8080/path/to/resource?search=a"
1919
filesSrv.On("RunDelete", uriArg).Run(func(args mock.Arguments) {
20-
fmt.Fprintln(buf, fmt.Sprintf("RunDelete was called with %d args", len(args)))
21-
fmt.Fprintln(buf, fmt.Sprintf("uri: %v", args[0]))
20+
fmt.Fprintf(buf, "RunDelete was called with %d args\n", len(args))
21+
fmt.Fprintf(buf, "uri: %v\n", args[0])
2222
}).Return(nil)
2323

2424
initializer := cmdmocks.NewMockSrvInitializer(t)

cmd/files/import/cmd_import_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ func TestNewImportCmd(t *testing.T) {
2525
Overwrite: true,
2626
}
2727
filesSrv.On("RunImport", params).Run(func(args mock.Arguments) {
28-
fmt.Fprintln(buf, fmt.Sprintf("RunImport was called with %d args", len(args)))
29-
fmt.Fprintln(buf, fmt.Sprintf("params: %v", args[0]))
28+
fmt.Fprintf(buf, "RunImport was called with %d args\n", len(args))
29+
fmt.Fprintf(buf, "params: %v\n", args[0])
3030
}).Return(nil)
3131

3232
initializer := cmdmocks.NewMockSrvInitializer(t)

cmd/files/list/cmd_list_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,18 @@ func TestNewListCmd(t *testing.T) {
1919
shortArg := true
2020
uriArg := "https://example.com:8080/path/to/resource?search=a"
2121
filesSrv.On("RunList", formatTypeArg, shortArg, uriArg).Run(func(args mock.Arguments) {
22-
fmt.Fprintln(buf, fmt.Sprintf("RunList was called with %d args", len(args)))
23-
fmt.Fprintln(buf, fmt.Sprintf("format: %v", args[0]))
24-
fmt.Fprintln(buf, fmt.Sprintf("short: %v", args[1]))
25-
fmt.Fprintln(buf, fmt.Sprintf("uri: %v", args[2]))
22+
if _, err := fmt.Fprintf(buf, "RunList was called with %d args\n", len(args)); err != nil {
23+
t.Fatal(err)
24+
}
25+
if _, err := fmt.Fprintf(buf, "format: %v\n", args[0]); err != nil {
26+
t.Fatal(err)
27+
}
28+
if _, err := fmt.Fprintf(buf, "short: %v\n", args[1]); err != nil {
29+
t.Fatal(err)
30+
}
31+
if _, err := fmt.Fprintf(buf, "uri: %v\n", args[2]); err != nil {
32+
t.Fatal(err)
33+
}
2634
}).Return(nil)
2735

2836
initializer := cmdmocks.NewMockSrvInitializer(t)

cmd/files/pull/cmd_pull_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,12 @@ func TestNewPullCmd(t *testing.T) {
2626
Retrieve: "none",
2727
}
2828
filesSrv.On("RunPull", params).Run(func(args mock.Arguments) {
29-
fmt.Fprintln(buf, fmt.Sprintf("RunPull was called with %d args", len(args)))
30-
fmt.Fprintln(buf, fmt.Sprintf("params: %v", args[0]))
29+
if _, err := fmt.Fprintf(buf, "RunPull was called with %d args\n", len(args)); err != nil {
30+
t.Fatal(err)
31+
}
32+
if _, err := fmt.Fprintf(buf, "params: %v\n", args[0]); err != nil {
33+
t.Fatal(err)
34+
}
3135
}).Return(nil)
3236

3337
initializer := cmdmocks.NewMockSrvInitializer(t)

cmd/files/push/cmd_push.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package push
33
import (
44
filescmd "github.com/Smartling/smartling-cli/cmd/files"
55
"github.com/Smartling/smartling-cli/services/files"
6+
"github.com/Smartling/smartling-cli/services/helpers"
67
"github.com/Smartling/smartling-cli/services/helpers/help"
78

89
"github.com/spf13/cobra"
@@ -75,6 +76,10 @@ can be used to override detected file type.
7576
return err
7677
}
7778

79+
directives, err := helpers.MKeyValueToMap(directives)
80+
if err != nil {
81+
return err
82+
}
7883
p := files.PushParams{
7984
URI: uri,
8085
File: file,

cmd/files/push/cmd_push_test.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ func TestNewPushCmd(t *testing.T) {
2424
Authorize: true,
2525
FileType: "text",
2626
Directory: ".",
27-
Directives: []string{"01", "05"},
27+
Directives: map[string]string{"key1": "01", "key5": "05"},
2828
}
29-
filesSrv.On("RunPush", params).Run(func(args mock.Arguments) {
30-
fmt.Fprintln(buf, fmt.Sprintf("RunPush was called with %d args", len(args)))
31-
fmt.Fprintln(buf, fmt.Sprintf("params: %v", args[0]))
29+
filesSrv.On("RunPush", mock.Anything, params).Run(func(args mock.Arguments) {
30+
if _, err := fmt.Fprintf(buf, "RunPush was called with %d args\n", len(args)); err != nil {
31+
t.Fatal(err)
32+
}
33+
if _, err := fmt.Fprintf(buf, "params: %v\n", args[1]); err != nil {
34+
t.Fatal(err)
35+
}
3236
}).Return(nil)
3337

3438
initializer := cmdmocks.NewMockSrvInitializer(t)
@@ -46,8 +50,8 @@ func TestNewPushCmd(t *testing.T) {
4650
"--locale", params.Locales[1],
4751
"--branch", params.Branch,
4852
"--type", params.FileType,
49-
"--directive", params.Directives[0],
50-
"--directive", params.Directives[1],
53+
"--directive", "key1=01",
54+
"--directive", "key5=05",
5155
})
5256

5357
err := cmd.Execute()
@@ -56,7 +60,7 @@ func TestNewPushCmd(t *testing.T) {
5660
}
5761

5862
output := buf.String()
59-
expected := fmt.Sprintf(`RunPush was called with 1 args
63+
expected := fmt.Sprintf(`RunPush was called with 2 args
6064
params: %v
6165
`, params)
6266

cmd/files/rename/cmd_rename_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ func TestNewRenameCmd(t *testing.T) {
1919
oldArg := "_old"
2020
newArg := "_new"
2121
filesSrv.On("RunRename", oldArg, newArg).Run(func(args mock.Arguments) {
22-
fmt.Fprintln(buf, fmt.Sprintf("RunRename was called with %d args", len(args)))
23-
fmt.Fprintln(buf, fmt.Sprintf("old: %v", args[0]))
24-
fmt.Fprintln(buf, fmt.Sprintf("new: %v", args[1]))
22+
if _, err := fmt.Fprintf(buf, "RunRename was called with %d args\n", len(args)); err != nil {
23+
t.Fatal(err)
24+
}
25+
if _, err := fmt.Fprintf(buf, "old: %v\n", args[0]); err != nil {
26+
t.Fatal(err)
27+
}
28+
if _, err := fmt.Fprintf(buf, "new: %v\n", args[1]); err != nil {
29+
t.Fatal(err)
30+
}
2531
}).Return(nil)
2632

2733
initializer := cmdmocks.NewMockSrvInitializer(t)

cmd/files/status/cmd_status_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ func TestNewStatusCmd(t *testing.T) {
2222
Format: "txt",
2323
}
2424
filesSrv.On("RunStatus", params).Run(func(args mock.Arguments) {
25-
fmt.Fprintln(buf, fmt.Sprintf("RunStatus was called with %d args", len(args)))
26-
fmt.Fprintln(buf, fmt.Sprintf("params: %v", args[0]))
25+
if _, err := fmt.Fprintf(buf, "RunStatus was called with %d args\n", len(args)); err != nil {
26+
t.Fatal(err)
27+
}
28+
if _, err := fmt.Fprintf(buf, "params: %v\n", args[0]); err != nil {
29+
t.Fatal(err)
30+
}
2731
}).Return(nil)
2832

2933
initializer := cmdmocks.NewMockSrvInitializer(t)

0 commit comments

Comments
 (0)