This repository was archived by the owner on Mar 17, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathroot.go
More file actions
64 lines (55 loc) · 2.22 KB
/
root.go
File metadata and controls
64 lines (55 loc) · 2.22 KB
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
package cmd
import (
"fmt"
"github.com/charmbracelet/lipgloss"
"github.com/nitrictech/suga/cli/internal/config"
"github.com/nitrictech/suga/cli/internal/style/colors"
"github.com/nitrictech/suga/cli/internal/version"
"github.com/samber/do/v2"
"github.com/spf13/cobra"
)
func NewRootCmd(injector do.Injector) *cobra.Command {
rootCmd := &cobra.Command{
Use: version.CommandName,
Short: fmt.Sprintf("%s CLI - The command line interface for %s", version.ProductName, version.ProductName),
Long: fmt.Sprintf("%s CLI is a command line interface for managing and deploying %s applications. It provides a set of commands to help you develop, test, and deploy your %s applications.", version.ProductName, version.ProductName, version.ProductName),
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
conf, err := config.Load(cmd)
if err != nil {
return err
}
if debugFlag, _ := cmd.Flags().GetBool("debug"); debugFlag {
conf.SetDebug(true)
}
do.ProvideValue(injector, conf)
return nil
},
}
rootCmd.PersistentFlags().Bool("debug", false, "Enable debug mode with verbose API request/response logging")
rootCmd.AddCommand(NewLoginCmd(injector))
rootCmd.AddCommand(NewLogoutCmd(injector))
rootCmd.AddCommand(NewAccessTokenCmd(injector))
rootCmd.AddCommand(NewVersionCmd(injector))
rootCmd.AddCommand(NewTemplatesCmd(injector))
rootCmd.AddCommand(NewInitCmd(injector))
rootCmd.AddCommand(NewNewCmd(injector))
rootCmd.AddCommand(NewBuildCmd(injector))
rootCmd.AddCommand(NewGenerateCmd(injector))
rootCmd.AddCommand(NewEditCmd(injector))
rootCmd.AddCommand(NewDevCmd(injector))
rootCmd.AddCommand(NewConfigCmd(injector))
rootCmd.AddCommand(NewTeamCmd(injector))
return rootCmd
}
// NewVersionCmd creates the version command
func NewVersionCmd(injector do.Injector) *cobra.Command {
return &cobra.Command{
Use: "version",
Short: fmt.Sprintf("Print the %s CLI version", version.ProductName),
Long: fmt.Sprintf("Display the version number of the %s CLI.", version.ProductName),
Run: func(cmd *cobra.Command, args []string) {
highlight := lipgloss.NewStyle().Foreground(colors.Teal)
fmt.Printf("%s cli version %s\n", version.ProductName, highlight.Render(version.Version))
},
}
}