Skip to content

Commit 852c3f0

Browse files
authored
Merge pull request #479 from kool-dev/tweaks
Improved preset names + other tweaks
2 parents a0a5b5b + df2f0c3 commit 852c3f0

File tree

21 files changed

+70
-15
lines changed

21 files changed

+70
-15
lines changed

commands/cloud_setup.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ func (s *KoolCloudSetup) Execute(args []string) (err error) {
9090

9191
s.Shell().Info(fmt.Sprintf("Setting up service container '%s' for deployment", serviceName))
9292
deployConfig.Services[serviceName] = &cloud.DeployConfigService{
93-
Environment: map[string]string{
94-
"FOO": "bar",
95-
},
93+
Environment: map[string]string{},
9694
}
9795

9896
// handle image/build config

commands/preset.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"kool-dev/kool/core/presets"
66
"kool-dev/kool/core/shell"
7+
"sort"
78

89
"github.com/spf13/cobra"
910
)
@@ -74,9 +75,9 @@ an interactive wizard will present the available options.`,
7475
return
7576
}
7677

77-
func (p *KoolPreset) getPreset(args []string) (preset string, err error) {
78+
func (p *KoolPreset) getPreset(args []string) (pickedPreset string, err error) {
7879
if len(args) == 1 {
79-
preset = args[0]
80+
pickedPreset = args[0]
8081
return
8182
}
8283

@@ -90,6 +91,24 @@ func (p *KoolPreset) getPreset(args []string) (preset string, err error) {
9091
return
9192
}
9293

93-
preset, err = p.promptSelect.Ask("What preset do you want to use", p.presetsParser.GetPresets(tag))
94+
var availablePresets = p.presetsParser.GetPresets(tag)
95+
var presets []string
96+
97+
for _, name := range availablePresets {
98+
presets = append(presets, name)
99+
}
100+
101+
sort.Strings(presets)
102+
103+
if pickedPreset, err = p.promptSelect.Ask("What preset do you want to use", presets); err != nil {
104+
return
105+
}
106+
107+
for preset, name := range availablePresets {
108+
if name == pickedPreset {
109+
pickedPreset = preset
110+
}
111+
}
112+
94113
return
95114
}

core/presets/fake_parser.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type FakeParser struct {
1313

1414
MockExists bool
1515
MockGetTags []string
16-
MockGetPresets []string
16+
MockGetPresets map[string]string
1717
MockInstall error
1818
MockCreate error
1919
MockAdd error
@@ -38,7 +38,7 @@ func (f *FakeParser) GetTags() (languages []string) {
3838
}
3939

4040
// GetPresets get all presets names
41-
func (f *FakeParser) GetPresets(tag string) (presets []string) {
41+
func (f *FakeParser) GetPresets(tag string) (presets map[string]string) {
4242
f.CalledGetPresets = true
4343
presets = f.MockGetPresets
4444
return

core/presets/fake_parser_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ func TestFakeParser(t *testing.T) {
1515
t.Error("failed to use mocked Exists function on FakeParser")
1616
}
1717

18-
f.MockGetPresets = []string{"preset"}
18+
f.MockGetPresets = map[string]string{"preset": "preset"}
1919
presets := f.GetPresets("")
2020

21-
if !f.CalledGetPresets || len(presets) != 1 || presets[0] != "preset" {
21+
if !f.CalledGetPresets || len(presets) != 1 || presets["preset"] != "preset" {
2222
t.Error("failed to use mocked GetPresets function on FakeParser")
2323
}
2424

core/presets/parser.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type DefaultParser struct {
4040
type Parser interface {
4141
Exists(string) bool
4242
GetTags() []string
43-
GetPresets(string) []string
43+
GetPresets(string) map[string]string
4444
Install(string) error
4545
Create(string) error
4646
Add(string, shell.Shell) error
@@ -97,7 +97,7 @@ func (p *DefaultParser) GetTags() (tags []string) {
9797
}
9898

9999
// GetPresets look up all presets IDs with the given tag
100-
func (p *DefaultParser) GetPresets(tag string) (presets []string) {
100+
func (p *DefaultParser) GetPresets(tag string) (presets map[string]string) {
101101
var (
102102
entries []fs.DirEntry
103103
folder fs.DirEntry
@@ -107,6 +107,8 @@ func (p *DefaultParser) GetPresets(tag string) (presets []string) {
107107

108108
entries, _ = source.ReadDir("presets")
109109

110+
presets = make(map[string]string, len(entries))
111+
110112
for _, folder = range entries {
111113
data, _ = source.ReadFile(
112114
fmt.Sprintf(presetConfigFile, folder.Name()),
@@ -116,11 +118,14 @@ func (p *DefaultParser) GetPresets(tag string) (presets []string) {
116118
_ = yaml.Unmarshal(data, config)
117119

118120
if config.HasTag(tag) {
119-
presets = append(presets, folder.Name())
121+
presets[folder.Name()] = folder.Name()
122+
123+
if config.Name != "" {
124+
presets[folder.Name()] = config.Name
125+
}
120126
}
121127
}
122128

123-
sort.Strings(presets)
124129
return
125130
}
126131

presets/adonis/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Which tags are related to this preset; used for branching the choices on preset wizard
22
tags: [ 'JS' ]
33

4+
name: 'AdonisJS'
5+
46
# Create defines the workflow for creating a new Project where this preset can then be installed
57
create:
68
- name: Creating new Adonis Application

presets/codeigniter/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Which tags are related to this preset; used for branching the choices on preset wizard
22
tags: [ 'PHP' ]
33

4+
name: 'CodeIgniter'
5+
46
# Create defines the workflow for creating a new Project where this preset can then be installed
57
create:
68
- name: Creating new CodeIgniter Application

presets/expressjs/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Which tags are related to this preset; used for branching the choices on preset wizard
22
tags: [ 'JS' ]
33

4+
name: 'ExpressJS'
5+
46
# Create defines the workflow for creating a new Project where this preset can then be installed
57
create:
68
- name: Creating new Express Application

presets/golang-cli/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Which tags are related to this preset; used for branching the choices on preset wizard
22
tags: [ 'Golang' ]
33

4+
name: 'CLI App'
5+
46
# Preset defines the workflow for installing this preset in the current working directory
57
preset:
68
- name: 'Copy basic config files'

presets/hugo/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Which tags are related to this preset; used for branching the choices on preset wizard
22
tags: [ 'Static' ]
33

4+
name: 'Hugo'
5+
46
# Create defines the workflow for creating a new Project where this preset can then be installed
57
create:
68
- name: Creating new Hugo website

0 commit comments

Comments
 (0)