-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from nao1215/feat/s3hub
Add: s3hub subcommand entrypoint. all subcommnads are not implemented yet
- Loading branch information
Showing
20 changed files
with
320 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ go.work | |
cover.* | ||
data | ||
localstack | ||
/s3hub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Package main is the entrypoint of s3hub. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/nao1215/rainbow/cmd/subcmd/s3hub" | ||
) | ||
|
||
func main() { | ||
if err := s3hub.Execute(); err != nil { | ||
fmt.Fprintf(os.Stderr, "%s\n", err) | ||
os.Exit(1) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package s3hub | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
// newCpCmd return cp command. | ||
func newCpCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "cp", | ||
Short: "Copy file from local(S3 bucket) to S3 bucket(local)", | ||
RunE: cp, | ||
} | ||
} | ||
|
||
// cp is the entrypoint of cp command. | ||
func cp(cmd *cobra.Command, _ []string) error { | ||
cmd.Println("cp is not implemented yet") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package s3hub | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func Test_cp(t *testing.T) { | ||
t.Run("Copy file from local(S3 bucket) to S3 bucket(local)", func(t *testing.T) { | ||
cmd := newCpCmd() | ||
stdout := bytes.NewBufferString("") | ||
cmd.SetOutput(stdout) | ||
|
||
if err := cmd.RunE(cmd, []string{}); err != nil { | ||
t.Errorf("got %v, want nil", err) | ||
} | ||
|
||
want := "cp is not implemented yet\n" | ||
got := stdout.String() | ||
if got != want { | ||
t.Errorf("got %s, want %s", got, want) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package s3hub | ||
|
||
import "fmt" | ||
|
||
func interactive() error { | ||
fmt.Println("interactive mode is not implemented yet") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package s3hub | ||
|
||
import "testing" | ||
|
||
func Test_interactive(t *testing.T) { | ||
t.Run("Interactive mode", func(t *testing.T) { | ||
if err := interactive(); err != nil { | ||
t.Errorf("got %v, want nil", err) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package s3hub | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
// newLsCmd return ls command. | ||
func newLsCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "ls", | ||
Short: "List S3 buckets", | ||
RunE: ls, | ||
} | ||
} | ||
|
||
// ls is the entrypoint of ls command. | ||
func ls(cmd *cobra.Command, _ []string) error { | ||
cmd.Println("ls is not implemented yet") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package s3hub | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func Test_ls(t *testing.T) { | ||
t.Run("List S3 buckets", func(t *testing.T) { | ||
cmd := newLsCmd() | ||
stdout := bytes.NewBufferString("") | ||
cmd.SetOutput(stdout) | ||
|
||
if err := cmd.RunE(cmd, []string{}); err != nil { | ||
t.Errorf("got %v, want nil", err) | ||
} | ||
|
||
want := "ls is not implemented yet\n" | ||
got := stdout.String() | ||
if got != want { | ||
t.Errorf("got %s, want %s", got, want) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package s3hub | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
// newMbCmd return mb command. mb means make bucket. | ||
func newMbCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "mb", | ||
Short: "Make S3 bucket", | ||
RunE: mb, | ||
} | ||
} | ||
|
||
// mb is the entrypoint of mb command. | ||
func mb(cmd *cobra.Command, _ []string) error { | ||
cmd.Println("mb is not implemented yet") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package s3hub | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func Test_mb(t *testing.T) { | ||
t.Run("Make S3 bucket", func(t *testing.T) { | ||
cmd := newMbCmd() | ||
stdout := bytes.NewBufferString("") | ||
cmd.SetOutput(stdout) | ||
|
||
if err := cmd.RunE(cmd, []string{}); err != nil { | ||
t.Errorf("got %v, want nil", err) | ||
} | ||
|
||
want := "mb is not implemented yet\n" | ||
got := stdout.String() | ||
if got != want { | ||
t.Errorf("got %s, want %s", got, want) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package s3hub | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
// newRmCmd return rm command. | ||
func newRmCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "rm", | ||
Short: "Remove contents from S3 bucket (or remove S3 bucket)", | ||
RunE: rm, | ||
} | ||
} | ||
|
||
// rm is the entrypoint of rm command. | ||
func rm(cmd *cobra.Command, _ []string) error { | ||
cmd.Println("rm is not implemented yet") | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package s3hub | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func Test_rm(t *testing.T) { | ||
t.Run("Remove contents from S3 bucket (or remove S3 bucket)", func(t *testing.T) { | ||
cmd := newRmCmd() | ||
stdout := bytes.NewBufferString("") | ||
cmd.SetOutput(stdout) | ||
|
||
if err := cmd.RunE(cmd, []string{}); err != nil { | ||
t.Errorf("got %v, want nil", err) | ||
} | ||
|
||
want := "rm is not implemented yet\n" | ||
got := stdout.String() | ||
if got != want { | ||
t.Errorf("got %s, want %s", got, want) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Package s3hub is the root command of s3hub. | ||
package s3hub | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Execute starts the root command of s3hub. | ||
func Execute() error { | ||
if len(os.Args) == 1 { | ||
return interactive() | ||
} | ||
return newRootCmd().Execute() | ||
} | ||
|
||
// newRootCmd returns a root command for s3hub. | ||
func newRootCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "s3hub", | ||
Short: "user-friendly S3 buckets management tool", | ||
} | ||
cmd.CompletionOptions.DisableDefaultCmd = true | ||
cmd.SilenceUsage = true | ||
cmd.SilenceErrors = true | ||
cmd.DisableFlagParsing = true | ||
|
||
cmd.AddCommand(newVersionCmd()) | ||
cmd.AddCommand(newMbCmd()) | ||
cmd.AddCommand(newLsCmd()) | ||
cmd.AddCommand(newRmCmd()) | ||
cmd.AddCommand(newCpCmd()) | ||
|
||
return cmd | ||
} | ||
|
||
// commandName returns the s3hub command name. | ||
func commandName() string { | ||
return "s3hub" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package s3hub | ||
|
||
import ( | ||
"fmt" | ||
|
||
ver "github.com/nao1215/rainbow/version" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// newVersionCmd return version command. | ||
func newVersionCmd() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "version", | ||
Short: fmt.Sprintf("Print %s version", commandName()), | ||
Run: version, | ||
} | ||
} | ||
|
||
// version return s3hub command version. | ||
func version(cmd *cobra.Command, _ []string) { | ||
cmd.Printf("%s %s (under MIT LICENSE)\n", commandName(), ver.GetVersion()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package s3hub | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
ver "github.com/nao1215/rainbow/version" | ||
) | ||
|
||
func Test_version(t *testing.T) { | ||
t.Run("Get version information", func(t *testing.T) { | ||
cmd := newVersionCmd() | ||
stdout := bytes.NewBufferString("") | ||
cmd.SetOutput(stdout) | ||
|
||
orgVersion := ver.Version | ||
ver.Version = "v0.0.0" | ||
t.Cleanup(func() { | ||
ver.Version = orgVersion | ||
}) | ||
|
||
cmd.Run(cmd, []string{}) | ||
|
||
want := "s3hub v0.0.0 (under MIT LICENSE)\n" | ||
got := stdout.String() | ||
if got != want { | ||
t.Errorf("got %s, want %s", got, want) | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,12 @@ | ||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= | ||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= | ||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= | ||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= | ||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= | ||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= | ||
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0= | ||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho= | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|