Closed jasonjoh closed 2 years ago
Hey @jasonjoh. Even more than PHP, the CLI generation capability is still in its early days. You might want to try generating with #1326 that @calebkiage started putting together when working with CLI generation.
It did fix the first issue that blocked compile, but the Service not found
error persists.
@calebkiage please assist Jason on this one
@jasonjoh, you need to set up the services when building your command line. See microsoftgraph/msgraph-cli:Program.cs#L83
Thanks @calebkiage. It looks like the Kiota library doesn't provide any implementations of IOutputFilter
or IOutputFormatterFactory
, is that right? I see implementations in Microsoft.Graph.Cli.Core.IO.
Are there any plans to move those to Kiota so there are default implementations?
I created a simple implementation of those two interfaces to just print JSON. Now when I try to execute, I'm getting this error:
Method not found: 'System.Object System.CommandLine.Parsing.ParseResult.GetValueForArgument(System.CommandLine.IArgument)'.
at Microsoft.Kiota.Cli.Commons.Binding.CollectionBinding.GetValueForHandlerParameter(IValueDescriptor[] symbols, Int32 index, BindingContext context)
at Microsoft.Kiota.Cli.Commons.Binding.CollectionBinding.GetBoundValue(BindingContext bindingContext)
at System.CommandLine.Binding.BinderBase`1.System.CommandLine.Binding.IValueSource.TryGetValue(IValueDescriptor valueDescriptor, BindingContext bindingContext, Object& boundValue)
at System.CommandLine.Handler.GetValueForHandlerParameter[T](IValueDescriptor[] symbols, Int32& index, InvocationContext conte--- End--- End of stack trace from previous location ---
at System.CommandLine.Hosting.HostingExtensions.<>c__DisplayClass1_0.<<UseHost>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass13_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass20_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__19_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__6_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass9_0.<<UseExceptionHandler>b__0>d.MoveNext()
Ok, disregard that last. I was still using the latest package from the private feed. When I switched to use a project reference with the latest code in your branch, it worked!
So I guess the questions I still have are about default implementations for JSON and table output.
Default implementations will be available in commons once PR https://github.com/microsoft/kiota/pull/1326 is merged
I was using the build from 1326 and I see the formatters, but no formatter factory or output filters.
using 0.1.10-preview.1 version, I've faced the same problem any hint, how and where to assign output filter?
....
public Command BuildGetCommand() {
var command = new Command("get");....
command.SetHandler(async (invocationContext) => {
var output = invocationContext.ParseResult.GetValueForOption(outputOption);
var query = invocationContext.ParseResult.GetValueForOption(queryOption);
var jsonNoIndent = invocationContext.ParseResult.GetValueForOption(jsonNoIndentOption);
var outputFilter = invocationContext.BindingContext.GetRequiredService
replacing those two lines inside generated BuildGetCommand method solved the problem without knowing any side effects:
//invocationContext.BindingContext.GetRequiredService
//invocationContext.BindingContext.GetRequiredService
I generated a client using the
shell
language option to do aGET /me
on Microsoft Graph. The code has an error and won't compile. InBuildGetCommand
:The compiler says:
I changed it manually to
formatter.WriteOutput(response, new JsonOutputFormatterOptions());
, but trying to run it throws an exception:Command line
getme.yml
Program.cs