-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommonMessageSettings.cs
More file actions
80 lines (71 loc) · 3.3 KB
/
CommonMessageSettings.cs
File metadata and controls
80 lines (71 loc) · 3.3 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.ComponentModel;
using BuslyCLI.TypeConverters;
using Spectre.Console;
using Spectre.Console.Cli;
namespace BuslyCLI.Commands;
// TODO: Required options will be implemented soon according to https://github.com/spectreconsole/spectre.console/discussions/538. Until this is implemented we must do the following
// public override ValidationResult Validate()
// {
// if (string.IsNullOrWhiteSpace(Foo))
// {
// return ValidationResult.Error("Foo is required");
// }
//
// return base.Validate();
// }
public abstract class CommonMessageSettings : GlobalCommandSettings
{
[CommandOption("-c|--content-type <content-type>")]
[Description("The type of serialization used for the message")]
public required string ContentType { get; set; }
[CommandOption("-e|--enclosed-message-type <enclosed-message-type>")]
[Description("The fully qualified .NET type name of the enclosed message")]
public required string EnclosedMessageType { get; set; }
[CommandOption("-m|--message-body <message-body>")]
[Description("The content of the message body. Accepts a raw JSON string or a path to a file using curl-style @file syntax (e.g. @payload.json).")]
public required MessageBodyValue MessageBody { get; set; }
public override ValidationResult Validate()
{
if (string.IsNullOrWhiteSpace(ContentType)) return ValidationResult.Error("must specify a 'content-type'.");
if (string.IsNullOrWhiteSpace(EnclosedMessageType))
return ValidationResult.Error("must specify an 'enclosed-message-type'.");
if (MessageBody is null) return ValidationResult.Error("must specify a 'message-body'.");
if (Path.IsPathFullyQualified(MessageBody.Value))
{
if (!File.Exists(MessageBody.Value))
return ValidationResult.Error($"File not found: {MessageBody.Value}");
MessageBody.Value = File.ReadAllText(MessageBody.Value);
}
return base.Validate();
}
// public override ValidationResult Validate()
// {
// if (!string.IsNullOrWhiteSpace(ConnectionString)
// && (!string.IsNullOrWhiteSpace(Server)
// || !string.IsNullOrWhiteSpace(Database)))
// {
// return ValidationResult.Error(
// "You cannot specify a <Server> or <Database> when passing a <ConnectionString>");
// }
//
// if (string.IsNullOrEmpty(ConnectionString) && !string.IsNullOrWhiteSpace(Server) &&
// string.IsNullOrWhiteSpace(Database))
// return ValidationResult.Error("You must specify a <database> when using the <server> parameter");
//
// if (string.IsNullOrEmpty(ConnectionString) && !string.IsNullOrWhiteSpace(Database) &&
// string.IsNullOrWhiteSpace(Server))
// return ValidationResult.Error("You must specify a <server> when using the <database> parameter");
//
// if (!string.IsNullOrWhiteSpace(UserID) && string.IsNullOrWhiteSpace(Password))
// {
// return ValidationResult.Error("You must specify a <Password> when passing a <UserID>");
// }
//
// if (!string.IsNullOrWhiteSpace(Password) && string.IsNullOrWhiteSpace(UserID))
// {
// return ValidationResult.Error("You must specify a <UserID> when passing a <Password>");
// }
//
// return base.Validate();
// }
}