-
Notifications
You must be signed in to change notification settings - Fork 52
kool create command #198
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
Merged
Merged
kool create command #198
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b8e4088
add create command
leandroncbrito 36b4e86
Merge branch 'master' into create-command
leandroncbrito 43cbafc
tests
leandroncbrito faa1058
update parse presets
leandroncbrito 8a57c2b
added test and KoolDocker service
leandroncbrito a2ab8ad
calling preset after create
leandroncbrito b9b4c21
removing unnecessary error validation
leandroncbrito 068b9a5
new test case
leandroncbrito 308cea1
making docs
leandroncbrito 70e3873
remove init changes from docs
leandroncbrito e7ec8fa
Merge branch 'master' into create-command
leandroncbrito 9ef30cf
load presets function, new tests
leandroncbrito d72bee0
replace kooldocker command by builder command, code review
leandroncbrito 74ef333
fix lint
leandroncbrito 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,86 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "kool-dev/kool/cmd/builder" | ||
| "kool-dev/kool/cmd/presets" | ||
| "os" | ||
|
|
||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| // KoolCreate holds handlers and functions to implement the preset command logic | ||
| type KoolCreate struct { | ||
| DefaultKoolService | ||
| parser presets.Parser | ||
| createCommand builder.Command | ||
| KoolPreset | ||
| } | ||
|
|
||
| func init() { | ||
| var ( | ||
| create = NewKoolCreate() | ||
| createCmd = NewCreateCommand(create) | ||
| ) | ||
|
|
||
| rootCmd.AddCommand(createCmd) | ||
| } | ||
|
|
||
| // NewKoolCreate creates a new handler for create logic | ||
| func NewKoolCreate() *KoolCreate { | ||
| return &KoolCreate{ | ||
| *newDefaultKoolService(), | ||
| &presets.DefaultParser{}, | ||
| &builder.DefaultCommand{}, | ||
| *NewKoolPreset(), | ||
| } | ||
| } | ||
|
|
||
| // Execute runs the create logic with incoming arguments. | ||
| func (c *KoolCreate) Execute(originalArgs []string) (err error) { | ||
| preset := originalArgs[0] | ||
| dir := originalArgs[1] | ||
|
|
||
| c.parser.LoadPresets(presets.GetAll()) | ||
|
|
||
| if !c.parser.Exists(preset) { | ||
| err = fmt.Errorf("Unknown preset %s", preset) | ||
| return | ||
| } | ||
|
|
||
| createCmd, err := c.parser.GetCreateCommand(preset) | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| err = c.createCommand.Parse(createCmd) | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| err = c.createCommand.Interactive(dir) | ||
|
|
||
| if err != nil { | ||
| return | ||
| } | ||
|
|
||
| _ = os.Chdir(dir) | ||
|
|
||
| err = c.KoolPreset.Execute([]string{preset}) | ||
|
|
||
| return | ||
| } | ||
|
|
||
| // NewCreateCommand initializes new kool create command | ||
| func NewCreateCommand(create *KoolCreate) (createCmd *cobra.Command) { | ||
| createCmd = &cobra.Command{ | ||
| Use: "create [preset] [project]", | ||
| Short: "Create a new project using preset", | ||
| Args: cobra.ExactArgs(2), | ||
| Run: DefaultCommandRunFunction(create), | ||
| } | ||
|
|
||
| return | ||
| } | ||
This file contains hidden or 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,126 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "kool-dev/kool/cmd/builder" | ||
| "kool-dev/kool/cmd/presets" | ||
| "kool-dev/kool/cmd/shell" | ||
| "testing" | ||
| ) | ||
|
|
||
| func newFakeKoolCreate() *KoolCreate { | ||
| return &KoolCreate{ | ||
| *newFakeKoolService(), | ||
| &presets.FakeParser{}, | ||
| &builder.FakeCommand{}, | ||
| *newFakeKoolPreset(), | ||
| } | ||
| } | ||
|
|
||
| func TestNewKoolCreate(t *testing.T) { | ||
| k := NewKoolCreate() | ||
|
|
||
| if _, ok := k.DefaultKoolService.out.(*shell.DefaultOutputWriter); !ok { | ||
| t.Errorf("unexpected shell.OutputWriter on default KoolCreate instance") | ||
| } | ||
|
|
||
| if _, ok := k.DefaultKoolService.exiter.(*shell.DefaultExiter); !ok { | ||
| t.Errorf("unexpected shell.Exiter on default KoolCreate instance") | ||
| } | ||
|
|
||
| if _, ok := k.DefaultKoolService.in.(*shell.DefaultInputReader); !ok { | ||
| t.Errorf("unexpected shell.InputReader on default KoolCreate instance") | ||
| } | ||
|
|
||
| if _, ok := k.createCommand.(*builder.DefaultCommand); !ok { | ||
| t.Errorf("unexpected builder.Command on default KoolCreate instance") | ||
| } | ||
|
|
||
| if _, ok := k.parser.(*presets.DefaultParser); !ok { | ||
| t.Errorf("unexpected presets.Parser on default KoolCreate instance") | ||
| } | ||
| } | ||
|
|
||
| func TestNewKoolCreateCommand(t *testing.T) { | ||
| f := newFakeKoolCreate() | ||
|
|
||
| f.parser.(*presets.FakeParser).MockExists = true | ||
| f.KoolPreset.parser.(*presets.FakeParser).MockExists = true | ||
| f.parser.(*presets.FakeParser).MockCreateCommand = "kool docker create command" | ||
|
|
||
| cmd := NewCreateCommand(f) | ||
| cmd.SetArgs([]string{"laravel", "my-app"}) | ||
|
|
||
| if err := cmd.Execute(); err != nil { | ||
| t.Errorf("unexpected error executing create command; error: %v", err) | ||
| } | ||
|
|
||
| if !f.parser.(*presets.FakeParser).CalledLoadPresets { | ||
| t.Error("did not call parser.LoadPresets") | ||
| } | ||
|
|
||
| if !f.parser.(*presets.FakeParser).CalledExists { | ||
| t.Error("did not call parser.Exists") | ||
| } | ||
|
|
||
| if !f.parser.(*presets.FakeParser).CalledGetCreateCommand { | ||
| t.Error("did not call parser.GetCreateCommand") | ||
| } | ||
|
|
||
| if !f.createCommand.(*builder.FakeCommand).CalledParseCommand { | ||
| t.Error("did not call Parse on KoolCreate.createCommand Command") | ||
| } | ||
|
|
||
| if !f.createCommand.(*builder.FakeCommand).CalledInteractive { | ||
| t.Error("did not call Interactive on KoolCreate.createCommand Command") | ||
| } | ||
|
|
||
| if !f.out.(*shell.FakeOutputWriter).CalledSetWriter { | ||
| t.Error("did not call SetWriter") | ||
| } | ||
| } | ||
|
|
||
| func TestInvalidPresetCreateCommand(t *testing.T) { | ||
| f := newFakeKoolCreate() | ||
| cmd := NewCreateCommand(f) | ||
|
|
||
| cmd.SetArgs([]string{"invalid", "my-app"}) | ||
|
|
||
| if err := cmd.Execute(); err != nil { | ||
| t.Errorf("unexpected error executing preset command; error: %v", err) | ||
| } | ||
|
|
||
| if !f.parser.(*presets.FakeParser).CalledLoadPresets { | ||
| t.Error("did not call parser.LoadPresets") | ||
| } | ||
|
|
||
| if !f.parser.(*presets.FakeParser).CalledExists { | ||
| t.Error("did not call parser.Exists") | ||
| } | ||
|
|
||
| if !f.out.(*shell.FakeOutputWriter).CalledError { | ||
| t.Error("did not call Error") | ||
| } | ||
|
|
||
| expected := "Unknown preset invalid" | ||
| output := f.out.(*shell.FakeOutputWriter).Err.Error() | ||
|
|
||
| if expected != output { | ||
| t.Errorf("expecting error '%s', got '%s'", expected, output) | ||
| } | ||
|
|
||
| if !f.exiter.(*shell.FakeExiter).Exited() { | ||
| t.Error("did not call Exit") | ||
| } | ||
| } | ||
|
|
||
| func TestNoArgsNewCreateCommand(t *testing.T) { | ||
| f := newFakeKoolCreate() | ||
|
|
||
| cmd := NewCreateCommand(f) | ||
| cmd.SetOut(bytes.NewBufferString("")) | ||
|
|
||
| if err := cmd.Execute(); err == nil { | ||
| t.Error("expecting no arguments error executing create command") | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.