Skip to content
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

Improved preset names + other tweaks #479

Merged
merged 3 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions commands/cloud_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ func (s *KoolCloudSetup) Execute(args []string) (err error) {

s.Shell().Info(fmt.Sprintf("Setting up service container '%s' for deployment", serviceName))
deployConfig.Services[serviceName] = &cloud.DeployConfigService{
Environment: map[string]string{
"FOO": "bar",
},
Environment: map[string]string{},
}

// handle image/build config
Expand Down
25 changes: 22 additions & 3 deletions commands/preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"kool-dev/kool/core/presets"
"kool-dev/kool/core/shell"
"sort"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -74,9 +75,9 @@ an interactive wizard will present the available options.`,
return
}

func (p *KoolPreset) getPreset(args []string) (preset string, err error) {
func (p *KoolPreset) getPreset(args []string) (pickedPreset string, err error) {
if len(args) == 1 {
preset = args[0]
pickedPreset = args[0]
return
}

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

preset, err = p.promptSelect.Ask("What preset do you want to use", p.presetsParser.GetPresets(tag))
var availablePresets = p.presetsParser.GetPresets(tag)
var presets []string

for _, name := range availablePresets {
presets = append(presets, name)
}

sort.Strings(presets)

if pickedPreset, err = p.promptSelect.Ask("What preset do you want to use", presets); err != nil {
return
}

for preset, name := range availablePresets {
if name == pickedPreset {
pickedPreset = preset
}
}

return
}
4 changes: 2 additions & 2 deletions core/presets/fake_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type FakeParser struct {

MockExists bool
MockGetTags []string
MockGetPresets []string
MockGetPresets map[string]string
MockInstall error
MockCreate error
MockAdd error
Expand All @@ -38,7 +38,7 @@ func (f *FakeParser) GetTags() (languages []string) {
}

// GetPresets get all presets names
func (f *FakeParser) GetPresets(tag string) (presets []string) {
func (f *FakeParser) GetPresets(tag string) (presets map[string]string) {
f.CalledGetPresets = true
presets = f.MockGetPresets
return
Expand Down
4 changes: 2 additions & 2 deletions core/presets/fake_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func TestFakeParser(t *testing.T) {
t.Error("failed to use mocked Exists function on FakeParser")
}

f.MockGetPresets = []string{"preset"}
f.MockGetPresets = map[string]string{"preset": "preset"}
presets := f.GetPresets("")

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

Expand Down
13 changes: 9 additions & 4 deletions core/presets/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type DefaultParser struct {
type Parser interface {
Exists(string) bool
GetTags() []string
GetPresets(string) []string
GetPresets(string) map[string]string
Install(string) error
Create(string) error
Add(string, shell.Shell) error
Expand Down Expand Up @@ -97,7 +97,7 @@ func (p *DefaultParser) GetTags() (tags []string) {
}

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

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

presets = make(map[string]string, len(entries))

for _, folder = range entries {
data, _ = source.ReadFile(
fmt.Sprintf(presetConfigFile, folder.Name()),
Expand All @@ -116,11 +118,14 @@ func (p *DefaultParser) GetPresets(tag string) (presets []string) {
_ = yaml.Unmarshal(data, config)

if config.HasTag(tag) {
presets = append(presets, folder.Name())
presets[folder.Name()] = folder.Name()

if config.Name != "" {
presets[folder.Name()] = config.Name
}
}
}

sort.Strings(presets)
return
}

Expand Down
2 changes: 2 additions & 0 deletions presets/adonis/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'JS' ]

name: 'AdonisJS'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new Adonis Application
Expand Down
2 changes: 2 additions & 0 deletions presets/codeigniter/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'PHP' ]

name: 'CodeIgniter'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new CodeIgniter Application
Expand Down
2 changes: 2 additions & 0 deletions presets/expressjs/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'JS' ]

name: 'ExpressJS'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new Express Application
Expand Down
2 changes: 2 additions & 0 deletions presets/golang-cli/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'Golang' ]

name: 'CLI App'

# Preset defines the workflow for installing this preset in the current working directory
preset:
- name: 'Copy basic config files'
Expand Down
2 changes: 2 additions & 0 deletions presets/hugo/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'Static' ]

name: 'Hugo'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new Hugo website
Expand Down
2 changes: 2 additions & 0 deletions presets/laravel+octane/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'PHP' ]

name: 'Laravel Octane'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
# picks what engine to use
Expand Down
2 changes: 2 additions & 0 deletions presets/laravel/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'PHP' ]

name: 'Laravel'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new Laravel Application
Expand Down
2 changes: 2 additions & 0 deletions presets/nest+next/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'Typescript' ]

name: 'NestJS + NextJS (monorepo)'

# Create defines the workflow for creating a new Project
# where this preset can then be installed
create:
Expand Down
4 changes: 3 additions & 1 deletion presets/nestjs/config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'TS' ]
tags: [ 'Typescript' ]

name: 'NestJS'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
Expand Down
2 changes: 2 additions & 0 deletions presets/nextjs/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'JS' ]

name: 'NextJS'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new NextJS Application
Expand Down
2 changes: 2 additions & 0 deletions presets/nginx/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'Static' ]

name: 'Nginx'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new NGINX Application
Expand Down
2 changes: 2 additions & 0 deletions presets/nodejs/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'JS' ]

name: 'Hello World'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new Laravel Application
Expand Down
2 changes: 2 additions & 0 deletions presets/nuxtjs/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'JS' ]

name: 'NuxtJS'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new Nuxt Application
Expand Down
3 changes: 3 additions & 0 deletions presets/php/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'PHP' ]

# Name of the preset
name: 'Hello World (PHP+Nginx)'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new PHP Application
Expand Down
2 changes: 2 additions & 0 deletions presets/symfony/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'PHP' ]

name: 'Symfony'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new Symfony Application
Expand Down
2 changes: 2 additions & 0 deletions presets/wordpress/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Which tags are related to this preset; used for branching the choices on preset wizard
tags: [ 'PHP' ]

name: 'Wordpress'

# Create defines the workflow for creating a new Project where this preset can then be installed
create:
- name: Creating new Wordpress Application
Expand Down