@@ -3,14 +3,14 @@ package memex
33import (
44 "fmt"
55 "os"
6+ "os/exec"
67 "path/filepath"
78 "strconv"
89 "strings"
910
1011 "memex/internal/memex/core"
1112 "memex/internal/memex/migration"
1213 "memex/internal/memex/repository"
13- "memex/pkg/types"
1414)
1515
1616var (
@@ -62,52 +62,52 @@ func ModuleCommand(args ...string) error {
6262 }
6363 return nil
6464
65- case "install " :
65+ case "add " :
6666 if len (args ) < 2 {
67- return fmt .Errorf ("install requires module path" )
67+ return fmt .Errorf ("add requires module path" )
6868 }
6969
70- // Check for --dev flag
71- var devMode bool
72- var modulePath string
73- if strings .HasPrefix (args [1 ], "--dev=" ) {
74- devValue := strings .TrimPrefix (args [1 ], "--dev=" )
75- devMode = devValue == "true"
76- if len (args ) < 3 {
77- return fmt .Errorf ("install requires module path" )
78- }
79- modulePath = args [2 ]
80- } else {
81- modulePath = args [1 ]
70+ // Run go get
71+ cmd := exec .Command ("go" , "get" , args [1 ])
72+ cmd .Dir = filepath .Dir (repoPath )
73+ if err := cmd .Run (); err != nil {
74+ return fmt .Errorf ("installing module: %w" , err )
75+ }
76+
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 )
84+ if err := cmd .Run (); err != nil {
85+ return fmt .Errorf ("updating modules: %w" , err )
8286 }
8387
84- // Get module ID from path
85- moduleID := filepath .Base (modulePath )
86- moduleID = strings .TrimSuffix (moduleID , filepath .Ext (moduleID ))
87-
88- // Convert to module repository
89- var moduleRepo types.ModuleRepository
90- if r , ok := repo .(* repository.Repository ); ok {
91- moduleRepo = r .AsModuleRepository ()
92- } else if mr , ok := repo .(types.ModuleRepository ); ok {
93- moduleRepo = mr
94- } else {
95- return fmt .Errorf ("repository does not support module operations" )
88+ fmt .Println ("Modules updated successfully" )
89+ return nil
90+
91+ case "remove" :
92+ if len (args ) < 2 {
93+ return fmt .Errorf ("remove requires module name" )
9694 }
9795
98- // Add module path
99- if devMode {
100- moduleRepo . GetLoader (). AddDevPath ( moduleID , modulePath )
101- } else {
102- moduleRepo . GetLoader (). AddPath ( modulePath )
96+ // Run go mod edit to remove module
97+ cmd := exec . Command ( "go" , "mod" , "edit" , "-droprequire" , args [ 1 ])
98+ cmd . Dir = filepath . Dir ( repoPath )
99+ if err := cmd . Run (); err != nil {
100+ return fmt . Errorf ( "removing module: %w" , err )
103101 }
104102
105- // Discover and load modules
106- if err := moduleRepo .GetDiscovery ().DiscoverModules (); err != nil {
107- return fmt .Errorf ("discovering modules: %w" , err )
103+ // Run go mod tidy
104+ cmd = exec .Command ("go" , "mod" , "tidy" )
105+ cmd .Dir = filepath .Dir (repoPath )
106+ if err := cmd .Run (); err != nil {
107+ return fmt .Errorf ("tidying modules: %w" , err )
108108 }
109109
110- fmt .Printf ("Module %s installed successfully\n " , moduleID )
110+ fmt .Printf ("Module %s removed successfully\n " , args [ 1 ] )
111111 return nil
112112
113113 default :
0 commit comments