Skip to content

Commit

Permalink
context: put quotes around flagvalue incase of whitespaced values
Browse files Browse the repository at this point in the history
  • Loading branch information
Ataberk Gürel authored and Ataberk Gürel committed Aug 5, 2023
1 parent 393e8dd commit 925ce0f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
- Upgraded minimum required Go version to 1.19. ([#583](https://github.com/peak/s5cmd/pull/583))

#### Bugfixes
- Fixed a bug that causes `sync` command with whitespaced flag value to fail. ([#541](https://github.com/peak/s5cmd/issues/541))
- Fixed a bug introduced with `external sort` support in `sync` command which prevents `sync` to an empty destination with `--delete` option. ([#576](https://github.com/peak/s5cmd/issues/576))
- Fixed a bug in `sync` command, which previously caused the command to continue running even if an error was received from the destination bucket. ([#564](https://github.com/peak/s5cmd/issues/564))
- Fixed a bug that causes local files to be lost if downloads fail. ([#479](https://github.com/peak/s5cmd/issues/479))
Expand Down
4 changes: 2 additions & 2 deletions command/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func generateCommand(c *cli.Context, cmd string, defaultFlags map[string]interfa

flags := []string{}
for flagname, flagvalue := range defaultFlags {
flags = append(flags, fmt.Sprintf("--%s=%v", flagname, flagvalue))
flags = append(flags, fmt.Sprintf("--%s='%v'", flagname, flagvalue))
}

isDefaultFlag := func(flagname string) bool {
Expand All @@ -88,7 +88,7 @@ func generateCommand(c *cli.Context, cmd string, defaultFlags map[string]interfa
}

for _, flagvalue := range contextValue(c, flagname) {
flags = append(flags, fmt.Sprintf("--%s=%s", flagname, flagvalue))
flags = append(flags, fmt.Sprintf("--%s='%s'", flagname, flagvalue))
}
}

Expand Down
8 changes: 4 additions & 4 deletions command/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestGenerateCommand(t *testing.T) {
mustNewURL(t, "s3://bucket/key1"),
mustNewURL(t, "s3://bucket/key2"),
},
expectedCommand: `cp --acl=public-read --raw=true "s3://bucket/key1" "s3://bucket/key2"`,
expectedCommand: `cp --acl='public-read' --raw='true' "s3://bucket/key1" "s3://bucket/key2"`,
},
{
name: "same-flag-should-be-ignored-if-given-from-both-default-and-cli-flags",
Expand All @@ -64,7 +64,7 @@ func TestGenerateCommand(t *testing.T) {
mustNewURL(t, "s3://bucket/key1"),
mustNewURL(t, "s3://bucket/key2"),
},
expectedCommand: `cp --raw=true "s3://bucket/key1" "s3://bucket/key2"`,
expectedCommand: `cp --raw='true' "s3://bucket/key1" "s3://bucket/key2"`,
},
{
name: "ignore-non-shared-flag",
Expand Down Expand Up @@ -101,7 +101,7 @@ func TestGenerateCommand(t *testing.T) {
mustNewURL(t, "s3://bucket/key1"),
mustNewURL(t, "s3://bucket/key2"),
},
expectedCommand: `cp --concurrency=6 --flatten=true --force-glacier-transfer=true --raw=true "s3://bucket/key1" "s3://bucket/key2"`,
expectedCommand: `cp --concurrency='6' --flatten='true' --force-glacier-transfer='true' --raw='true' "s3://bucket/key1" "s3://bucket/key2"`,
},
{
name: "string-slice-flag",
Expand All @@ -116,7 +116,7 @@ func TestGenerateCommand(t *testing.T) {
mustNewURL(t, "/source/dir"),
mustNewURL(t, "s3://bucket/prefix/"),
},
expectedCommand: `cp --exclude=*.log --exclude=*.txt "/source/dir" "s3://bucket/prefix/"`,
expectedCommand: `cp --exclude='*.log' --exclude='*.txt' "/source/dir" "s3://bucket/prefix/"`,
},
{
name: "command-with-multiple-args",
Expand Down

0 comments on commit 925ce0f

Please sign in to comment.