Skip to content

Commit f79772c

Browse files
committed
method structure refactoring, SA rules
1 parent 507b1c5 commit f79772c

File tree

2 files changed

+63
-25
lines changed

2 files changed

+63
-25
lines changed

src/Generator.Client.CommandLine/ConsoleApplication.cs

Lines changed: 61 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using CommandDotNet.Attributes;
1212
using Generator.Shared.Template;
1313
using Generator.Shared.Transformation;
14+
using Newtonsoft.Json;
1415
using NLog;
1516

1617
namespace 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
}

src/Generator.Client.CommandLine/RunnerFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ public static AppRunner<TApplication> Create<TApplication>()
1818
where TApplication : class
1919
{
2020
var settings = new AppSettings();
21-
settings.Case = Case.LowerCase;
21+
settings.Case = Case.CamelCase;
22+
settings.Help.UsageAppNameStyle = UsageAppNameStyle.GlobalTool;
2223
settings.Help.TextStyle = HelpTextStyle.Detailed;
2324
var runner = new AppRunner<TApplication>(settings);
2425
return runner;

0 commit comments

Comments
 (0)