Debian Codegraph @

examples/gh/create.go

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