Skip to content

Commit

Permalink
short cli flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Ujstor committed Feb 2, 2025
1 parent 230a910 commit bb6e27f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
1 change: 1 addition & 0 deletions blueprint-ui/cmd/web/components/folderstructure.templ
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type OptionsStruct struct {
SelectedDB string
SelectGit string
AdvancedOptions []string
ShortFlags bool
}

func contains(slice []string, value string) bool {
Expand Down
59 changes: 46 additions & 13 deletions blueprint-ui/cmd/web/components/form.templ
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package components

import "strings"

type FeatureTuple struct {
Expand All @@ -7,24 +8,42 @@ type FeatureTuple struct {
}

func GetCommandString(options OptionsStruct) string {
var command string

projectName := strings.ReplaceAll(options.ProjectName, " ", "_")
if projectName == "" {
projectName = "my_project"
}
command := "go-blueprint create --name " + projectName + " --framework " + options.SelectedBackend
if options.SelectedDB != "none" {
command += " --driver " + options.SelectedDB
} else {
command += " --driver none"
}
if len(options.AdvancedOptions) > 0 {
command += " --advanced"
}
for _, opt := range options.AdvancedOptions {
command += " --feature " + opt
}
if options.ShortFlags { // Short format when toggle is checked
command = "go-blueprint create -n " + projectName + " -f " + options.SelectedBackend
if options.SelectedDB != "none" {
command += " -d " + options.SelectedDB
} else {
command += " -d none"
}
if len(options.AdvancedOptions) > 0 {
command += " -a"
}
for _, opt := range options.AdvancedOptions {
command += " --feature " + opt
}
command += " -g " + options.SelectGit

command += " --git " + options.SelectGit
} else { // Long format (default)
command = "go-blueprint create --name " + projectName + " --framework " + options.SelectedBackend
if options.SelectedDB != "none" {
command += " --driver " + options.SelectedDB
} else {
command += " --driver none"
}
if len(options.AdvancedOptions) > 0 {
command += " --advanced"
}
for _, opt := range options.AdvancedOptions {
command += " --feature " + opt
}
command += " --git " + options.SelectGit
}

return command
}
Expand Down Expand Up @@ -71,6 +90,20 @@ var options = OptionsStruct{

templ Form() {
<form class="space-y-2" hx-boost="true" action="/update_structure" hx-trigger="submit" hx-target="#results">
<div class="flex justify-end mb-4">
<label class="inline-flex items-center cursor-pointer">
<input
type="checkbox"
id="shortFlags"
name="shortFlags"
class="sr-only peer"
hx-post="/update_structure"
hx-target="#results"
/>
<div class="relative w-11 h-6 bg-gray-300 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-indigo-200 rounded-full peer peer-checked:after:translate-x-full rtl:peer-checked:after:-translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:start-[2px] after:bg-white after:border-gray-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-indigo-600"></div>
<span class="ms-3 text-sm font-medium text-gray-900">Short CLI Flags</span>
</label>
</div>
<div class="mt-4">
<label
for="projectName"
Expand Down
1 change: 1 addition & 0 deletions blueprint-ui/cmd/web/update_structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func UpdateStructureHandler(w http.ResponseWriter, r *http.Request) {
SelectedDB: r.FormValue("database"),
SelectGit: r.FormValue("git"),
AdvancedOptions: filteredOptions,
ShortFlags: r.FormValue("shortFlags") == "on",
}

commandStr := components.GetCommandString(options)
Expand Down

0 comments on commit bb6e27f

Please sign in to comment.