-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
54 lines (45 loc) · 1.28 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
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
packagecloud "github.com/atotto/packagecloud/api/v1"
"github.com/google/subcommands"
)
var (
PACKAGECLOUD_TOKEN = os.Getenv("PACKAGECLOUD_TOKEN")
)
func main() {
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGTERM, syscall.SIGINT)
ctx, cancel := context.WithCancel(context.Background())
subcommands.Register(subcommands.HelpCommand(), "")
subcommands.Register(pushPackageCommand, "package")
subcommands.Register(pullPackageCommand, "package")
subcommands.Register(searchPackageCommand, "package")
subcommands.Register(promotePackageCommand, "package")
subcommands.Register(deletePackageCommand, "package")
subcommands.Register(helpDistroCommand, "help")
flag.Parse()
if PACKAGECLOUD_TOKEN == "" {
fmt.Fprintf(flag.CommandLine.Output(), `
Please set an environment variable with the name PACKAGECLOUD_TOKEN, containing the value of a packagecloud API token.
You can find a packagecloud API token at https://packagecloud.io/api_token .
`)
log.Println(`PACKAGECLOUD_TOKEN is empty`)
os.Exit(2)
}
ctx = packagecloud.WithPackagecloudToken(ctx, PACKAGECLOUD_TOKEN)
go func() {
os.Exit(int(subcommands.Execute(ctx)))
}()
select {
case <-sig:
cancel()
case <-ctx.Done():
}
}