-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.go
More file actions
77 lines (61 loc) · 1.87 KB
/
Copy pathcli.go
File metadata and controls
77 lines (61 loc) · 1.87 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
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
package main
import (
"context"
"fmt"
"os"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/solerf/gg/github"
"github.com/solerf/gg/tui"
)
type ListCmd struct {
}
type CreateCmd struct {
RepositoryName string `required:"" short:"r" help:"GitHub new repository name"`
Visibility string `option:"" optional:"" short:"v" default:"public" enum:"public,private" help:"GitHub new repository visibility (private|public)"`
}
type gg struct {
List ListCmd `cmd:"" help:"list repositories and allow cloning"`
Create CreateCmd `cmd:"" help:"create a new repository at remote"`
HomeDir string `optional:"" type:"path" short:"d" default:"$HOME" env:"HOME" help:"$HOME directory"`
User string `required:"" type:"string" short:"u" help:"GitHub username"`
PtaPath string `optional:"" type:"path" help:"Absolute path to user's PTA location"`
}
var description = "Details from GitHub user repositories"
var cli = &gg{}
func (l *ListCmd) Run(gg *gg) error {
// the gg is auto injected
curDir, err := os.Getwd()
if err != nil {
return err
}
client, err := github.NewClient(gg.HomeDir, gg.PtaPath, gg.User)
if err != nil {
return err
}
model, err := tui.NewModel(curDir, client)
if err != nil {
return err
}
if _, err = tea.NewProgram(model).Run(); err != nil {
return fmt.Errorf("running tui: %w", err)
}
return nil
}
func (c *CreateCmd) Run(gg *gg) error {
// the gg is auto injected
client, err := github.NewClient(gg.HomeDir, gg.PtaPath, gg.User)
if err != nil {
return err
}
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()
repository, err := client.CreateRepository(ctx, c.RepositoryName, c.Visibility != "public")
if err != nil {
return err
}
fmt.Printf("Created repository %s\n", repository.FullName)
fmt.Printf("- %s\n", repository.HtmlUrl)
fmt.Printf("- %s\n", repository.CloneUrl)
return nil
}