-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
97 lines (82 loc) · 2.8 KB
/
main.go
File metadata and controls
97 lines (82 loc) · 2.8 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
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
92
93
94
95
96
97
package main
import (
"context"
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"github.com/spf13/cobra"
"github.com/newcore-network/opencore-cli/internal/commands"
"github.com/newcore-network/opencore-cli/internal/ui"
"github.com/newcore-network/opencore-cli/internal/updater"
)
var (
version = "1.3.1"
)
func main() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
rootCmd := &cobra.Command{
Use: "opencore",
Short: "OpenCore CLI - Official tooling for OpenCore Framework",
Long: ui.Logo() + "\n\n" +
"OpenCore CLI is the official command-line tool for creating,\n" +
"managing, and building FiveM servers with the OpenCore Framework.\n\n" +
"Project Structure:\n" +
" • Resources: Framework-connected modules in resources/ folder\n" +
" (can use DI container, exports, events, database, etc.)\n" +
" • Standalones: Independent scripts in standalones/ folder\n" +
" (self-contained, no framework dependencies)",
Version: version,
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
pm, _ := cmd.Flags().GetString("usePackageManager")
pm = strings.TrimSpace(pm)
if pm != "" {
os.Setenv("OPENCORE_PACKAGE_MANAGER", pm)
}
return nil
},
}
rootCmd.PersistentFlags().String("usePackageManager", "", "Package manager to use (pnpm|yarn|npm|auto)")
// Set version template
rootCmd.SetVersionTemplate("{{.Version}}\n")
// Add commands
rootCmd.AddCommand(commands.NewInitCommand())
rootCmd.AddCommand(commands.NewCreateCommand())
rootCmd.AddCommand(commands.NewBuildCommand())
rootCmd.AddCommand(commands.NewDevCommand())
rootCmd.AddCommand(commands.NewDoctorCommand())
rootCmd.AddCommand(commands.NewCloneCommand())
rootCmd.AddCommand(commands.NewAdapterCommand())
rootCmd.AddCommand(commands.NewUpdateCommand())
if err := rootCmd.ExecuteContext(ctx); err != nil {
fmt.Println(ui.Error(err.Error()))
os.Exit(1)
}
// Check for updates in the background after command execution
if shouldCheckForUpdates(os.Args) {
channel := updater.GetConfiguredChannel()
if info, err := updater.CheckForUpdate(version, false, channel); err == nil {
if updater.NeedsUpdate(version, info.LatestVersion) {
fmt.Println()
fmt.Println(ui.Info(fmt.Sprintf("New %s version available: %s -> %s", channel, version, info.LatestVersion)))
fmt.Println(ui.Info(fmt.Sprintf("Run 'opencore update --channel %s' to update.", channel)))
}
}
}
}
func shouldCheckForUpdates(args []string) bool {
if len(args) <= 1 {
return false
}
if args[1] == "update" || args[1] == "--version" || args[1] == "-v" {
return false
}
if ui.IsUpdateCheckDisabled() || ui.IsNonInteractiveSession() {
return false
}
return true
}