Repository navigation
Expand file tree
/
Copy pathRunCommandDefinition.cs
More file actions
88 lines (74 loc) · 3.29 KB
/
Copy pathRunCommandDefinition.cs
File metadata and controls
88 lines (74 loc) · 3.29 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
81
82
83
84
85
86
87
88
using System;
using System.Collections.Generic;
using System.Linq;
namespace NETworkManager.Models.RunCommand;
/// <summary>
/// Command of the run command dialog (e.g. "dnslookup" with the alias "dns"), which opens an application or the
/// settings.
/// </summary>
public sealed class RunCommandDefinition
{
/// <summary>
/// Whether the command opens an application or the settings.
/// </summary>
public RunCommandType Type { get; init; }
/// <summary>
/// Application to open (<see cref="ApplicationName.None" /> for the settings).
/// </summary>
public ApplicationName Application { get; init; }
/// <summary>
/// Command (lowercase, e.g. "dnslookup").
/// </summary>
public string Command { get; init; }
/// <summary>
/// Short forms of the command (lowercase, e.g. "dns", "nslookup").
/// </summary>
public IReadOnlyList<string> Aliases { get; init; } = [];
/// <summary>
/// The command accepts a target (e.g. host, IP range, query).
/// </summary>
public bool SupportsTarget { get; init; }
/// <summary>
/// The target is a host (or a list / range of hosts): a URL is converted to its host (e.g. "trace
/// https://borntoberoot.net/docs" traces "borntoberoot.net"), like a URL pasted into the host input.
/// </summary>
public bool TargetIsHost { get; init; }
/// <summary>
/// The command accepts a profile ("@name") instead of a target.
/// </summary>
public bool SupportsProfile { get; init; }
/// <summary>
/// Second argument after the target (e.g. ports or DNS server).
/// </summary>
public RunCommandArgument Argument { get; init; }
/// <summary>
/// Type keywords that can follow the target (lowercase, e.g. "a", "aaaa" for the DNS lookup).
/// </summary>
public IReadOnlyList<string> Types { get; init; } = [];
/// <summary>
/// The type keyword is required and is the first word after the command (e.g. "lookup port 22"). The rest of the
/// input is the target, so it can contain spaces (e.g. "lookup oui Cisco Systems").
/// </summary>
public bool TypeBeforeTarget { get; init; }
/// <summary>
/// Parts of the syntax of the arguments for the hint (e.g. "<Hosts>", "[DNS server]", "[Type]",
/// "@<Profile>"), empty if there are none.
/// </summary>
public IReadOnlyList<RunCommandSyntaxPart> SyntaxParts { get; init; } = [];
/// <summary>
/// Syntax of the arguments (e.g. "<Hosts> [DNS server] [Type] | @<Profile>", or
/// "[@<Profile>]" without a target), empty if there are none.
/// </summary>
public string Syntax => string.Join(" ",
SyntaxParts.Select(x => x.Kind == RunCommandSyntaxPartKind.Profile && SupportsTarget ? $"| {x.Text}" : x.Text));
/// <summary>
/// Checks if the text is the command or one of its aliases (case-insensitive).
/// </summary>
/// <param name="text">Command text.</param>
/// <returns>True if the text matches.</returns>
public bool Matches(string text)
{
return string.Equals(Command, text, StringComparison.OrdinalIgnoreCase) ||
Aliases.Any(x => string.Equals(x, text, StringComparison.OrdinalIgnoreCase));
}
}