-
Notifications
You must be signed in to change notification settings - Fork 116
/
main.go
48 lines (40 loc) · 1.07 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
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package main
import (
"context"
"errors"
"log"
"os"
"os/exec"
"github.com/elastic/elastic-package/cmd"
"github.com/elastic/elastic-package/internal/install"
)
func main() {
err := install.EnsureInstalled()
if err != nil {
log.Fatalf("Validating installation failed: %v", err)
}
rootCmd := cmd.RootCmd()
rootCmd.SilenceErrors = true // Silence errors so we handle them here.
err = rootCmd.Execute()
if errIsInterruption(err) {
rootCmd.Println("interrupted")
os.Exit(130)
}
if err != nil {
rootCmd.PrintErrln(rootCmd.ErrPrefix(), err)
os.Exit(1)
}
}
func errIsInterruption(err error) bool {
if errors.Is(err, context.Canceled) {
return true
}
var exitError *exec.ExitError
if errors.As(err, &exitError) && (*exitError).ProcessState.ExitCode() == 130 { // 130 -> subcommand killed by sigint
return true
}
return false
}