-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into v2
- Loading branch information
Showing
18 changed files
with
205 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,37 @@ | ||
using CliFx; | ||
using CliFx.Infrastructure; | ||
using Meadow.Cli; | ||
using Meadow.Hcom; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Meadow.CLI.Commands.DeviceManagement; | ||
|
||
public abstract class BaseCommand<T> : ICommand | ||
{ | ||
protected ILogger<T> Logger { get; } | ||
protected ISettingsManager SettingsManager { get; } | ||
protected ILogger<T>? Logger { get; } | ||
protected ILoggerFactory? LoggerFactory { get; } | ||
protected IConsole? Console { get; private set; } | ||
|
||
public BaseCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory) | ||
public BaseCommand(ILoggerFactory? loggerFactory) | ||
{ | ||
Logger = loggerFactory.CreateLogger<T>(); | ||
SettingsManager = settingsManager; | ||
LoggerFactory = loggerFactory; | ||
Logger = loggerFactory?.CreateLogger<T>(); | ||
} | ||
|
||
protected abstract ValueTask ExecuteCommand(CancellationToken cancellationToken); | ||
protected abstract ValueTask ExecuteCommand(CancellationToken? cancellationToken); | ||
|
||
public virtual async ValueTask ExecuteAsync(IConsole console) | ||
{ | ||
var cancellationToken = console.RegisterCancellationHandler(); | ||
Console = console; | ||
var cancellationToken = Console?.RegisterCancellationHandler(); | ||
|
||
try | ||
{ | ||
await ExecuteCommand(cancellationToken); | ||
if (cancellationToken!= null) | ||
await ExecuteCommand(cancellationToken); | ||
} | ||
catch (Exception ex) | ||
{ | ||
Logger.LogError(ex.Message); | ||
Logger?.LogError(ex.Message); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Source/v2/Meadow.Cli/Commands/Current/BaseSettingsCommand.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using CliFx.Infrastructure; | ||
using Meadow.Cli; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Meadow.CLI.Commands.DeviceManagement; | ||
|
||
public abstract class BaseSettingsCommand<T> : BaseCommand<T> | ||
{ | ||
protected ISettingsManager SettingsManager { get; } | ||
|
||
public BaseSettingsCommand(ISettingsManager settingsManager, ILoggerFactory? loggerFactory) | ||
: base (loggerFactory) | ||
{ | ||
SettingsManager = settingsManager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.