-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.go
More file actions
60 lines (47 loc) · 1.61 KB
/
init.go
File metadata and controls
60 lines (47 loc) · 1.61 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
package cmd
import (
"github.com/dtvem/dtvem/src/internal/config"
"github.com/dtvem/dtvem/src/internal/path"
"github.com/dtvem/dtvem/src/internal/ui"
"github.com/spf13/cobra"
)
var initYes bool
var initCmd = &cobra.Command{
Use: "init",
Short: "Initialize dtvem (setup directories and PATH)",
Long: `Initialize dtvem by creating necessary directories and configuring your PATH.
This command:
- Creates the ~/.dtvem directory structure
- Adds ~/.dtvem/shims to your PATH (with your permission)
Run this command after installing dtvem for the first time.
Example:
dtvem init`,
Run: func(cmd *cobra.Command, args []string) {
ui.Header("Initializing dtvem...")
// Ensure directories exist
spinner := ui.NewSpinner("Creating directories...")
spinner.Start()
if err := config.EnsureDirectories(); err != nil {
spinner.Error("Failed to create directories")
ui.Error("%v", err)
return
}
spinner.Success("Directories created")
// Setup PATH - AddToPath handles checking position and moving if needed
shimsDir := path.ShimsDir()
if err := path.AddToPath(shimsDir, initYes); err != nil {
ui.Error("Failed to configure PATH: %v", err)
ui.Info("You can manually add %s to your PATH", shimsDir)
return
}
ui.Success("dtvem initialized successfully!")
ui.Info("\nNext steps:")
ui.Info(" 1. Restart your terminal (required for PATH changes)")
ui.Info(" 2. Run: dtvem install <runtime> <version>")
ui.Info(" 3. Run: dtvem global <runtime> <version>")
},
}
func init() {
initCmd.Flags().BoolVarP(&initYes, "yes", "y", false, "Skip confirmation prompts")
rootCmd.AddCommand(initCmd)
}