-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathReplConfig.cs
51 lines (41 loc) · 1.56 KB
/
ReplConfig.cs
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
using System;
using CommandDotNet.Builders;
namespace CommandDotNet.ReadLineRepl
{
public class ReplConfig
{
private Func<CommandContext, string>? _sessionInitMessage;
private Func<CommandContext, string>? _sessionHelpMessage;
public string? AppName { get; set; }
public ReplOption ReplOption { get; set; } = new ReplOption();
public Func<CommandContext, string> GetSessionInitMessage
{
get => _sessionInitMessage ?? BuildSessionInit ;
set => _sessionInitMessage = value ?? throw new ArgumentNullException(nameof(value));
}
public Func<CommandContext, string> GetSessionHelpMessage
{
get => _sessionHelpMessage ?? BuildSessionHelp;
set => _sessionHelpMessage = value ?? throw new ArgumentNullException(nameof(value));
}
private string BuildSessionInit(CommandContext context)
{
var appInfo = AppInfo.GetAppInfo();
return @$"{AppName ?? appInfo.FileName} {appInfo.Version}
Type 'help' to see interactive options
{BuildSessionHelp(context)}";
}
private string BuildSessionHelp(CommandContext context)
{
return @"Type '-h' or '--help' for the list of commands
Type 'exit', 'quit' or 'Ctrl+C + Enter' to exit.";
}
}
public class ReplOption
{
public string? LongName { get; set; }
public char? ShortName { get; set; }
public string? Description { get; set; }
internal bool IsRequested => LongName is { } || ShortName is { };
}
}