Skip to content
Merged

V7 #182

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/package_version.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PI_MAJOR_VERSION=7
PI_MINOR_VERSION=0
PI_PATCH_VERSION=0
PI_MINOR_VERSION=1
PI_PATCH_VERSION=1
PI_DEPENDENCIES_SUFFIX=-*
2 changes: 1 addition & 1 deletion apps/auth/TestMsal/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private static void ConfigureLoggingDelegate(HostBuilderContext context, ILoggin

// Configure logging of your choice, here we are configuring Serilog
var loggerConfig = new LoggerConfiguration();
loggerConfig.MinimumLevel.Error();
loggerConfig.MinimumLevel.Verbose();
loggerConfig.WriteTo.Console();
Log.Logger = loggerConfig.CreateLogger();
builder.AddSerilog(Log.Logger);
Expand Down
4 changes: 2 additions & 2 deletions apps/auth/TestMsal/Runners/AuthRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace OneImlx.Terminal.Apps.TestAuth.Runners
/// </summary>
[CommandOwners("test")]
[CommandDescriptor("auth", "Auth group", "Test auth group description.", CommandTypes.IsolatedGroup)]
public class AuthRunner : CommandRunner<CommandRunnerResult>, IDeclarativeRunner
public class AuthRunner : CommandRunner<CommandContext, CommandRunnerResult>, IDeclarativeRunner
{
private readonly ITerminalConsole _terminalConsole;
private readonly ILogger<AuthRunner> _logger;
Expand All @@ -34,7 +34,7 @@ public AuthRunner(ITerminalConsole terminalConsole, ILogger<AuthRunner> logger)
/// </summary>
/// <param name="context">Command runner context.</param>
/// <returns>Command runner result.</returns>
public override async Task<CommandRunnerResult> RunCommandAsync(ICommandContext context)
public override async Task<CommandRunnerResult> RunCommandAsync(CommandContext context)
{
await _terminalConsole.WriteLineAsync("Auth group command called.");

Expand Down
4 changes: 2 additions & 2 deletions apps/auth/TestMsal/Runners/AuthUserRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace OneImlx.Terminal.Apps.TestAuth.Runners
/// </summary>
[CommandOwners("auth")]
[CommandDescriptor("user", "Get user", "Fetches user information from Microsoft Graph API.", CommandTypes.IsolatedGroup)]
public class AuthUserRunner : CommandRunner<CommandRunnerResult>, IDeclarativeRunner
public class AuthUserRunner : CommandRunner<CommandContext, CommandRunnerResult>, IDeclarativeRunner
{
/// <summary>
/// Initializes a new instance.
Expand All @@ -36,7 +36,7 @@ public AuthUserRunner(ITerminalConsole terminalConsole, IHttpClientFactory httpC
/// </summary>
/// <param name="context">Command runner context.</param>
/// <returns>Command runner result.</returns>
public override async Task<CommandRunnerResult> RunCommandAsync(ICommandContext context)
public override async Task<CommandRunnerResult> RunCommandAsync(CommandContext context)
{

// Get the HTTP client from the factory with the name "demo-http" since this name is configured to use the
Expand Down
9 changes: 3 additions & 6 deletions apps/auth/TestMsal/Runners/TestAuthRunner.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// Copyright © 2019-2026 Perpetual Intelligence L.L.C. All rights reserved.
// For license, terms, and data policies, go to:
// https://terms.perpetualintelligence.com/articles/intro.html
using System;
using System;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using OneImlx.Terminal.Commands;
Expand All @@ -20,7 +17,7 @@ namespace OneImlx.Terminal.Apps.TestAuth.Runners
[CommandDescriptor("test", "Test App", "Test application description.", CommandTypes.Root)]
[OptionDescriptor("version", nameof(String), "Test version description", BehaviorFlags.None, "v")]
[CommandChecker(typeof(CommandChecker))]
public class TestRunner : CommandRunner<CommandRunnerResult>, IDeclarativeRunner
public class TestRunner : CommandRunner<CommandContext, CommandRunnerResult>, IDeclarativeRunner
{
/// <summary>
/// Initializes a new instance.
Expand All @@ -38,7 +35,7 @@ public TestRunner(ITerminalConsole terminalConsole, ILogger<TestRunner> logger)
/// </summary>
/// <param name="context">Command runner context.</param>
/// <returns>Command runner result.</returns>
public override async Task<CommandRunnerResult> RunCommandAsync(ICommandContext context)
public override async Task<CommandRunnerResult> RunCommandAsync(CommandContext context)
{
await _terminalConsole.WriteLineAsync("Test root command called.");

Expand Down
2 changes: 1 addition & 1 deletion apps/cli/TestConsole/Checkers/Cmd3CommandChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public Cmd3CommandChecker(ITerminalConsole terminalConsole)
this.terminalConsole = terminalConsole;
}

public Task<CommandCheckerResult> CheckCommandAsync(ICommandContext context)
public Task<CommandCheckerResult> CheckCommandAsync(CommandContext context)
{
terminalConsole.WriteLineAsync("Cmd3 custom checker called.");
return Task.FromResult(new CommandCheckerResult());
Expand Down
9 changes: 9 additions & 0 deletions apps/cli/TestConsole/Custom/CustomCommandContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;
using OneImlx.Terminal.Shared;

namespace OneImlx.Terminal.Apps.Test.Custom
{
public class CustomCommandContext(Dictionary<string, object> properties) : CommandContext(properties)
{
}
}
28 changes: 28 additions & 0 deletions apps/cli/TestConsole/Custom/CustomCommandContextFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using OneImlx.Terminal.Extensions;
using OneImlx.Terminal.Shared;
using System;
using System.Collections.Generic;
using System.Text;

namespace OneImlx.Terminal.Apps.Test.Custom
{
internal class CustomCommandContextFactory : ICommandContextFactory
{
public CommandContext Create(CommandRequest request, TerminalRouterContext routerContext, Dictionary<string, object> properties)
{
var context = new CustomCommandContext(properties);
context.SetCommandRequest(request);
context.SetRouterContext(routerContext);
return context;

}

public TContext Create<TContext>(CommandRequest request, TerminalRouterContext routerContext, Dictionary<string, object> properties) where TContext : CommandContext
{
var context = new CustomCommandContext(properties);
context.SetCommandRequest(request);
context.SetRouterContext(routerContext);
return (TContext) (CommandContext) context;
}
}
}
15 changes: 15 additions & 0 deletions apps/cli/TestConsole/Custom/CustomRunnerResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using OneImlx.Terminal.Commands.Runners;

namespace OneImlx.Terminal.Apps.Test.Custom
{
public class CustomRunnerResult : CommandRunnerResult
{
public CustomRunnerResult()
{
}

public CustomRunnerResult(object value) : base(value)
{
}
}
}
5 changes: 3 additions & 2 deletions apps/cli/TestConsole/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using OneImlx.Shared.Licensing;
using OneImlx.Terminal.Apps.Test.Custom;
using OneImlx.Terminal.Apps.Test.Runners;
using OneImlx.Terminal.Commands;
using OneImlx.Terminal.Extensions;
Expand Down Expand Up @@ -64,8 +65,8 @@ private static void ConfigureOneImlxTerminal(IServiceCollection collection)
options.Router.Caret = "> ";
});

// Default command context
terminalBuilder.AddCommandContextFactory<CommandContextFactory>();
// Custom command context
terminalBuilder.AddCommandContextFactory<CustomCommandContextFactory>();

// Add commands using declarative syntax.
terminalBuilder.AddDeclarativeAssembly<TestRunner>();
Expand Down
9 changes: 5 additions & 4 deletions apps/cli/TestConsole/Runners/ClearRunner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Threading.Tasks;
using OneImlx.Terminal.Apps.Test.Custom;
using OneImlx.Terminal.Commands;
using OneImlx.Terminal.Commands.Runners;
using OneImlx.Terminal.Runtime;
Expand All @@ -11,7 +12,7 @@ namespace OneImlx.Terminal.Apps.Test.Runners
/// Clears the console.
/// </summary>
[CommandDescriptor("cls", "Clear Console", "Clears the console.", CommandTypes.Native)]
public class ClearRunner : CommandRunner<CommandRunnerResult>, IDeclarativeRunner
public class ClearRunner : CommandRunner<CustomCommandContext, CustomRunnerResult>, IDeclarativeRunner
{
/// <summary>
/// Initializes a new instance of the <see cref="ClearRunner"/> class.
Expand All @@ -23,12 +24,12 @@ public ClearRunner(ITerminalConsole terminalConsole)
}

/// <inheritdoc/>
public override async Task<CommandRunnerResult> RunCommandAsync(ICommandContext context)
public override async Task<CustomRunnerResult> RunCommandAsync(CustomCommandContext context)
{
await terminalConsole.ClearAsync();
return await CommandRunnerResult.EmptyAsync();
return new CustomRunnerResult();
}

private readonly ITerminalConsole terminalConsole;
}
}
}
8 changes: 5 additions & 3 deletions apps/cli/TestConsole/Runners/Cmd7Runner.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Extensions.Logging;
using OneImlx.Terminal.Apps.Test.Custom;
using OneImlx.Terminal.Commands;
using OneImlx.Terminal.Commands.Runners;
using OneImlx.Terminal.Extensions;
using OneImlx.Terminal.Runtime;
using OneImlx.Terminal.Shared;
using OneImlx.Terminal.Shared.Declarative;
Expand All @@ -13,7 +15,7 @@ namespace OneImlx.Terminal.Apps.Test.Runners
/// </summary>
[CommandOwners("grp3")]
[CommandDescriptor("cmd7", "Command 7", "Command 7 under grp3.", CommandTypes.Leaf)]
public class Cmd7Runner : CommandRunner<CommandRunnerResult>, IDeclarativeRunner
public class Cmd7Runner : CommandRunner<CustomCommandContext, CustomRunnerResult>, IDeclarativeRunner
{
private readonly ITerminalConsole terminalConsole;
private readonly ILogger<Cmd7Runner> logger;
Expand All @@ -24,12 +26,12 @@ public Cmd7Runner(ITerminalConsole terminalConsole, ILogger<Cmd7Runner> logger)
this.logger = logger;
}

public override async Task<CommandRunnerResult> RunCommandAsync(ICommandContext context)
public override async Task<CustomRunnerResult> RunCommandAsync(CustomCommandContext context)
{
logger.LogInformation("Executing grp3 cmd7");
await terminalConsole.WriteLineAsync("Executing: grp3 cmd7");
await terminalConsole.WriteLineAsync("This is a leaf command under isolated group grp3.");
return new CommandRunnerResult();
return new CustomRunnerResult();
}
}
}
7 changes: 4 additions & 3 deletions apps/cli/TestConsole/Runners/Cmd8Runner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using OneImlx.Terminal.Apps.Test.Custom;
using OneImlx.Terminal.Commands;
using OneImlx.Terminal.Commands.Runners;
using OneImlx.Terminal.Runtime;
Expand All @@ -13,7 +14,7 @@ namespace OneImlx.Terminal.Apps.Test.Runners
/// </summary>
[CommandOwners("grp3")]
[CommandDescriptor("cmd8", "Command 8", "Command 8 under grp3.", CommandTypes.Leaf)]
public class Cmd8Runner : CommandRunner<CommandRunnerResult>, IDeclarativeRunner
public class Cmd8Runner : CommandRunner<CustomCommandContext, CustomRunnerResult>, IDeclarativeRunner
{
private readonly ITerminalConsole terminalConsole;
private readonly ILogger<Cmd8Runner> logger;
Expand All @@ -24,12 +25,12 @@ public Cmd8Runner(ITerminalConsole terminalConsole, ILogger<Cmd8Runner> logger)
this.logger = logger;
}

public override async Task<CommandRunnerResult> RunCommandAsync(ICommandContext context)
public override async Task<CustomRunnerResult> RunCommandAsync(CustomCommandContext context)
{
logger.LogInformation("Executing grp3 cmd8");
await terminalConsole.WriteLineAsync("Executing: grp3 cmd8");
await terminalConsole.WriteLineAsync("This is a leaf command under isolated group grp3.");
return new CommandRunnerResult();
return new CustomRunnerResult();
}
}
}
8 changes: 4 additions & 4 deletions apps/cli/TestConsole/Runners/Cmd9Runner.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Microsoft.Extensions.Logging;
using OneImlx.Terminal.Apps.Test.Checkers;
using OneImlx.Terminal.Apps.Test.Custom;
using OneImlx.Terminal.Commands;
using OneImlx.Terminal.Commands.Checkers;
using OneImlx.Terminal.Commands.Runners;
using OneImlx.Terminal.Runtime;
using OneImlx.Terminal.Shared;
Expand All @@ -16,7 +16,7 @@ namespace OneImlx.Terminal.Apps.Test.Runners
[CommandOwners("grp3")]
[CommandDescriptor("cmd9", "Command 9", "Command 9 under grp3 with custom checker.", CommandTypes.Leaf)]
[CommandChecker(typeof(Cmd3CommandChecker))]
public class Cmd9Runner : CommandRunner<CommandRunnerResult>, IDeclarativeRunner
public class Cmd9Runner : CommandRunner<CustomCommandContext, CustomRunnerResult>, IDeclarativeRunner
{
private readonly ITerminalConsole terminalConsole;
private readonly ILogger<Cmd9Runner> logger;
Expand All @@ -27,12 +27,12 @@ public Cmd9Runner(ITerminalConsole terminalConsole, ILogger<Cmd9Runner> logger)
this.logger = logger;
}

public override async Task<CommandRunnerResult> RunCommandAsync(ICommandContext context)
public override async Task<CustomRunnerResult> RunCommandAsync(CustomCommandContext context)
{
logger.LogInformation("Executing grp3 cmd9");
await terminalConsole.WriteLineAsync("Executing: grp3 cmd9");
await terminalConsole.WriteLineAsync("This is a leaf command with custom checker under grp3.");
return new CommandRunnerResult();
return new CustomRunnerResult();
}
}
}
19 changes: 8 additions & 11 deletions apps/cli/TestConsole/Runners/ExitRunner.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,39 @@
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
using Microsoft.Extensions.Hosting;
using OneImlx.Terminal.Apps.Test.Custom;
using OneImlx.Terminal.Commands;
using OneImlx.Terminal.Commands.Runners;
using OneImlx.Terminal.Runtime;
using OneImlx.Terminal.Shared;
using OneImlx.Terminal.Shared.Declarative;
using System.Threading.Tasks;

namespace OneImlx.Terminal.Apps.Test.Runners
{
/// <summary>
/// Runs native OS commands.
/// Exits the client terminal application.
/// </summary>
[CommandDescriptor("exit", "Exit", "Exits the client terminal application.", CommandTypes.Native)]
public class ExitRunner : CommandRunner<CommandRunnerResult>, IDeclarativeRunner
public class ExitRunner : CommandRunner<CustomCommandContext, CustomRunnerResult>, IDeclarativeRunner
{
/// <summary>
/// Initializes a new instance of the <see cref="ExitRunner"/> class.
/// </summary>
public ExitRunner(ITerminalConsole terminalConsole, IHostApplicationLifetime applicationLifetime)
{
this.terminalConsole = terminalConsole;
_applicationLifetime = applicationLifetime;
}

/// <inheritdoc/>
public override async Task<CommandRunnerResult> RunCommandAsync(ICommandContext context)
public override async Task<CustomRunnerResult> RunCommandAsync(CustomCommandContext context)
{
string answer = await terminalConsole.ReadAnswerAsync("Are you sure you want to exit ?", "y", "Y");
if (answer == "y" || answer == "Y")
{
_applicationLifetime.StopApplication();
await Task.Delay(2000);
}

return CommandRunnerResult.Empty();
return new CustomRunnerResult();
}

private readonly IHostApplicationLifetime _applicationLifetime;
private readonly ITerminalConsole terminalConsole;
}
}
}
Loading
Loading