-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcmd.go
91 lines (77 loc) · 2.39 KB
/
cmd.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*
Copyright © 2023 BuildSafe
*/
// Package cmd contains the main command for the bsf cli
package cmd
import (
"context"
"fmt"
"os"
"github.com/elewis787/boa"
"github.com/spf13/cobra"
"github.com/buildsafedev/bsf/cmd/attestation"
"github.com/buildsafedev/bsf/cmd/build"
"github.com/buildsafedev/bsf/cmd/configure"
"github.com/buildsafedev/bsf/cmd/develop"
"github.com/buildsafedev/bsf/cmd/direnv"
"github.com/buildsafedev/bsf/cmd/dockerfile"
initCmd "github.com/buildsafedev/bsf/cmd/init"
"github.com/buildsafedev/bsf/cmd/nixgenerate"
"github.com/buildsafedev/bsf/cmd/oci"
"github.com/buildsafedev/bsf/cmd/precheck"
"github.com/buildsafedev/bsf/cmd/release"
"github.com/buildsafedev/bsf/cmd/scan"
"github.com/buildsafedev/bsf/cmd/search"
"github.com/buildsafedev/bsf/cmd/styles"
"github.com/buildsafedev/bsf/cmd/update"
)
var (
// DebugDir is the directory where bsf project needs to be debugged
DebugDir string
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "bsf",
Short: "bsf CLI lets you manage OS dependencies of your application seamlessly",
Long: `Opinionated app dependency management tool.`,
}
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
debugDir := getDebugPath()
if debugDir != "" {
err := os.Chdir(debugDir)
if err != nil {
fmt.Println(styles.ErrorStyle.Render("error:", err.Error()))
os.Exit(1)
}
}
rootCmd.SetHelpFunc(boa.HelpFunc)
rootCmd.SetUsageFunc(boa.UsageFunc)
rootCmd.AddCommand(initCmd.InitCmd)
rootCmd.AddCommand(search.SearchCmd)
rootCmd.AddCommand(develop.DevCmd)
rootCmd.AddCommand(build.BuildCmd)
rootCmd.AddCommand(scan.ScanCmd)
rootCmd.AddCommand(update.UpdateCmd)
rootCmd.AddCommand(attestation.AttCmd)
rootCmd.AddCommand(direnv.Direnv)
if os.Getenv("BSF_DEBUG_MODE") == "true" {
rootCmd.AddCommand(configure.ConfigureCmd)
rootCmd.AddCommand(nixgenerate.NixGenCmd)
rootCmd.AddCommand(precheck.PreCheckCmd)
}
rootCmd.AddCommand(oci.OCICmd)
rootCmd.AddCommand(dockerfile.DFCmd)
rootCmd.AddCommand(release.ReleaseCmd)
err := rootCmd.ExecuteContext(context.Background())
if err != nil {
os.Exit(1)
}
}
func getDebugPath() string {
if os.Getenv("BSF_DEBUG_DIR") != "" {
DebugDir = os.Getenv("BSF_DEBUG_DIR")
}
return DebugDir
}