-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathRemoveCommand.cs
More file actions
54 lines (46 loc) · 1.32 KB
/
RemoveCommand.cs
File metadata and controls
54 lines (46 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using System;
using System.Threading.Tasks;
using SeqCli.Config;
using SeqCli.Util;
using Serilog;
namespace SeqCli.Cli.Commands.Profile;
[Command("profile", "remove", "Remove a connection profile",
Example = "seqcli profile remove -n Production")]
class RemoveCommand : Command
{
string? _name;
public RemoveCommand()
{
Options.Add("n=|name=",
"The name of the connection profile to remove",
v => _name = ArgumentString.Normalize(v));
}
protected override Task<int> Run()
{
return Task.FromResult(RunSync());
}
int RunSync()
{
if (_name == null)
{
Log.Error("A profile name is required");
return 1;
}
try
{
var config = SeqCliConfig.ReadFromFile(RuntimeConfigurationLoader.SeqCliConfigFilename());
if (!config.Profiles.Remove(_name))
{
Log.Error("No profile with name {ProfileName} was found", _name);
return 1;
}
SeqCliConfig.WriteToFile(config, RuntimeConfigurationLoader.SeqCliConfigFilename());
return 0;
}
catch (Exception ex)
{
Log.Error("Could not create profile: {ErrorMessage}", Presentation.FormattedMessage(ex));
return 1;
}
}
}