-
-
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.
- Loading branch information
Showing
7 changed files
with
108 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -24,4 +24,5 @@ data | |
localstack | ||
/s3hub | ||
/spare | ||
/cfn | ||
.envrc |
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,16 @@ | ||
// Package main is the entrypoint of s3hub. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/nao1215/rainbow/cmd/subcmd/cfn" | ||
) | ||
|
||
func main() { | ||
if err := cfn.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,6 @@ | ||
package cfn | ||
|
||
// commandName returns the cfn command name. | ||
func commandName() string { | ||
return "cfn" | ||
} |
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 cfn is the root command of cfn. | ||
package cfn | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// Execute starts the root command of cfn command. | ||
func Execute() error { | ||
if err := newRootCmd().Execute(); err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// newRootCmd returns a root command for cfn. | ||
func newRootCmd() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "cfn", | ||
Short: `cfn is a command line tool for AWS CloudFormation.`, | ||
} | ||
|
||
cmd.CompletionOptions.DisableDefaultCmd = true | ||
cmd.SilenceUsage = true | ||
cmd.SilenceErrors = true | ||
cmd.DisableFlagParsing = true | ||
|
||
cmd.AddCommand(newVersionCmd()) | ||
return cmd | ||
} |
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 cfn | ||
|
||
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 cfn | ||
|
||
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) | ||
} | ||
}) | ||
} |