@@ -51,14 +51,15 @@ public CommandResult<List<ModuleSpecification>> Module(
5151 bool fetchInfo = fetchInfoName != null ;
5252 var clog = context . ShellEnv . Colors . Log ;
5353 var o = context . Out ;
54+ string n ;
5455
5556 if ( loadModulePath == null && unloadModuleName == null && updateModuleName == null && installModuleName == null && uninstallModuleName == null
5657 && ! fetchList && ! fetchInfo )
5758 {
5859 // output reports on loaded modules
5960
6061 var col1length = context . CommandLineProcessor . ModuleManager . Modules . Values . Select ( x => x . Name . Length ) . Max ( ) + 1 ;
61- int n = 1 ;
62+ int i = 1 ;
6263 foreach ( var kvp in context . CommandLineProcessor . ModuleManager . Modules )
6364 {
6465 var ver = kvp . Value . Assembly . GetCustomAttribute < AssemblyInformationalVersionAttribute > ( ) ? . InformationalVersion ;
@@ -92,22 +93,46 @@ public CommandResult<List<ModuleSpecification>> Module(
9293 {
9394 o . Echoln ( $ "{ "" . PadRight ( col1length , ' ' ) } { context . ShellEnv . Colors . Label } version : { context . ShellEnv . Colors . HalfDark } { ver } (target { ( ( target == null ) ? "" : target + ", " ) } created { dat } ) { context . ShellEnv . Colors . Label } Company : (rdc){ comp } ({ aut } ) ") ;
9495 }
95- if ( n < context . CommandLineProcessor . ModuleManager . Modules . Count ) o . Echoln ( ) ;
96- n ++ ;
96+ if ( i < context . CommandLineProcessor . ModuleManager . Modules . Count ) o . Echoln ( ) ;
97+ i ++ ;
9798 }
9899 return new CommandResult < List < ModuleSpecification > > ( context . CommandLineProcessor . ModuleManager . Modules . Values . ToList ( ) ) ;
99100 }
100101
101102 if ( ! fetchList && ! fetchInfo )
102103 {
104+ // update module name
105+
106+ if ( updateModuleName != null )
107+ {
108+ n = updateModuleName ;
109+ if ( ModuleUtil . IsModuleInstalled ( context , n ) )
110+ {
111+ var modSpec = context . CommandLineProcessor . ModuleManager . GetModule ( context , n ) ;
112+ if ( modSpec == null )
113+ return _ModuleErr ( context , $ "module specification not found for module name '{ n } '") ;
114+
115+ var getVersMethod = typeof ( NuGetServerApiCommands ) . GetMethod ( "NugetVer" ) ;
116+ var r = context . CommandLineProcessor . Eval ( context , getVersMethod , $ "{ n } ", 0 ) ;
117+ if ( r . EvalResultCode == ( int ) ReturnCode . OK )
118+ {
119+ var vers = ( PackageVersions ) r . Result ;
120+ }
121+ else
122+ return _ModuleErr ( context , $ "module id '{ n } ' not found at NuGet") ;
123+ } else
124+ return _ModuleErr ( context , $ "module '{ n } ' is not installed") ;
125+ }
126+
103127 // uninstall module
104128
105129 if ( uninstallModuleName != null )
106130 {
107- var folderName = uninstallModuleName . ToLower ( ) ;
131+ n = uninstallModuleName ;
132+ var folderName = n . ToLower ( ) ;
108133 if ( ! ModuleUtil . IsModuleInstalled ( context , folderName ) )
109134 // error not installed
110- return _ModuleErr ( context , $ "module '{ uninstallModuleName } ' is not installed") ;
135+ return _ModuleErr ( context , $ "module '{ n } ' is not installed") ;
111136
112137 o . Echoln ( clog + "removing potentially registered dlls:" ) ;
113138 var modInit = ModuleUtil . LoadModuleInitConfiguration ( context ) ;
@@ -133,12 +158,13 @@ public CommandResult<List<ModuleSpecification>> Module(
133158
134159 if ( installModuleName != null )
135160 {
161+ n = installModuleName ;
136162 var lastVer = string . IsNullOrWhiteSpace ( version ) ;
137163
138164 #region fetch module info
139165
140166 var queryMethod = typeof ( NuGetServerApiCommands ) . GetMethod ( "NugetQuery" ) ;
141- var r0 = context . CommandLineProcessor . Eval ( context , queryMethod , $ "{ installModuleName } -t 1", 0 ) ;
167+ var r0 = context . CommandLineProcessor . Eval ( context , queryMethod , $ "{ n } -t 1", 0 ) ;
142168 if ( r0 . EvalResultCode != ( int ) ReturnCode . OK ) return _ModuleErr ( context , r0 . ErrorReason ) ;
143169 var queryRes = r0 . Result as QueryResultRoot ;
144170 if ( queryRes == null ) return _ModuleErr ( context , "nuget query return a null result" ) ;
@@ -150,7 +176,7 @@ public CommandResult<List<ModuleSpecification>> Module(
150176 o . Echoln ( ) ;
151177
152178 var getVersMethod = typeof ( NuGetServerApiCommands ) . GetMethod ( "NugetVer" ) ;
153- var r = context . CommandLineProcessor . Eval ( context , getVersMethod , $ "{ installModuleName } ", 0 ) ;
179+ var r = context . CommandLineProcessor . Eval ( context , getVersMethod , $ "{ n } ", 0 ) ;
154180 if ( r . EvalResultCode == ( int ) ReturnCode . OK )
155181 {
156182 var vers = ( PackageVersions ) r . Result ;
@@ -179,7 +205,7 @@ public CommandResult<List<ModuleSpecification>> Module(
179205 if ( ! Directory . Exists ( moduleFolder ) ) Directory . CreateDirectory ( moduleFolder ) ;
180206
181207 moduleFolder = FileSystemPath . UnescapePathSeparators ( moduleFolder ) ;
182- var rd = context . CommandLineProcessor . Eval ( context , dwnMethod , $ "{ installModuleName } { version } -o { moduleFolder } ", 0 ) ;
208+ var rd = context . CommandLineProcessor . Eval ( context , dwnMethod , $ "{ n } { version } -o { moduleFolder } ", 0 ) ;
183209 if ( rd . EvalResultCode == ( int ) ReturnCode . OK )
184210 {
185211 o . Echo ( clog + "extracting package... " ) ;
@@ -265,17 +291,18 @@ public CommandResult<List<ModuleSpecification>> Module(
265291 return _ModuleErr ( null , null ) ;
266292 }
267293
268- // unload module
294+ // unload module (unregistered in session)
269295
270296 if ( unloadModuleName != null )
271297 {
272- if ( context . CommandLineProcessor . ModuleManager . Modules . Values . Any ( x => x . Name == unloadModuleName ) )
298+ n = unloadModuleName ;
299+ if ( context . CommandLineProcessor . ModuleManager . Modules . Values . Any ( x => x . Name == n ) )
273300 {
274- moduleSpecification = context . CommandLineProcessor . ModuleManager . UnregisterModule ( context , unloadModuleName ) ;
301+ moduleSpecification = context . CommandLineProcessor . ModuleManager . UnregisterModule ( context , n ) ;
275302 if ( moduleSpecification != null && moduleSpecification . Info != null ) o . Echoln ( $ "unloaded: { moduleSpecification . Info . GetDescriptor ( context ) } ") ;
276303 }
277304 else
278- return _ModuleErr ( context , $ "module '{ unloadModuleName } ' is not registered") ;
305+ return _ModuleErr ( context , $ "module '{ n } ' is not registered") ;
279306 }
280307 }
281308 else
0 commit comments