-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
40 lines (34 loc) · 1000 Bytes
/
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
// Copyright © 2022 Roberto Hidalgo <chinampa@un.rob.mx>
// SPDX-License-Identifier: Apache-2.0
package chinampa
import (
"git.rob.mx/nidito/chinampa/internal/commands"
"git.rob.mx/nidito/chinampa/internal/registry"
"git.rob.mx/nidito/chinampa/pkg/command"
"git.rob.mx/nidito/chinampa/pkg/runtime"
"github.com/spf13/cobra"
)
func Register(cmds ...*command.Command) {
for _, cmd := range cmds {
registry.Register(cmd.SetBindings())
}
}
type Config struct {
Name string
Version string
Summary string
Description string
}
func SetVersionCommandName(name string) {
commands.VersionCommandName = name
}
func SetErrorHandler(handlerFunc func(cmd *cobra.Command, err error) error) {
registry.ErrorHandler = handlerFunc
}
func Execute(config Config) error {
runtime.Executable = config.Name
command.Root.Summary = config.Summary
command.Root.Description = config.Description
command.Root.Path = []string{runtime.Executable}
return registry.Execute(config.Version)
}