-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (39 loc) · 1.09 KB
/
main.go
File metadata and controls
47 lines (39 loc) · 1.09 KB
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
package main
import (
"flag"
"fmt"
"os"
tea "github.com/charmbracelet/bubbletea"
"github.com/common-creation/backlog-tui/internal/config"
"github.com/common-creation/backlog-tui/internal/ui"
)
func main() {
profile := flag.String("profile", "", "profile name from ~/.backlog/credentials")
open := flag.String("open", "", "issue key to open directly (requires --profile)")
flag.Parse()
if *open != "" && *profile == "" {
fmt.Fprintln(os.Stderr, "Error: --open requires --profile")
os.Exit(1)
}
creds, err := config.LoadCredentials()
if err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
if len(creds.Profiles) == 0 {
fmt.Fprintln(os.Stderr, "No profiles found in ~/.backlog/credentials")
os.Exit(1)
}
if *profile != "" {
if _, ok := creds.GetProfile(*profile); !ok {
fmt.Fprintf(os.Stderr, "Profile %q not found in ~/.backlog/credentials\n", *profile)
os.Exit(1)
}
}
m := ui.NewApp(creds, *profile, *open)
p := tea.NewProgram(m, tea.WithAltScreen())
if _, err := p.Run(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
}
}