Skip to content

Commit 700efdf

Browse files
committed
move frameworks flag to backed
1 parent b9b62dd commit 700efdf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+216
-172
lines changed

.github/workflows/generate-linter-advanced.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Linting Generated Blueprints Advanced
33
on:
44
pull_request: {}
55
workflow_dispatch: {}
6-
push:
7-
branches:
8-
- cli-refactor
6+
# push:
7+
# branches:
8+
# - cli-refactor
99

1010
jobs:
1111
framework_matrix:

.github/workflows/generate-linter-core.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Linting Generated Blueprints Core
33
on:
44
pull_request: {}
55
workflow_dispatch: {}
6-
push:
7-
branches:
8-
- cli-refactor
6+
# push:
7+
# branches:
8+
# - cli-refactor
99

1010
jobs:
1111
framework_matrix:

.github/workflows/generate-linter-frontend.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Linting Generated Blueprints Advanced
33
on:
44
pull_request: {}
55
workflow_dispatch: {}
6-
push:
7-
branches:
8-
- cli-refactor
6+
# push:
7+
# branches:
8+
# - cli-refactor
99

1010
jobs:
1111
framework_matrix:

.github/workflows/testcontainers.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ name: Integrations Test for the Generated Blueprints
33
on:
44
pull_request: {}
55
workflow_dispatch: {}
6-
push:
7-
branches:
8-
- cli-refactor
6+
# push:
7+
# branches:
8+
# - cli-refactor
99

1010
jobs:
1111
itests_matrix:

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@
77
</div>
88

99
Go Blueprint is a CLI tool that allows users to spin up a Go project with the corresponding structure seamlessly. It also
10-
gives the option to integrate with one of the more popular Go frameworks (and the list is growing with new features)!
10+
gives the option to integrate with one of the more popular Go backends (and the list is growing with new features)!
1111

1212
### Why Would I use this?
1313

1414
- Easy to set up and install
1515
- Have the entire Go structure already established
1616
- Setting up a Go HTTP server (or Fasthttp with Fiber)
17-
- Integrate with a popular frameworks
17+
- Integrate with a popular backends
1818
- Focus on the actual code of your application
1919

2020
## Table of Contents
2121

2222
- [Install](#install)
23-
- [Frameworks Supported](#frameworks-supported)
23+
- [backends Supported](#backends-supported)
2424
- [Database Support](#database-support)
2525
- [Advanced Features](#advanced-features)
2626
- [Blueprint UI](#blueprint-ui)
@@ -64,18 +64,18 @@ go-blueprint create
6464
You can also use the provided flags to set up a project without interacting with the UI.
6565

6666
```bash
67-
go-blueprint create --name my-project --framework gin --driver postgres --git commit
67+
go-blueprint create --name my-project --backend gin --driver postgres --git commit
6868
```
6969

7070
See `go-blueprint create -h` for all the options and shorthands.
7171

72-
<a id="frameworks-supported"></a>
72+
<a id="backends-supported"></a>
7373

7474
<h2>
7575
<picture>
76-
<img src="./public/frameworks.gif?raw=true" width="60px" style="margin-right: 1px;">
76+
<img src="./public/backends.gif?raw=true" width="60px" style="margin-right: 1px;">
7777
</picture>
78-
Frameworks Supported
78+
backends Supported
7979
</h2>
8080

8181
- [Chi](https://github.com/go-chi/chi)
@@ -152,7 +152,7 @@ Blueprint UI is a web application that allows you to create commands for the CLI
152152
Here's an example of setting up a project with a specific database driver:
153153

154154
```bash
155-
go-blueprint create --name my-project --framework gin --driver postgres --git commit
155+
go-blueprint create --name my-project --backend gin --driver postgres --git commit
156156
```
157157

158158
<p align="center">
@@ -206,7 +206,7 @@ go-blueprint create --advanced --feature react
206206
Or all features at once:
207207

208208
```bash
209-
go-blueprint create --name my-project --framework chi --driver mysql --advanced --feature htmx --feature githubaction --feature websocket --feature tailwind --feature docker --git commit --feature react
209+
go-blueprint create --name my-project --backend chi --driver mysql --advanced --feature htmx --feature githubaction --feature websocket --feature tailwind --feature docker --git commit --feature react
210210
```
211211

212212
<p align="center">

cmd/create.go

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,34 @@ var (
4040
)
4141

4242
func init() {
43-
var flagFramework flags.Framework
43+
var flagBackend flags.Backend
4444
var flagDBDriver flags.Database
4545
var frontendFrameworks flags.FrontendFramework
4646
var frontendAdvanced flags.FrontendAdvanced
4747
var advancedFeatures flags.AdvancedFeatures
4848
var flagGit flags.Git
4949
rootCmd.AddCommand(createCmd)
5050

51+
// Main flags
5152
createCmd.Flags().StringP("name", "n", "", "Name of project to create")
52-
createCmd.Flags().VarP(&flagFramework, "framework", "b", fmt.Sprintf("Framework to use. Allowed values: %s", strings.Join(flags.AllowedProjectTypes, ", ")))
53+
createCmd.Flags().VarP(&flagBackend, "backend", "b", fmt.Sprintf("Backend to use. Allowed values: %s", strings.Join(flags.AllowedBackedTypes, ", ")))
5354
createCmd.Flags().VarP(&flagDBDriver, "driver", "d", fmt.Sprintf("Database drivers to use. Allowed values: %s", strings.Join(flags.AllowedDBDrivers, ", ")))
55+
createCmd.Flags().VarP(&flagGit, "git", "g", fmt.Sprintf("Git to use. Allowed values: %s", strings.Join(flags.AllowedGitsOptions, ", ")))
56+
57+
// Frontend flags group
5458
createCmd.Flags().BoolP("frontend", "f", false, "Get prompts for frontend frameworks")
5559
createCmd.Flags().Var(&frontendFrameworks, "frontend-framework", fmt.Sprintf("Frontend framework to use. Allowed values: %s", strings.Join(flags.AllowedFrontendTypes, ", ")))
5660
createCmd.Flags().Var(&frontendAdvanced, "frontend-advanced", fmt.Sprintf("Frontend framework advanced features to use. Allowed values: %s", strings.Join(flags.AllowedFrontendAdvanced, ", ")))
61+
62+
// Advanced features group
5763
createCmd.Flags().BoolP("advanced", "a", false, "Get prompts for advanced features")
5864
createCmd.Flags().Var(&advancedFeatures, "feature", fmt.Sprintf("Advanced feature to use. Allowed values: %s", strings.Join(flags.AllowedAdvancedFeatures, ", ")))
59-
createCmd.Flags().VarP(&flagGit, "git", "g", fmt.Sprintf("Git to use. Allowed values: %s", strings.Join(flags.AllowedGitsOptions, ", ")))
65+
66+
// Mark dependencies for frontend flags
67+
createCmd.MarkFlagsRequiredTogether("frontend", "frontend-framework")
68+
69+
// Mark feature flag as requiring --advanced
70+
createCmd.MarkFlagsRequiredTogether("advanced", "feature")
6071
}
6172

6273
type Options struct {
@@ -95,7 +106,7 @@ var createCmd = &cobra.Command{
95106

96107
// VarP already validates the contents of the framework flag.
97108
// If this flag is filled, it is always valid
98-
flagFramework := flags.Framework(cmd.Flag("framework").Value.String())
109+
flagBackend := flags.Backend(cmd.Flag("backend").Value.String())
99110
flagDBDriver := flags.Database(cmd.Flag("driver").Value.String())
100111
flagFrontendFremwork := flags.FrontendFramework(cmd.Flag("frontend-framework").Value.String())
101112
flagGit := flags.Git(cmd.Flag("git").Value.String())
@@ -116,17 +127,17 @@ var createCmd = &cobra.Command{
116127

117128
project := &program.Project{
118129
ProjectName: flagName,
119-
ProjectType: flagFramework,
130+
ProjectType: flagBackend,
120131
DBDriver: flagDBDriver,
121-
FrameworkMap: make(map[flags.Framework]program.Framework),
132+
BackendMap: make(map[flags.Backend]program.Backend),
122133
DBDriverMap: make(map[flags.Database]program.Driver),
123134
FrontendFramework: flagFrontendFremwork,
124135
FrontendOptions: make(map[string]bool),
125136
AdvancedOptions: make(map[string]bool),
126137
GitOptions: flagGit,
127138
}
128139

129-
steps := steps.InitSteps(flagFramework, flagDBDriver, flagFrontendFremwork, flagGit)
140+
steps := steps.InitSteps(flagBackend, flagDBDriver, flagFrontendFremwork, flagGit)
130141
fmt.Printf("%s\n", logoStyle.Render(logo))
131142

132143
// Advanced option steps:
@@ -177,7 +188,7 @@ var createCmd = &cobra.Command{
177188

178189
if project.ProjectType == "" {
179190
isInteractive = true
180-
step := steps.Steps["framework"]
191+
step := steps.Steps["backend"]
181192
tprogram = tea.NewProgram(multiInput.InitialModelMulti(step.Options, options.ProjectType, step.Headers, project))
182193
if _, err := tprogram.Run(); err != nil {
183194
cobra.CheckErr(textinput.CreateErrorInputModel(err).Err())
@@ -187,11 +198,11 @@ var createCmd = &cobra.Command{
187198
step.Field = options.ProjectType.Choice
188199

189200
// this type casting is always safe since the user interface can
190-
// only pass strings that can be cast to a flags.Framework instance
191-
project.ProjectType = flags.Framework(strings.ToLower(options.ProjectType.Choice))
192-
err := cmd.Flag("framework").Value.Set(project.ProjectType.String())
201+
// only pass strings that can be cast to a flags.Backend instance
202+
project.ProjectType = flags.Backend(strings.ToLower(options.ProjectType.Choice))
203+
err := cmd.Flag("backend").Value.Set(project.ProjectType.String())
193204
if err != nil {
194-
log.Fatal("failed to set the framework flag value", err)
205+
log.Fatal("failed to set the backend flag value", err)
195206
}
196207
}
197208

@@ -357,13 +368,13 @@ var createCmd = &cobra.Command{
357368
}
358369

359370
if options.FrontendAdvanced.Choices["Tailwind"] && options.FrontendFramework.Choice == "Htmx" {
360-
fmt.Println(endingMsgStyle.Render("• Download the tailwind standalone cli wiht Makefile target\n"))
371+
fmt.Println(endingMsgStyle.Render("• Download the tailwind standalone cli with Makefile target\n"))
361372
fmt.Println(endingMsgStyle.Render("• More info about the Tailwind CLI: https://tailwindcss.com/blog/standalone-cli\n"))
362373
}
363374

364375
if options.FrontendFramework.Choice == "Htmx" {
365-
fmt.Println(endingMsgStyle.Render("• Install the templ cli `go install github.com/a-h/templ/cmd/templ@latest` or use Makefile\n"))
366-
fmt.Println(endingMsgStyle.Render("• Generate templ function files by running `templ generate`\n"))
376+
fmt.Println(endingMsgStyle.Render("• Install the templ cli `go install github.com/a-h/templ/cmd/templ@latest`\n"))
377+
fmt.Println(endingMsgStyle.Render("• Generate templ function files by running `templ generate` or use Makefile for both steps\n"))
367378
}
368379

369380
if isInteractive {

cmd/flags/backend.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package flags
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
)
7+
8+
type Backend string
9+
10+
// These are all the current backends supported. If you want to add one, you
11+
// can simply copy and paste a line here. Do not forget to also add it into the
12+
// AllowedBackedTypes slice too!
13+
const (
14+
Chi Backend = "chi"
15+
Gin Backend = "gin"
16+
Fiber Backend = "fiber"
17+
GorillaMux Backend = "gorilla/mux"
18+
HttpRouter Backend = "httprouter"
19+
StandardLibrary Backend = "standard-library"
20+
Echo Backend = "echo"
21+
)
22+
23+
var AllowedBackedTypes = []string{string(Chi), string(Gin), string(Fiber), string(GorillaMux), string(HttpRouter), string(StandardLibrary), string(Echo)}
24+
25+
func (f Backend) String() string {
26+
return string(f)
27+
}
28+
29+
func (f *Backend) Type() string {
30+
return "Backend"
31+
}
32+
33+
func (f *Backend) Set(value string) error {
34+
// Contains isn't available in 1.20 yet
35+
// if AllowedBackedTypes.Contains(value) {
36+
for _, project := range AllowedBackedTypes {
37+
if project == value {
38+
*f = Backend(value)
39+
return nil
40+
}
41+
}
42+
43+
return fmt.Errorf("Backend to use. Allowed values: %s", strings.Join(AllowedBackedTypes, ", "))
44+
}

cmd/flags/frameworks.go

Lines changed: 0 additions & 44 deletions
This file was deleted.

cmd/flags/frontendFramework.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type FrontendFramework string
99

1010
// These are all the current frameworks supported. If you want to add one, you
1111
// can simply copy and paste a line here. Do not forget to also add it into the
12-
// AllowedProjectTypes slice too!
12+
// AllowedFrontedTypes slice too!
1313
const (
1414
Htmx FrontendFramework = "htmx"
1515
React FrontendFramework = "react"
@@ -27,7 +27,7 @@ func (f *FrontendFramework) Type() string {
2727

2828
func (f *FrontendFramework) Set(value string) error {
2929
// Contains isn't available in 1.20 yet
30-
// if AllowedProjectTypes.Contains(value) {
30+
// if AllowedFrontedTypes.Contains(value) {
3131
for _, frontendFrameworks := range AllowedFrontendTypes {
3232
if frontendFrameworks == value {
3333
*f = FrontendFramework(value)

0 commit comments

Comments
 (0)