@@ -30,17 +30,11 @@ func ModuleCommand(args ...string) error {
3030 return fmt .Errorf ("module command requires subcommand (list, run)" )
3131 }
3232
33- // Get current repository
34- repo , err := GetRepository ()
35- if err != nil {
36- return fmt .Errorf ("getting repository: %w" , err )
37- }
38-
3933 cmd := args [0 ]
4034 switch cmd {
4135 case "list" :
4236 // List installed modules
43- modules := repo . ListModules ()
37+ modules := ListModules ()
4438 if len (modules ) == 0 {
4539 fmt .Println ("No modules installed" )
4640 return nil
@@ -62,52 +56,59 @@ func ModuleCommand(args ...string) error {
6256 }
6357 return nil
6458
65- case "add " :
59+ case "install " :
6660 if len (args ) < 2 {
67- return fmt .Errorf ("add requires module path" )
61+ return fmt .Errorf ("install requires module path" )
6862 }
63+ modulePath := args [1 ]
64+ fullPath := fmt .Sprintf ("github.com/systemshift/%s" , modulePath )
6965
70- // Run go get
71- cmd := exec .Command ("go" , "get" , args [ 1 ] )
72- cmd .Dir = filepath . Dir ( repoPath )
66+ // Run go get to download the module
67+ cmd := exec .Command ("go" , "get" , fullPath )
68+ cmd .Dir = "."
7369 if err := cmd .Run (); err != nil {
7470 return fmt .Errorf ("installing module: %w" , err )
7571 }
7672
77- fmt .Printf ("Module %s added successfully\n " , args [1 ])
78- return nil
79-
80- case "update" :
81- // Run go get -u
82- cmd := exec .Command ("go" , "get" , "-u" , "./..." )
83- cmd .Dir = filepath .Dir (repoPath )
73+ // Run go mod tidy
74+ cmd = exec .Command ("go" , "mod" , "tidy" )
75+ cmd .Dir = "."
8476 if err := cmd .Run (); err != nil {
85- return fmt .Errorf ("updating modules: %w" , err )
77+ return fmt .Errorf ("tidying modules: %w" , err )
8678 }
8779
88- fmt .Println ( "Modules updated successfully" )
80+ fmt .Printf ( "Module %s installed successfully\n " , modulePath )
8981 return nil
9082
91- case "remove " :
83+ case "install-dev " :
9284 if len (args ) < 2 {
93- return fmt .Errorf ("remove requires module name" )
85+ return fmt .Errorf ("install-dev requires module path" )
86+ }
87+ modulePath := args [1 ]
88+ fullPath := fmt .Sprintf ("github.com/systemshift/%s" , modulePath )
89+
90+ // Add require directive first
91+ cmd := exec .
Command (
"go" ,
"mod" ,
"edit" ,
"-require" ,
fmt .
Sprintf (
"%[email protected] " ,
fullPath ))
92+ cmd .Dir = "."
93+ if err := cmd .Run (); err != nil {
94+ return fmt .Errorf ("adding require directive: %w" , err )
9495 }
9596
96- // Run go mod edit to remove module
97- cmd : = exec .Command ("go" , "mod" , "edit" , "-droprequire " , args [ 1 ] )
98- cmd .Dir = filepath . Dir ( repoPath )
97+ // Add replace directive
98+ cmd = exec .Command ("go" , "mod" , "edit" , "-replace " , fmt . Sprintf ( "%s=./%s" , fullPath , modulePath ) )
99+ cmd .Dir = "."
99100 if err := cmd .Run (); err != nil {
100- return fmt .Errorf ("removing module : %w" , err )
101+ return fmt .Errorf ("adding replace directive : %w" , err )
101102 }
102103
103104 // Run go mod tidy
104105 cmd = exec .Command ("go" , "mod" , "tidy" )
105- cmd .Dir = filepath . Dir ( repoPath )
106+ cmd .Dir = "."
106107 if err := cmd .Run (); err != nil {
107108 return fmt .Errorf ("tidying modules: %w" , err )
108109 }
109110
110- fmt .Printf ("Module %s removed successfully \n " , args [ 1 ] )
111+ fmt .Printf ("Module %s installed in development mode \n " , modulePath )
111112 return nil
112113
113114 default :
@@ -117,15 +118,16 @@ func ModuleCommand(args ...string) error {
117118 return fmt .Errorf ("module command required" )
118119 }
119120
120- module , exists := repo .GetModule (moduleID )
121- if ! exists {
122- return fmt .Errorf ("module not found: %s" , moduleID )
123- }
124-
125121 cmd := args [1 ]
126122 cmdArgs := args [2 :]
127123
128- return module .HandleCommand (cmd , cmdArgs )
124+ // Get current repository for module commands
125+ repo , err := GetRepository ()
126+ if err != nil {
127+ return fmt .Errorf ("getting repository: %w" , err )
128+ }
129+
130+ return HandleModuleCommand (moduleID , cmd , cmdArgs , repo )
129131 }
130132}
131133
0 commit comments