-
Notifications
You must be signed in to change notification settings - Fork 194
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 #1449 from merico-dev/mvp
feat: new commands support: start/create
- Loading branch information
Showing
9 changed files
with
349 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/devstream-io/devstream/internal/pkg/create" | ||
) | ||
|
||
var createCMD = &cobra.Command{ | ||
Use: "create", | ||
Short: "create", | ||
Long: `create.`, | ||
Run: createCMDFunc, | ||
} | ||
|
||
func createCMDFunc(cmd *cobra.Command, args []string) { | ||
err := create.Create() | ||
if err != nil { | ||
log.Panic(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
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 main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/devstream-io/devstream/internal/pkg/start" | ||
"github.com/devstream-io/devstream/pkg/util/log" | ||
) | ||
|
||
var startCMD = &cobra.Command{ | ||
Use: "start", | ||
Short: "start", | ||
Long: `start.`, | ||
Run: startCMDFunc, | ||
} | ||
|
||
func startCMDFunc(_ *cobra.Command, _ []string) { | ||
err := start.Start() | ||
if err != nil { | ||
log.Fatal(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
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,41 @@ | ||
package create | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func Create() error { | ||
helloMsg := func() { | ||
fmt.Println("I'll scaffold a new repository for you.") | ||
time.Sleep(time.Second) | ||
fmt.Println("Are you ready?") | ||
time.Sleep(time.Second) | ||
fmt.Println("Let's get started.") | ||
time.Sleep(time.Second) | ||
} | ||
helloMsg() | ||
|
||
lang, err := getLanguage() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
time.Sleep(time.Second) | ||
fmt.Println("\nPlease choose a framework next.") | ||
time.Sleep(time.Second) | ||
|
||
fram, err := getFramework() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return createRepo(lang, fram) | ||
// TODO(daniel-hutao): cicd | ||
} | ||
|
||
// TODO(daniel-hutao): support python/flask first | ||
func createRepo(lang, fram string) error { | ||
fmt.Printf("Lang: %s, Fram: %s\n", lang, fram) | ||
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,56 @@ | ||
package create | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/manifoldco/promptui" | ||
) | ||
|
||
type framework struct { | ||
Name string | ||
} | ||
|
||
//TODO(daniel-hutao): support Python first | ||
func getFramework() (string, error) { | ||
frameworks := []framework{ | ||
{Name: "flask"}, | ||
{Name: "django"}, | ||
} | ||
|
||
templates := &promptui.SelectTemplates{ | ||
Label: "{{ . }}?", | ||
Active: "\U0001F336 {{ .Name | cyan }}", | ||
Inactive: " {{ .Name | cyan }}", | ||
Selected: "\U0001F336 {{ .Name | red | cyan }}", | ||
Details: ` | ||
--------- Framework ---------- | ||
{{ "Name:" | faint }} {{ .Name }}`, | ||
} | ||
|
||
searcher := func(input string, index int) bool { | ||
pepper := frameworks[index] | ||
name := strings.Replace(strings.ToLower(pepper.Name), " ", "", -1) | ||
input = strings.Replace(strings.ToLower(input), " ", "", -1) | ||
|
||
return strings.Contains(name, input) | ||
} | ||
|
||
prompt := promptui.Select{ | ||
Label: "Choose your framework", | ||
Items: frameworks, | ||
Templates: templates, | ||
Size: 4, | ||
Searcher: searcher, | ||
} | ||
|
||
i, _, err := prompt.Run() | ||
|
||
if err != nil { | ||
return "", fmt.Errorf("got unsupported framework") | ||
} | ||
|
||
retFram := frameworks[i].Name | ||
fmt.Printf("You choosed: %s.\n", retFram) | ||
return retFram, 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,58 @@ | ||
package create | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/manifoldco/promptui" | ||
) | ||
|
||
type language struct { | ||
Name string | ||
} | ||
|
||
func getLanguage() (string, error) { | ||
languages := []language{ | ||
{Name: "Python"}, | ||
{Name: "Java"}, | ||
{Name: "Go"}, | ||
{Name: "Node.js"}, | ||
{Name: "C++"}, | ||
} | ||
|
||
templates := &promptui.SelectTemplates{ | ||
Label: "{{ . }}?", | ||
Active: "\U0001F336 {{ .Name | cyan }}", | ||
Inactive: " {{ .Name | cyan }}", | ||
Selected: "\U0001F336 {{ .Name | red | cyan }}", | ||
Details: ` | ||
--------- Language ---------- | ||
{{ "Name:" | faint }} {{ .Name }}`, | ||
} | ||
|
||
searcher := func(input string, index int) bool { | ||
pepper := languages[index] | ||
name := strings.Replace(strings.ToLower(pepper.Name), " ", "", -1) | ||
input = strings.Replace(strings.ToLower(input), " ", "", -1) | ||
|
||
return strings.Contains(name, input) | ||
} | ||
|
||
prompt := promptui.Select{ | ||
Label: "Choose your language", | ||
Items: languages, | ||
Templates: templates, | ||
Size: 4, | ||
Searcher: searcher, | ||
} | ||
|
||
i, _, err := prompt.Run() | ||
|
||
if err != nil { | ||
return "", fmt.Errorf("got unsupported language") | ||
} | ||
|
||
retLang := languages[i].Name | ||
fmt.Printf("You choosed: %s.\n", retLang) | ||
return retLang, nil | ||
} |
Oops, something went wrong.