Skip to content

Commit e178b4d

Browse files
authored
Merge pull request #1449 from merico-dev/mvp
feat: new commands support: start/create
2 parents e95ebc7 + 5085194 commit e178b4d

File tree

9 files changed

+349
-2
lines changed

9 files changed

+349
-2
lines changed

cmd/devstream/create.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"log"
5+
6+
"github.com/spf13/cobra"
7+
8+
"github.com/devstream-io/devstream/internal/pkg/create"
9+
)
10+
11+
var createCMD = &cobra.Command{
12+
Use: "create",
13+
Short: "create",
14+
Long: `create.`,
15+
Run: createCMDFunc,
16+
}
17+
18+
func createCMDFunc(cmd *cobra.Command, args []string) {
19+
err := create.Create()
20+
if err != nil {
21+
log.Panic(err)
22+
}
23+
}

cmd/devstream/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ func init() {
4545
rootCMD.AddCommand(listCMD)
4646
rootCMD.AddCommand(showCMD)
4747
rootCMD.AddCommand(upgradeCMD)
48+
49+
rootCMD.AddCommand(startCMD)
50+
rootCMD.AddCommand(createCMD)
4851
}
4952

5053
func initConfig() {

cmd/devstream/start.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package main
2+
3+
import (
4+
"github.com/spf13/cobra"
5+
6+
"github.com/devstream-io/devstream/internal/pkg/start"
7+
"github.com/devstream-io/devstream/pkg/util/log"
8+
)
9+
10+
var startCMD = &cobra.Command{
11+
Use: "start",
12+
Short: "start",
13+
Long: `start.`,
14+
Run: startCMDFunc,
15+
}
16+
17+
func startCMDFunc(_ *cobra.Command, _ []string) {
18+
err := start.Start()
19+
if err != nil {
20+
log.Fatal(err)
21+
}
22+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ require (
2121
github.com/hashicorp/go-cleanhttp v0.5.2
2222
github.com/hashicorp/go-getter v1.6.2
2323
github.com/imdario/mergo v0.3.12
24+
github.com/manifoldco/promptui v0.9.0
2425
github.com/mitchellh/mapstructure v1.5.0
2526
github.com/mittwald/go-helm-client v0.8.4
2627
github.com/onsi/ginkgo/v2 v2.1.4
@@ -83,6 +84,7 @@ require (
8384
github.com/bradleyfalzon/ghinstallation/v2 v2.0.3 // indirect
8485
github.com/cespare/xxhash/v2 v2.1.2 // indirect
8586
github.com/chai2010/gettext-go v0.0.0-20170215093142-bf70f2a70fb1 // indirect
87+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect
8688
github.com/containerd/containerd v1.5.7 // indirect
8789
github.com/cyphar/filepath-securejoin v0.2.2 // indirect
8890
github.com/davecgh/go-spew v1.1.1 // indirect
@@ -171,7 +173,6 @@ require (
171173
github.com/modern-go/reflect2 v1.0.2 // indirect
172174
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
173175
github.com/morikuni/aec v1.0.0 // indirect
174-
github.com/nxadm/tail v1.4.8 // indirect
175176
github.com/opencontainers/go-digest v1.0.0 // indirect
176177
github.com/opencontainers/image-spec v1.0.1 // indirect
177178
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
@@ -223,7 +224,6 @@ require (
223224
gopkg.in/gorp.v1 v1.7.2 // indirect
224225
gopkg.in/inf.v0 v0.9.1 // indirect
225226
gopkg.in/ini.v1 v1.62.0 // indirect
226-
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
227227
gopkg.in/warnings.v0 v0.1.2 // indirect
228228
gopkg.in/yaml.v2 v2.4.0 // indirect
229229
k8s.io/apiextensions-apiserver v0.22.4 // indirect

go.sum

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,11 @@ github.com/checkpoint-restore/go-criu/v5 v5.0.0/go.mod h1:cfwC0EG7HMUenopBsUf9d8
258258
github.com/cheggaaa/pb v1.0.27/go.mod h1:pQciLPpbU0oxA0h+VJYYLxO+XeDQb5pZijXscXHm81s=
259259
github.com/cheggaaa/pb v1.0.29 h1:FckUN5ngEk2LpvuG0fw1GEFx6LtyY2pWI/Z2QgCnEYo=
260260
github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30=
261+
github.com/chzyer/logex v1.1.10 h1:Swpa1K6QvQznwJRcfTfQJmTE72DqScAa40E+fbHEXEE=
261262
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
263+
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e h1:fY5BOSpyZCqRo5OhCuC+XN+r/bBCmeuuJtjz+bCNIf8=
262264
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
265+
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWsoZXJNW3xEE4JJyHa5Q25/sd8=
263266
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
264267
github.com/cilium/ebpf v0.0.0-20200110133405-4032b1d8aae3/go.mod h1:MA5e5Lr8slmEg9bt0VpxxWqJlO4iwu3FBdHUzV7wQVg=
265268
github.com/cilium/ebpf v0.0.0-20200702112145-1c8d4c9ef775/go.mod h1:7cR51M8ViRLIdUjrmSXlK9pkrsDlLHbO8jiB8X8JnOc=
@@ -940,6 +943,8 @@ github.com/mailru/easyjson v0.7.6/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
940943
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
941944
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
942945
github.com/malexdev/utfutil v0.0.0-20180510171754-00c8d4a8e7a8/go.mod h1:UtpLyb/EupVKXF/N0b4NRe1DNg+QYJsnsHQ038romhM=
946+
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
947+
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
943948
github.com/markbates/errx v1.1.0 h1:QDFeR+UP95dO12JgW+tgi2UVfo0V8YBHiUIOaeBPiEI=
944949
github.com/markbates/errx v1.1.0/go.mod h1:PLa46Oex9KNbVDZhKel8v1OT7hD5JZ2eI7AHhA0wswc=
945950
github.com/markbates/oncer v1.0.0 h1:E83IaVAHygyndzPimgUYJjbshhDTALZyXxvk9FOlQRY=

internal/pkg/create/create.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package create
2+
3+
import (
4+
"fmt"
5+
"time"
6+
)
7+
8+
func Create() error {
9+
helloMsg := func() {
10+
fmt.Println("I'll scaffold a new repository for you.")
11+
time.Sleep(time.Second)
12+
fmt.Println("Are you ready?")
13+
time.Sleep(time.Second)
14+
fmt.Println("Let's get started.")
15+
time.Sleep(time.Second)
16+
}
17+
helloMsg()
18+
19+
lang, err := getLanguage()
20+
if err != nil {
21+
return err
22+
}
23+
24+
time.Sleep(time.Second)
25+
fmt.Println("\nPlease choose a framework next.")
26+
time.Sleep(time.Second)
27+
28+
fram, err := getFramework()
29+
if err != nil {
30+
return err
31+
}
32+
33+
return createRepo(lang, fram)
34+
// TODO(daniel-hutao): cicd
35+
}
36+
37+
// TODO(daniel-hutao): support python/flask first
38+
func createRepo(lang, fram string) error {
39+
fmt.Printf("Lang: %s, Fram: %s\n", lang, fram)
40+
return nil
41+
}

internal/pkg/create/framework.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package create
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/manifoldco/promptui"
8+
)
9+
10+
type framework struct {
11+
Name string
12+
}
13+
14+
//TODO(daniel-hutao): support Python first
15+
func getFramework() (string, error) {
16+
frameworks := []framework{
17+
{Name: "flask"},
18+
{Name: "django"},
19+
}
20+
21+
templates := &promptui.SelectTemplates{
22+
Label: "{{ . }}?",
23+
Active: "\U0001F336 {{ .Name | cyan }}",
24+
Inactive: " {{ .Name | cyan }}",
25+
Selected: "\U0001F336 {{ .Name | red | cyan }}",
26+
Details: `
27+
--------- Framework ----------
28+
{{ "Name:" | faint }} {{ .Name }}`,
29+
}
30+
31+
searcher := func(input string, index int) bool {
32+
pepper := frameworks[index]
33+
name := strings.Replace(strings.ToLower(pepper.Name), " ", "", -1)
34+
input = strings.Replace(strings.ToLower(input), " ", "", -1)
35+
36+
return strings.Contains(name, input)
37+
}
38+
39+
prompt := promptui.Select{
40+
Label: "Choose your framework",
41+
Items: frameworks,
42+
Templates: templates,
43+
Size: 4,
44+
Searcher: searcher,
45+
}
46+
47+
i, _, err := prompt.Run()
48+
49+
if err != nil {
50+
return "", fmt.Errorf("got unsupported framework")
51+
}
52+
53+
retFram := frameworks[i].Name
54+
fmt.Printf("You choosed: %s.\n", retFram)
55+
return retFram, nil
56+
}

internal/pkg/create/language.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package create
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/manifoldco/promptui"
8+
)
9+
10+
type language struct {
11+
Name string
12+
}
13+
14+
func getLanguage() (string, error) {
15+
languages := []language{
16+
{Name: "Python"},
17+
{Name: "Java"},
18+
{Name: "Go"},
19+
{Name: "Node.js"},
20+
{Name: "C++"},
21+
}
22+
23+
templates := &promptui.SelectTemplates{
24+
Label: "{{ . }}?",
25+
Active: "\U0001F336 {{ .Name | cyan }}",
26+
Inactive: " {{ .Name | cyan }}",
27+
Selected: "\U0001F336 {{ .Name | red | cyan }}",
28+
Details: `
29+
--------- Language ----------
30+
{{ "Name:" | faint }} {{ .Name }}`,
31+
}
32+
33+
searcher := func(input string, index int) bool {
34+
pepper := languages[index]
35+
name := strings.Replace(strings.ToLower(pepper.Name), " ", "", -1)
36+
input = strings.Replace(strings.ToLower(input), " ", "", -1)
37+
38+
return strings.Contains(name, input)
39+
}
40+
41+
prompt := promptui.Select{
42+
Label: "Choose your language",
43+
Items: languages,
44+
Templates: templates,
45+
Size: 4,
46+
Searcher: searcher,
47+
}
48+
49+
i, _, err := prompt.Run()
50+
51+
if err != nil {
52+
return "", fmt.Errorf("got unsupported language")
53+
}
54+
55+
retLang := languages[i].Name
56+
fmt.Printf("You choosed: %s.\n", retLang)
57+
return retLang, nil
58+
}

0 commit comments

Comments
 (0)