Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Commit ac18c84

Browse files
authored
Merge pull request #5 from microsoftgraph/chore/generate_cli_code
Add generated code
2 parents 8437ae9 + 2d9704e commit ac18c84

File tree

10,079 files changed

+1077968
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

10,079 files changed

+1077968
-3
lines changed

.github/workflows/build-cli.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: "Build CLI"
2+
on: [push]
3+
jobs:
4+
build:
5+
runs-on: ubuntu-latest
6+
env:
7+
NUGET_URL: https://nuget.pkg.github.com/microsoft/index.json
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
- name: Setup .NET Core SDK 6
12+
uses: actions/setup-dotnet@v1
13+
with:
14+
dotnet-version: 6.x
15+
- name: Add NuGet kiota source
16+
# TODO: Add NUGET_USER and NUGET_PASSWORD secrets
17+
# TODO: Add NUGET_URL to env
18+
# NOTE: Password encryption is not supported for the linux platform (Encryption is only supported on Windows platforms.)
19+
run: |
20+
dotnet nuget add source ${{env.NUGET_URL}} -n github -u ${{secrets.NUGET_USER}} -p ${{secrets.NUGET_PASSWORD}} --store-password-in-clear-text
21+
- uses: actions/cache@v2
22+
with:
23+
path: ~/.nuget/packages
24+
# Look to see if there is a cache hit for the corresponding requirements file
25+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
26+
restore-keys: |
27+
${{ runner.os }}-nuget
28+
- name: Install dependencies
29+
run: dotnet restore
30+
- name: Build
31+
run: dotnet build --configuration Release --no-restore

src/Program.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.CommandLine;
2+
using System.Threading.Tasks;
23

34
namespace Microsoft.Graph.Cli
45
{
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
using ApiSdk.Admin.ServiceAnnouncement;
2+
using ApiSdk.Models.Microsoft.Graph;
3+
using Microsoft.Kiota.Abstractions;
4+
using Microsoft.Kiota.Abstractions.Serialization;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.CommandLine;
8+
using System.CommandLine.Invocation;
9+
using System.IO;
10+
using System.Linq;
11+
using System.Text;
12+
using System.Threading;
13+
using System.Threading.Tasks;
14+
namespace ApiSdk.Admin {
15+
/// <summary>Builds and executes requests for operations under \admin</summary>
16+
public class AdminRequestBuilder {
17+
/// <summary>Path parameters for the request</summary>
18+
private Dictionary<string, object> PathParameters { get; set; }
19+
/// <summary>The request adapter to use to execute the requests.</summary>
20+
private IRequestAdapter RequestAdapter { get; set; }
21+
/// <summary>Url template to use to build the URL for the current request builder</summary>
22+
private string UrlTemplate { get; set; }
23+
/// <summary>
24+
/// Get admin
25+
/// </summary>
26+
public Command BuildGetCommand() {
27+
var command = new Command("get");
28+
command.Description = "Get admin";
29+
// Create options for all the parameters
30+
command.AddOption(new Option<object>("--select", description: "Select properties to be returned"));
31+
command.AddOption(new Option<object>("--expand", description: "Expand related entities"));
32+
command.Handler = CommandHandler.Create<object, object>(async (select, expand) => {
33+
var requestInfo = CreateGetRequestInformation();
34+
requestInfo.QueryParameters.Add("select", select);
35+
requestInfo.QueryParameters.Add("expand", expand);
36+
var result = await RequestAdapter.SendAsync<ApiSdk.Models.Microsoft.Graph.Admin>(requestInfo);
37+
// Print request output. What if the request has no return?
38+
using var serializer = RequestAdapter.SerializationWriterFactory.GetSerializationWriter("application/json");
39+
serializer.WriteObjectValue(null, result);
40+
using var content = serializer.GetSerializedContent();
41+
using var reader = new StreamReader(content);
42+
var strContent = await reader.ReadToEndAsync();
43+
Console.Write(strContent + "\n");
44+
});
45+
return command;
46+
}
47+
/// <summary>
48+
/// Update admin
49+
/// </summary>
50+
public Command BuildPatchCommand() {
51+
var command = new Command("patch");
52+
command.Description = "Update admin";
53+
// Create options for all the parameters
54+
command.AddOption(new Option<string>("--body"));
55+
command.Handler = CommandHandler.Create<string>(async (body) => {
56+
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(body));
57+
var parseNode = ParseNodeFactoryRegistry.DefaultInstance.GetRootParseNode("application/json", stream);
58+
var model = parseNode.GetObjectValue<ApiSdk.Models.Microsoft.Graph.Admin>();
59+
var requestInfo = CreatePatchRequestInformation(model);
60+
await RequestAdapter.SendNoContentAsync(requestInfo);
61+
// Print request output. What if the request has no return?
62+
Console.WriteLine("Success");
63+
});
64+
return command;
65+
}
66+
public Command BuildServiceAnnouncementCommand() {
67+
var command = new Command("service-announcement");
68+
var builder = new ApiSdk.Admin.ServiceAnnouncement.ServiceAnnouncementRequestBuilder(PathParameters, RequestAdapter);
69+
command.AddCommand(builder.BuildDeleteCommand());
70+
command.AddCommand(builder.BuildGetCommand());
71+
command.AddCommand(builder.BuildHealthOverviewsCommand());
72+
command.AddCommand(builder.BuildIssuesCommand());
73+
command.AddCommand(builder.BuildMessagesCommand());
74+
command.AddCommand(builder.BuildPatchCommand());
75+
return command;
76+
}
77+
/// <summary>
78+
/// Instantiates a new AdminRequestBuilder and sets the default values.
79+
/// <param name="pathParameters">Path parameters for the request</param>
80+
/// <param name="requestAdapter">The request adapter to use to execute the requests.</param>
81+
/// </summary>
82+
public AdminRequestBuilder(Dictionary<string, object> pathParameters, IRequestAdapter requestAdapter) {
83+
_ = pathParameters ?? throw new ArgumentNullException(nameof(pathParameters));
84+
_ = requestAdapter ?? throw new ArgumentNullException(nameof(requestAdapter));
85+
UrlTemplate = "{+baseurl}/admin{?select,expand}";
86+
var urlTplParams = new Dictionary<string, object>(pathParameters);
87+
PathParameters = urlTplParams;
88+
RequestAdapter = requestAdapter;
89+
}
90+
/// <summary>
91+
/// Get admin
92+
/// <param name="h">Request headers</param>
93+
/// <param name="o">Request options</param>
94+
/// <param name="q">Request query parameters</param>
95+
/// </summary>
96+
public RequestInformation CreateGetRequestInformation(Action<GetQueryParameters> q = default, Action<IDictionary<string, string>> h = default, IEnumerable<IRequestOption> o = default) {
97+
var requestInfo = new RequestInformation {
98+
HttpMethod = HttpMethod.GET,
99+
UrlTemplate = UrlTemplate,
100+
PathParameters = PathParameters,
101+
};
102+
if (q != null) {
103+
var qParams = new GetQueryParameters();
104+
q.Invoke(qParams);
105+
qParams.AddQueryParameters(requestInfo.QueryParameters);
106+
}
107+
h?.Invoke(requestInfo.Headers);
108+
requestInfo.AddRequestOptions(o?.ToArray());
109+
return requestInfo;
110+
}
111+
/// <summary>
112+
/// Update admin
113+
/// <param name="body"></param>
114+
/// <param name="h">Request headers</param>
115+
/// <param name="o">Request options</param>
116+
/// </summary>
117+
public RequestInformation CreatePatchRequestInformation(ApiSdk.Models.Microsoft.Graph.Admin body, Action<IDictionary<string, string>> h = default, IEnumerable<IRequestOption> o = default) {
118+
_ = body ?? throw new ArgumentNullException(nameof(body));
119+
var requestInfo = new RequestInformation {
120+
HttpMethod = HttpMethod.PATCH,
121+
UrlTemplate = UrlTemplate,
122+
PathParameters = PathParameters,
123+
};
124+
requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
125+
h?.Invoke(requestInfo.Headers);
126+
requestInfo.AddRequestOptions(o?.ToArray());
127+
return requestInfo;
128+
}
129+
/// <summary>
130+
/// Get admin
131+
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
132+
/// <param name="h">Request headers</param>
133+
/// <param name="o">Request options</param>
134+
/// <param name="q">Request query parameters</param>
135+
/// <param name="responseHandler">Response handler to use in place of the default response handling provided by the core service</param>
136+
/// </summary>
137+
public async Task<ApiSdk.Models.Microsoft.Graph.Admin> GetAsync(Action<GetQueryParameters> q = default, Action<IDictionary<string, string>> h = default, IEnumerable<IRequestOption> o = default, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) {
138+
var requestInfo = CreateGetRequestInformation(q, h, o);
139+
return await RequestAdapter.SendAsync<ApiSdk.Models.Microsoft.Graph.Admin>(requestInfo, responseHandler, cancellationToken);
140+
}
141+
/// <summary>
142+
/// Update admin
143+
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
144+
/// <param name="h">Request headers</param>
145+
/// <param name="model"></param>
146+
/// <param name="o">Request options</param>
147+
/// <param name="responseHandler">Response handler to use in place of the default response handling provided by the core service</param>
148+
/// </summary>
149+
public async Task PatchAsync(ApiSdk.Models.Microsoft.Graph.Admin model, Action<IDictionary<string, string>> h = default, IEnumerable<IRequestOption> o = default, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) {
150+
_ = model ?? throw new ArgumentNullException(nameof(model));
151+
var requestInfo = CreatePatchRequestInformation(model, h, o);
152+
await RequestAdapter.SendNoContentAsync(requestInfo, responseHandler, cancellationToken);
153+
}
154+
/// <summary>Get admin</summary>
155+
public class GetQueryParameters : QueryParametersBase {
156+
/// <summary>Expand related entities</summary>
157+
public string[] Expand { get; set; }
158+
/// <summary>Select properties to be returned</summary>
159+
public string[] Select { get; set; }
160+
}
161+
}
162+
}

0 commit comments

Comments
 (0)