@@ -106,6 +106,36 @@ public async Task<int> Rename(
106106 }
107107 }
108108
109+ [ ApplicationMetadata ( Description = "Saves the local configuration to the specified location." ) ]
110+ public async Task < int > Export (
111+ [ Argument (
112+ Description = "export path" ) ]
113+ string newPath )
114+ {
115+ if ( ! ConsoleUtils . TryGetManager ( null , out var manager ) )
116+ {
117+ Log . Error ( $ "Failed to obtain local storage manager.") ;
118+ return 1 ;
119+ }
120+
121+ try
122+ {
123+ var configurations = await manager . LoadStorageContentAsync ( ) ;
124+ if ( ! await manager . SaveConfigurationsAsync ( configurations , newPath ) )
125+ {
126+ Log . Error ( $ "Failed to save configurations to path [{ newPath } ].") ;
127+ return 3 ;
128+ }
129+
130+ return 0 ;
131+ }
132+ catch ( Exception e )
133+ {
134+ Log . Error ( e . Message ) ;
135+ return 2 ;
136+ }
137+ }
138+
109139 [ SubCommand ]
110140 [ ApplicationMetadata ( Description = "Get actions." ) ]
111141 public class Get
@@ -163,6 +193,39 @@ public async Task<int> Json(
163193 }
164194 }
165195 }
196+
197+ [ SubCommand ]
198+ [ ApplicationMetadata ( Description = "Import actions." ) ]
199+ public class Import
200+ {
201+ [ ApplicationMetadata ( Description = "Updates the local storage from a given path." ) ]
202+ public async Task < int > FromFile (
203+ [ Argument (
204+ Description = "Path to storage file." ) ]
205+ string storagePath )
206+ {
207+ if ( ! ConsoleUtils . TryGetManager ( null , out var currentManager ) )
208+ {
209+ Log . Error ( "Failed to obtain local manager instance." ) ;
210+ return 1 ;
211+ }
212+
213+ if ( ! ConsoleUtils . TryGetManager ( storagePath , out var remoteManager ) )
214+ {
215+ Log . Error ( $ "Failed to obtain remote manager instance using path [{ storagePath } ].") ;
216+ return 2 ;
217+ }
218+
219+ var remoteContents = await remoteManager . LoadStorageContentAsync ( ) ;
220+ if ( ! await currentManager . SaveConfigurationsAsync ( remoteContents ) )
221+ {
222+ Log . Error ( $ "Failed to update local manager instance.") ;
223+ return 3 ;
224+ }
225+
226+ return 0 ;
227+ }
228+ }
166229 }
167230 }
168231}
0 commit comments