From 7088c5bb1c297860e9bfeb5c71a7fdfb0c0b420b Mon Sep 17 00:00:00 2001 From: fabriciojs Date: Fri, 27 Oct 2023 23:04:41 -0300 Subject: [PATCH] presets: improving names display --- commands/preset.go | 21 ++++++++++++++++++++- core/presets/fake_parser.go | 4 ++-- core/presets/fake_parser_test.go | 4 ++-- core/presets/parser.go | 13 +++++++++---- presets/adonis/config.yml | 2 ++ presets/codeigniter/config.yml | 2 ++ presets/expressjs/config.yml | 2 ++ presets/golang-cli/config.yml | 2 ++ presets/hugo/config.yml | 2 ++ presets/laravel+octane/config.yml | 2 ++ presets/laravel/config.yml | 2 ++ presets/nest+next/config.yml | 2 ++ presets/nestjs/config.yml | 4 +++- presets/nextjs/config.yml | 2 ++ presets/nginx/config.yml | 2 ++ presets/nodejs/config.yml | 2 ++ presets/nuxtjs/config.yml | 2 ++ presets/php/config.yml | 3 +++ presets/symfony/config.yml | 2 ++ presets/wordpress/config.yml | 2 ++ 20 files changed, 67 insertions(+), 10 deletions(-) diff --git a/commands/preset.go b/commands/preset.go index 49de7196..eca8ef53 100644 --- a/commands/preset.go +++ b/commands/preset.go @@ -4,6 +4,7 @@ import ( "fmt" "kool-dev/kool/core/presets" "kool-dev/kool/core/shell" + "sort" "github.com/spf13/cobra" ) @@ -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) + + var pickedPreset string + + pickedPreset, err = p.promptSelect.Ask("What preset do you want to use", presets) + + for preset, name := range availablePresets { + if name == pickedPreset { + pickedPreset = preset + } + } + return } diff --git a/core/presets/fake_parser.go b/core/presets/fake_parser.go index 2e92bbce..843dead8 100644 --- a/core/presets/fake_parser.go +++ b/core/presets/fake_parser.go @@ -13,7 +13,7 @@ type FakeParser struct { MockExists bool MockGetTags []string - MockGetPresets []string + MockGetPresets map[string]string MockInstall error MockCreate error MockAdd error @@ -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 diff --git a/core/presets/fake_parser_test.go b/core/presets/fake_parser_test.go index a5233398..cf41d2a1 100644 --- a/core/presets/fake_parser_test.go +++ b/core/presets/fake_parser_test.go @@ -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") } diff --git a/core/presets/parser.go b/core/presets/parser.go index 856d3bae..ee67a544 100644 --- a/core/presets/parser.go +++ b/core/presets/parser.go @@ -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 @@ -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 @@ -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()), @@ -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 } diff --git a/presets/adonis/config.yml b/presets/adonis/config.yml index bba85157..59c05a82 100644 --- a/presets/adonis/config.yml +++ b/presets/adonis/config.yml @@ -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 diff --git a/presets/codeigniter/config.yml b/presets/codeigniter/config.yml index 4cba78f7..5babeca0 100644 --- a/presets/codeigniter/config.yml +++ b/presets/codeigniter/config.yml @@ -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 diff --git a/presets/expressjs/config.yml b/presets/expressjs/config.yml index 7fbad936..f894a5fd 100644 --- a/presets/expressjs/config.yml +++ b/presets/expressjs/config.yml @@ -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 diff --git a/presets/golang-cli/config.yml b/presets/golang-cli/config.yml index 32f193e5..0fe2dbbc 100644 --- a/presets/golang-cli/config.yml +++ b/presets/golang-cli/config.yml @@ -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' diff --git a/presets/hugo/config.yml b/presets/hugo/config.yml index 1aff3aa1..ea0a506c 100644 --- a/presets/hugo/config.yml +++ b/presets/hugo/config.yml @@ -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 diff --git a/presets/laravel+octane/config.yml b/presets/laravel+octane/config.yml index 107b23b2..a450fe22 100644 --- a/presets/laravel+octane/config.yml +++ b/presets/laravel+octane/config.yml @@ -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 diff --git a/presets/laravel/config.yml b/presets/laravel/config.yml index 6b86d0d7..0f2853ff 100644 --- a/presets/laravel/config.yml +++ b/presets/laravel/config.yml @@ -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 diff --git a/presets/nest+next/config.yml b/presets/nest+next/config.yml index 599323b9..9f9a1e0b 100644 --- a/presets/nest+next/config.yml +++ b/presets/nest+next/config.yml @@ -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: diff --git a/presets/nestjs/config.yml b/presets/nestjs/config.yml index 5e6eea87..997376bb 100644 --- a/presets/nestjs/config.yml +++ b/presets/nestjs/config.yml @@ -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: diff --git a/presets/nextjs/config.yml b/presets/nextjs/config.yml index 1211d03f..187ccd87 100644 --- a/presets/nextjs/config.yml +++ b/presets/nextjs/config.yml @@ -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 diff --git a/presets/nginx/config.yml b/presets/nginx/config.yml index ba7d47ba..6a05cd05 100644 --- a/presets/nginx/config.yml +++ b/presets/nginx/config.yml @@ -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 diff --git a/presets/nodejs/config.yml b/presets/nodejs/config.yml index e0b9d56d..5a36abf6 100644 --- a/presets/nodejs/config.yml +++ b/presets/nodejs/config.yml @@ -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 diff --git a/presets/nuxtjs/config.yml b/presets/nuxtjs/config.yml index 2498ebab..e2f95777 100644 --- a/presets/nuxtjs/config.yml +++ b/presets/nuxtjs/config.yml @@ -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 diff --git a/presets/php/config.yml b/presets/php/config.yml index 228f2c87..daf8f67d 100644 --- a/presets/php/config.yml +++ b/presets/php/config.yml @@ -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 diff --git a/presets/symfony/config.yml b/presets/symfony/config.yml index 443db9e3..fb0929cd 100644 --- a/presets/symfony/config.yml +++ b/presets/symfony/config.yml @@ -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 diff --git a/presets/wordpress/config.yml b/presets/wordpress/config.yml index 9a95d933..9cb4a85e 100644 --- a/presets/wordpress/config.yml +++ b/presets/wordpress/config.yml @@ -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