1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
package main
import (
"fmt"
"log"
"os"
"github.com/charmbracelet/huh"
"github.com/charmbracelet/huh/spinner"
"github.com/charmbracelet/lipgloss"
)
type Action int
const (
Cancel Action = iota
Push
Fork
Skip
)
var highlight = lipgloss.NewStyle().Foreground(lipgloss.Color("#00D7D7"))
func main() {
var action Action
spinnerStyle := lipgloss.NewStyle().Foreground(lipgloss.Color("4"))
repo := "charmbracelet/huh"
theme := huh.ThemeBase16()
theme.FieldSeparator = lipgloss.NewStyle().SetString("\n")
theme.Help.FullKey.MarginTop(1)
f := huh.NewForm(
huh.NewGroup(
huh.NewSelect[Action]().
Value(&action).
Options(
huh.NewOption(repo, Push),
huh.NewOption("Create a fork of "+repo, Fork),
huh.NewOption("Skip pushing the branch", Skip),
huh.NewOption("Cancel", Cancel),
).
Title("Where should we push the 'feature' branch?"),
),
).WithTheme(theme)
err := f.Run()
if err != nil {
log.Fatal(err)
}
switch action {
case Push:
_ = spinner.New().Title("Pushing to charmbracelet/huh").Style(spinnerStyle).Run()
fmt.Println("Pushed to charmbracelet/huh")
case Fork:
fmt.Println("Creating a fork of charmbracelet/huh...")
case Skip:
fmt.Println("Skipping pushing the branch...")
case Cancel:
fmt.Println("Cancelling...")
os.Exit(1)
}
fmt.Printf("Creating pull request for %s into %s in %s\n", highlight.Render("test"), highlight.Render("main"), repo)
var nextAction string
f = huh.NewForm(
huh.NewGroup(
huh.NewInput().
Title("Title ").
Prompt("").
Inline(true),
huh.NewText().
Title("Body"),
),
huh.NewGroup(
huh.NewSelect[string]().
Options(huh.NewOptions("Submit", "Submit as draft", "Continue in browser", "Add metadata", "Cancel")...).
Title("What's next?").Value(&nextAction),
),
).WithTheme(theme)
err = f.Run()
if err != nil {
log.Fatal(err)
}
if nextAction == "Submit" {
_ = spinner.New().Title("Submitting...").Style(spinnerStyle).Run()
fmt.Println("Pull request submitted!")
}
}
|