diff --git a/main.go b/main.go index a405401..7b123f5 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( var ( cliEndpoint = kingpin.Flag("endpoint", "Override command's default URL with the given URL").Envar("SKPR_S3_SYNC_ENDPOINT").String() cliExclude = kingpin.Flag("exclude", "Exclude paths from the list to be synced").Envar("SKPR_S3_SYNC_EXCLUDE").Default(".htaccess").String() + cliMode = kingpin.Flag("mode", "Mode which will used for syncing (sync or s3)").Envar("SKPR_S3_SYNC_MODE").Default("sync").String() cliSource = kingpin.Arg("source", "Source files which are synced (local or S3 path)").Required().String() cliTarget = kingpin.Arg("target", "Target files which are synced (local or S3 path)").Required().String() ) @@ -20,7 +21,7 @@ var ( func main() { kingpin.Parse() - args := buildArgs(*cliEndpoint, *cliSource, *cliTarget, *cliExclude) + args := buildArgs(*cliEndpoint, *cliMode, *cliSource, *cliTarget, *cliExclude) slog.Info("Starting sync", "args", strings.Join(args, " ")) @@ -38,14 +39,14 @@ func main() { } // Command which is compatible with the AWS S3 sync command line interface. -func buildArgs(endpoint, source, target, exclude string) []string { +func buildArgs(endpoint, mode, source, target, exclude string) []string { args := []string{"s3"} if endpoint != "" { args = append(args, "--endpoint-url", endpoint) } - args = append(args, "sync") + args = append(args, mode) if exclude != "" { for _, e := range strings.Split(exclude, ",") { diff --git a/main_test.go b/main_test.go index 7a31431..d1f0479 100644 --- a/main_test.go +++ b/main_test.go @@ -7,16 +7,21 @@ import ( ) func TestBuildArgsWithEndpoint(t *testing.T) { - command := buildArgs("127.0.0.1", "foo", "bar", "") + command := buildArgs("127.0.0.1", "sync", "foo", "bar", "") assert.Equal(t, []string{"s3", "--endpoint-url", "127.0.0.1", "sync", "foo", "bar"}, command) } +func TestBuildArgsWithEndpointAndCP(t *testing.T) { + command := buildArgs("127.0.0.1", "cp", "foo", "bar", "") + assert.Equal(t, []string{"s3", "--endpoint-url", "127.0.0.1", "cp", "foo", "bar"}, command) +} + func TestBuildArgsdWithExcludes(t *testing.T) { - command := buildArgs("", "foo", "bar", "/stuff,/things") + command := buildArgs("", "sync", "foo", "bar", "/stuff,/things") assert.Equal(t, []string{"s3", "sync", "--exclude", "/stuff", "--exclude", "/things", "foo", "bar"}, command) } func TestBuildArgsWithAll(t *testing.T) { - command := buildArgs("127.0.0.1", "foo", "bar", "/stuff,/things") + command := buildArgs("127.0.0.1", "sync", "foo", "bar", "/stuff,/things") assert.Equal(t, []string{"s3", "--endpoint-url", "127.0.0.1", "sync", "--exclude", "/stuff", "--exclude", "/things", "foo", "bar"}, command) }