-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
76 lines (59 loc) · 1.58 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package main
import (
"os"
_ "embed"
"github.com/hashicorp/actions-go-build/internal/log"
"github.com/hashicorp/actions-go-build/pkg/commands"
"github.com/hashicorp/actions-go-build/pkg/crt"
"github.com/hashicorp/actions-go-build/product"
actioncli "github.com/hashicorp/composite-action-framework-go/pkg/cli"
"github.com/mitchellh/cli"
)
//go:embed dev/VERSION
var versionCore string
func main() {
p, err := product.Product("actions-go-build", versionCore)
if err != nil {
log.Info("Error: invalid build: invalid product info: %s", err)
os.Exit(1)
}
status, err := makeCLI(p, os.Args[1:]).Run()
if err != nil {
log.Info("%s", err)
}
os.Exit(status)
}
func makeCLI(thisTool crt.Product, args []string) *cli.CLI {
versionCommand, version := commands.MakeVersionCommand(thisTool)
c := cli.NewCLI("actions-go-build", version)
c.Args = args
c.Commands = map[string]cli.CommandFactory{
"build": makeCommand(commands.Build),
"config": makeCommand(commands.Config),
"inspect": makeCommand(commands.Inspect),
"verify": makeCommand(commands.Verify),
"version": makeCommand(versionCommand),
}
return c
}
type cmd struct {
*actioncli.Command
run func([]string) error
}
func (c *cmd) Run(args []string) int {
if err := c.run(append([]string{""}, args...)); err != nil {
log.Info("%s", err)
return 1
}
return 0
}
func makeCommand(command *actioncli.Command) cli.CommandFactory {
return func() (cli.Command, error) {
return &cmd{
Command: command,
run: command.Execute,
}, nil
}
}