diff --git a/cmd/swarm/main.go b/cmd/swarm/main.go index f4ff0bb731..8ca1388447 100644 --- a/cmd/swarm/main.go +++ b/cmd/swarm/main.go @@ -141,6 +141,10 @@ var ( Name: "mime", Usage: "force mime type", } + SwarmEncryptedFlag = cli.BoolFlag{ + Name: "encrypted", + Usage: "use encrypted upload", + } SwarmPssEnabledFlag = cli.BoolFlag{ Name: "pss", Usage: "Enable pss (message passing over swarm)", @@ -218,19 +222,11 @@ The output of this command is supposed to be machine-readable. `, }, { - Action: nonEncryptedUpload, + Action: upload, Name: "up", Usage: "upload a file or directory to swarm using the HTTP API", ArgsUsage: " ", - Description: ` -"upload a file or directory to swarm using the HTTP API and prints the root hash", -`, - }, - { - Action: encryptedUpload, - Name: "encrypted-up", - Usage: "Upload a file or directory with encryption to swarm using the HTTP API. NOTE: Currently the reference for the uploaded content is non-deterministic, so you will receive different references if you upload it twice.", - ArgsUsage: " ", + Flags: []cli.Flag{SwarmEncryptedFlag}, Description: ` "upload a file or directory to swarm using the HTTP API and prints the root hash", `, diff --git a/cmd/swarm/upload.go b/cmd/swarm/upload.go index bdcbc96581..38207ddccb 100644 --- a/cmd/swarm/upload.go +++ b/cmd/swarm/upload.go @@ -35,15 +35,7 @@ import ( "gopkg.in/urfave/cli.v1" ) -func encryptedUpload(ctx *cli.Context) { - upload(ctx, true) -} - -func nonEncryptedUpload(ctx *cli.Context) { - upload(ctx, false) -} - -func upload(ctx *cli.Context, toEncrypt bool) { +func upload(ctx *cli.Context) { args := ctx.Args() var ( @@ -54,6 +46,7 @@ func upload(ctx *cli.Context, toEncrypt bool) { fromStdin = ctx.GlobalBool(SwarmUpFromStdinFlag.Name) mimeType = ctx.GlobalString(SwarmUploadMimeType.Name) client = swarm.NewClient(bzzapi) + toEncrypt = ctx.Bool(SwarmEncryptedFlag.Name) file string ) diff --git a/cmd/swarm/upload_test.go b/cmd/swarm/upload_test.go index f2ee999198..a868a5540c 100644 --- a/cmd/swarm/upload_test.go +++ b/cmd/swarm/upload_test.go @@ -59,15 +59,22 @@ func testCLISwarmUp(toEncrypt bool, t *testing.T) { t.Fatal(err) } - cmd := "up" hashRegexp := `[a-f\d]{64}` + flags := []string{ + "--bzzapi", cluster.Nodes[0].URL, + "up", + tmp.Name()} if toEncrypt { - cmd = "encrypted-up" hashRegexp = `[a-f\d]{128}` + flags = []string{ + "--bzzapi", cluster.Nodes[0].URL, + "up", + "--encrypted", + tmp.Name()} } - // upload the file with 'swarm up' or 'swarm encrypted-up' and expect a hash - log.Info(fmt.Sprintf("uploading file with '%s'", cmd)) - up := runSwarm(t, "--bzzapi", cluster.Nodes[0].URL, cmd, tmp.Name()) + // upload the file with 'swarm up' and expect a hash + log.Info(fmt.Sprintf("uploading file with 'swarm up'")) + up := runSwarm(t, flags...) _, matches := up.ExpectRegexp(hashRegexp) up.ExpectExit() hash := matches[0]