1111using CommandDotNet . Attributes ;
1212using Generator . Shared . Template ;
1313using Generator . Shared . Transformation ;
14+ using Newtonsoft . Json ;
1415using NLog ;
1516
1617namespace Generator . Client . CommandLine
@@ -71,32 +72,9 @@ public async Task<int> Build(
7172 }
7273
7374 [ SubCommand ]
74- [ ApplicationMetadata ( Description = "Entry point for configurations" ) ]
75+ [ ApplicationMetadata ( Description = "Entry point for configurations. " ) ]
7576 public class Configuration
7677 {
77- [ ApplicationMetadata ( Description = "Retrieves a list of all configurations contained in the storage." ) ]
78- public async Task < int > GetAll (
79- [ Option (
80- Description = "Path to storage." ,
81- ShortName = "s" ,
82- LongName = "storage" ) ]
83- string storage = null )
84- {
85- if ( ! ConsoleUtils . TryGetManager ( storage , out var manager ) )
86- {
87- return 1 ;
88- }
89-
90- var configurations = await manager . LoadStorageContentAsync ( ) ;
91- for ( var index = 0 ; index < configurations . Length ; index ++ )
92- {
93- var configuration = configurations [ index ] ;
94- Console . WriteLine ( $ "(#{ index + 1 : 00} ): { configuration . ConfigurationName } ") ;
95- }
96-
97- return 0 ;
98- }
99-
10078 [ ApplicationMetadata ( Description = "Renames the configuration if it can be found through the given id." ) ]
10179 public async Task < int > Rename (
10280 [ Argument (
@@ -129,6 +107,65 @@ public async Task<int> Rename(
129107 return 2 ;
130108 }
131109 }
110+
111+ [ SubCommand ]
112+ [ ApplicationMetadata ( Description = "Get actions." ) ]
113+ public class Get
114+ {
115+ [ ApplicationMetadata ( Description = "Retrieves a list of all configurations contained in the storage." ) ]
116+ public async Task < int > All (
117+ [ Option (
118+ Description = "Path to storage." ,
119+ ShortName = "s" ,
120+ LongName = "storage" ) ]
121+ string storage = null )
122+ {
123+ if ( ! ConsoleUtils . TryGetManager ( storage , out var manager ) )
124+ {
125+ return 1 ;
126+ }
127+
128+ var configurations = await manager . LoadStorageContentAsync ( ) ;
129+ for ( var index = 0 ; index < configurations . Length ; index ++ )
130+ {
131+ var configuration = configurations [ index ] ;
132+ Console . WriteLine ( $ "(#{ index + 1 : 00} ): { configuration . ConfigurationName } ") ;
133+ }
134+
135+ return 0 ;
136+ }
137+
138+ [ ApplicationMetadata ( Description = "Renames the configuration if it can be found through the given id." ) ]
139+ public async Task < int > Detail (
140+ [ Argument (
141+ Description =
142+ "id of configuration which can be the position of the configuration, its guid, or the configuration name" ) ]
143+ string id ,
144+ [ Option (
145+ Description = "Path to storage." ,
146+ ShortName = "s" ,
147+ LongName = "storage" ) ]
148+ string storage = null )
149+ {
150+ if ( ! ConsoleUtils . TryGetManager ( storage , out var manager ) )
151+ {
152+ return 1 ;
153+ }
154+
155+ try
156+ {
157+ var configuration = await manager . GetConfigurationByIdAsync ( id ) ;
158+ var serialized = JsonConvert . SerializeObject ( configuration , Formatting . Indented ) ;
159+ Console . WriteLine ( serialized ) ;
160+ return 0 ;
161+ }
162+ catch ( Exception e )
163+ {
164+ Log . Error ( e . Message ) ;
165+ return 2 ;
166+ }
167+ }
168+ }
132169 }
133170 }
134171}
0 commit comments