-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ls subcommand #9
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package subcmd | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
// Doer is an interface that represents the behavior of a command. | ||
type Doer interface { | ||
Do() error | ||
} | ||
|
||
// SubCommand is an interface that represents the behavior of a command. | ||
type SubCommand interface { | ||
Parse(cmd *cobra.Command, args []string) error | ||
Doer | ||
} | ||
|
||
// Run runs the subcommand. | ||
func Run(cmd *cobra.Command, args []string, subCmd SubCommand) error { | ||
if err := subCmd.Parse(cmd, args); err != nil { | ||
return err | ||
} | ||
return subCmd.Do() | ||
} |
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,75 @@ | ||
package s3hub | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/nao1215/rainbow/app/di" | ||
"github.com/nao1215/rainbow/app/domain/model" | ||
"github.com/nao1215/rainbow/utils/errfmt" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// s3hub have common fields and methods for s3hub commands. | ||
type s3hub struct { | ||
// S3App is the application service for S3. | ||
*di.S3App | ||
// command is the cobra command. | ||
command *cobra.Command | ||
// ctx is the context of s3hub command. | ||
ctx context.Context | ||
// profile is the AWS profile name. | ||
profile model.AWSProfile | ||
// region is the AWS region name. | ||
region model.Region | ||
} | ||
|
||
// newS3hub returns a new s3hub. | ||
func newS3hub() *s3hub { | ||
return &s3hub{} | ||
} | ||
|
||
// parse parses command line arguments. | ||
func (s *s3hub) parse(cmd *cobra.Command) error { | ||
s.command = cmd | ||
s.ctx = context.Background() | ||
|
||
p, err := cmd.Flags().GetString("profile") | ||
if err != nil { | ||
return err | ||
} | ||
s.profile = model.NewAWSProfile(p) | ||
|
||
r, err := cmd.Flags().GetString("region") | ||
if err != nil { | ||
return err | ||
} | ||
s.region = model.Region(r) | ||
|
||
cfg, err := model.NewAWSConfig(s.ctx, s.profile, s.region) | ||
if err != nil { | ||
return errfmt.Wrap(err, "can not get aws config") | ||
} | ||
if s.region == "" { | ||
if cfg.Config.Region == "" { | ||
s.region = model.RegionUSEast1 | ||
} else { | ||
s.region = model.Region(cfg.Config.Region) | ||
} | ||
} | ||
|
||
s.S3App, err = di.NewS3App(s.ctx, s.profile, s.region) | ||
if err != nil { | ||
return errfmt.Wrap(err, "can not create s3 application service") | ||
} | ||
return nil | ||
} | ||
|
||
// printf prints a formatted string. | ||
func (s *s3hub) printf(format string, a ...interface{}) { | ||
s.command.Printf(format, a...) | ||
} | ||
|
||
// commandName returns the s3hub command name. | ||
func commandName() string { | ||
return "s3hub" | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [golangci] reported by reviewdog 🐶
ST1000: at least one file in a package should have a package comment (stylecheck)