-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
55 lines (46 loc) · 1.16 KB
/
main.go
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
package main
import (
"context"
"errors"
"os"
"github.com/charmbracelet/log"
"github.com/cli/go-gh/v2"
"github.com/flexwie/ghs/pkg"
"github.com/urfave/cli/v2"
)
func init() {
var logger *log.Logger = log.NewWithOptions(os.Stdout, log.Options{
ReportTimestamp: false,
ReportCaller: false,
Level: log.DebugLevel,
})
log.SetDefault(logger)
}
func main() {
app := &cli.App{
Name: "ghs",
Usage: "npx-like script execution for GitHub gists",
SkipFlagParsing: true,
UseShortOptionHandling: true,
UsageText: "ghs <gist name> [arguments/flags...]",
Authors: []*cli.Author{
{Name: "Felix Wieland", Email: "[email protected]"},
},
Action: func(ctx *cli.Context) error {
_, err := gh.Path()
if err != nil {
return errors.New("gh cli is not installed")
}
gist := ctx.Args().Get(0)
if len(gist) == 0 {
return cli.Exit("no gist provided", 2)
}
args := ctx.Args().Slice()[1:]
log.Debug("parsing args", "gist", gist, "args", args)
return pkg.ExecGist(context.Background(), gist, args)
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}