You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 14, 2025. It is now read-only.
Currently, the solution I found was to simply make use of ICoconaCommandDispatcher myself and to create a while loop that listens for console input (see example below)
usingCocona;usingCocona.Command;usingCocona.Command.Dispatcher;varbuilder=CoconaApp.CreateBuilder();varapp=builder.Build();app.AddCommand("hello",([Argument]stringname)=>Console.WriteLine($"Hello {name}!")).WithDescription("Say hello");app.AddCommand("bye",([Argument]stringname)=>Console.WriteLine($"Goodbye {name}!")).WithDescription("Say goodbye");// Main loop command.app.AddCommand(async(CoconaAppContextctx,ICoconaCommandDispatcherdispatcher,ICoconaCommandResolverresolver,ICoconaCommandProviderprovider,ICoconaCommandMatchermatcher)=>{varcommandsCollection=provider.GetCommandCollection();while(!ctx.CancellationToken.IsCancellationRequested){Console.Write("> ");varinput=Console.ReadLine();if(string.IsNullOrWhiteSpace(input)){// Listen for another message.continue;}vartokens=input.Split(' ',StringSplitOptions.RemoveEmptyEntries);CommandResolverResultresolvedCommand=default;try{resolvedCommand=resolver.ParseAndResolve(commandsCollection,tokens);}catch(CommandNotFoundException){// For some reason, instead of resolving the command and setting the success flag to 'False', the method may throw an exception.}// Ignore main loop or try again if resolver fain to build the command.if(!resolvedCommand.Success||resolvedCommand.MatchedCommand==null||resolvedCommand.MatchedCommand.IsPrimaryCommand){Console.WriteLine($"Command input '{input}' couldn't be resolved");continue;}awaitdispatcher.DispatchAsync(resolvedCommand,ctx.CancellationToken);}});awaitapp.RunAsync();
Is there any built in support for REPL in Cocona?
Currently, the solution I found was to simply make use of
ICoconaCommandDispatchermyself and to create a while loop that listens for console input (see example below)Is there a better way to do it? something like: