-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathCliSchema.cs
More file actions
140 lines (125 loc) · 3.45 KB
/
CliSchema.cs
File metadata and controls
140 lines (125 loc) · 3.45 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
using System.IO.Abstractions;
using System.Text.Json;
namespace Elastic.Documentation.Configuration.Toc.CliReference;
// Language-agnostic CLI schema spec (https://cli-schema.org)
// Schema v2: type uses JSON Schema primitives; v1 used kind-style strings
public record CliSchema(
int SchemaVersion,
string Name,
string? Description,
List<CliParamSchema> GlobalOptions,
CliDefaultSchema? RootDefault,
List<CliCommandSchema> Commands,
List<CliNamespaceSchema> Namespaces,
string? Version = null,
string[]? ReservedMetaCommands = null,
string[]? Tags = null,
bool? RequiresAuth = null,
string[]? AuthCommands = null,
CliEnvironmentSchema? Environment = null,
List<CliShortcutSchema>? Shortcuts = null
)
{
public static CliSchema Load(IFileInfo schemaFile)
{
var json = schemaFile.FileSystem.File.ReadAllText(schemaFile.FullName);
return JsonSerializer.Deserialize(json, CliSchemaJsonContext.Default.CliSchema)
?? throw new InvalidOperationException($"Failed to deserialize CLI schema from {schemaFile.FullName}");
}
}
public record CliShortcutSchema(string From, string[] To);
public record CliCommandSchema(
string[] Path,
string Name,
string? Summary,
string? Notes,
string? Usage,
string[]? Examples,
List<CliParamSchema> Parameters,
string[]? Aliases = null,
bool Hidden = false,
string[]? Tags = null,
CliDeprecatedSchema? Deprecated = null,
CliIntentSchema? Intent = null,
CliOutputSchema? Output = null,
bool Streaming = false,
bool LongRunning = false
);
public record CliNamespaceSchema(
string Segment,
string? Summary,
string? Notes,
List<CliParamSchema>? Options,
CliDefaultSchema? DefaultCommand,
List<CliCommandSchema>? Commands,
List<CliNamespaceSchema>? Namespaces
);
public record CliParamSchema(
string Role,
string Name,
string? ShortName,
// v2: type uses JSON Schema primitives ("string","integer","number","boolean","array","enum")
string Type,
bool Required,
string? Summary,
string? DefaultValue = null,
string[]? EnumValues = null,
string? ElementType = null,
bool Repeatable = false,
string? Separator = null,
string[]? Aliases = null,
bool Hidden = false,
bool Variadic = false,
CliDeprecatedSchema? Deprecated = null,
List<CliValidationSchema>? Validations = null
);
public record CliDefaultSchema(
string? Summary,
string? Notes,
string? Usage,
string[]? Examples,
List<CliParamSchema> Parameters,
string Kind = "",
bool Hidden = false
);
public record CliValidationSchema(
string Kind,
string[]? Values = null,
string? Min = null,
string? Max = null,
string? Pattern = null
);
public record CliDeprecatedSchema(
string? Message = null,
string? Since = null,
string? RemovedIn = null
);
public record CliIntentSchema(
bool? Destructive = null,
bool? Idempotent = null,
string? Scope = null,
bool? RequiresConfirmation = null,
bool? RequiresAuth = null
);
public record CliOutputSchema(
string[]? Formats = null,
string? FormatFlag = null
);
public record CliEnvironmentSchema(
List<CliEnvVarSchema>? Variables = null,
List<CliConfigFileSchema>? ConfigFiles = null
);
public record CliEnvVarSchema(
string Name,
string? Description = null,
bool Required = false,
string? DefaultValue = null
);
public record CliConfigFileSchema(
string Path,
string? Description = null,
bool Required = false
);