Hermod
A cross-platform, modular and fully GDPR-compliant email archival solution!
Loading...
Searching...
No Matches
TerminalCommand.cs
Go to the documentation of this file.
1using System;
2
3namespace Hermod.Core.Commands {
4
5 using Results;
6
7 using getopt.net;
8
15 public class TerminalCommand: ICommand {
16
17 public TerminalCommand(string commandName, string shortDescription, string? longDescription, Func<string[], ICommandResult> func, params Option[] args) {
18 Name = commandName;
19 ShortDescription = shortDescription;
20 LongDescription = longDescription;
21 CommandOptions = args;
22 executor = func;
23 }
24
25 public string Name { get; }
26
27 public string ShortDescription { get; }
28
29 public string? LongDescription { get; }
30
31 public Option[] CommandOptions { get; }
32
33 Func<string[], ICommandResult> executor;
34
35 public ICommandResult Execute(params string[] args) => executor(args);
36
37 public Task<ICommandResult> ExecuteAsync(params string[] args) {
38 return new TaskFactory().StartNew(() => executor(args));
39 }
40 }
41}
42
Represents a single command that can only be executed on the (interactive) terminal.
string ShortDescription
A short description of the command and its function.
Option[] CommandOptions
A list of options applicable to this command.
TerminalCommand(string commandName, string shortDescription, string? longDescription, Func< string[], ICommandResult > func, params Option[] args)
ICommandResult Execute(params string[] args)
Executes the command and returns a genericised variation of the ICommandResult<T>,...
string Name
The (callable) name for the command.
string? LongDescription
A detailled description of the command and its function.
Func< string[], ICommandResult > executor
Task< ICommandResult > ExecuteAsync(params string[] args)
Asynchronous variation of Execute(string[]).
Specialised variation of ICommand with generic typing.
Definition: ICommand.cs:49
A generic, object-based variation of ICommandResult<T>.