-
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.
Refactor to support port list without connection and with console int…
…eraction.
- Loading branch information
1 parent
4badc53
commit ffc56af
Showing
15 changed files
with
131 additions
and
69 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,34 @@ | ||
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; } | ||
|
||
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(IConsole console, CancellationToken cancellationToken); | ||
|
||
public virtual async ValueTask ExecuteAsync(IConsole console) | ||
{ | ||
var cancellationToken = console.RegisterCancellationHandler(); | ||
|
||
try | ||
{ | ||
await ExecuteCommand(cancellationToken); | ||
await ExecuteCommand(console, 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
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
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
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.