Skip to content

Commit

Permalink
Merge branch 'develop' into dominique-TemplateWizard
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianstevens authored Sep 25, 2024
2 parents d7b18e5 + e14f43f commit 2acce33
Show file tree
Hide file tree
Showing 118 changed files with 620 additions and 182 deletions.
1 change: 1 addition & 0 deletions Meadow.CLI.Core/lib/meadow_link.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@
<assembly fullname="SQLite-net" />
<assembly fullname="MQTTnet" />
<assembly fullname="System.Configuration" />
<assembly fullname="ProjectLab" />
</linker>
8 changes: 7 additions & 1 deletion Source/v2/Meadow.CLI.v2.sln
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,20 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Dfu", "Meadow.Dfu\Me
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Firmware", "Meadow.Firmware\Meadow.Firmware.csproj", "{D2274F30-A001-482A-99E3-0AB1970CF695}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Meadow.Tooling.Core", "Meadow.Tooling.Core\Meadow.Tooling.Core.csproj", "{A22DBF4A-E472-445E-96C0-930C126039C2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Meadow.Tooling.Core", "Meadow.Tooling.Core\Meadow.Tooling.Core.csproj", "{A22DBF4A-E472-445E-96C0-930C126039C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Meadow.Repository", "Meadow.Repository\Meadow.Repository.csproj", "{66E4476E-41C6-4618-BBC2-98C6277757E6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{66E4476E-41C6-4618-BBC2-98C6277757E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{66E4476E-41C6-4618-BBC2-98C6277757E6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{66E4476E-41C6-4618-BBC2-98C6277757E6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{66E4476E-41C6-4618-BBC2-98C6277757E6}.Release|Any CPU.Build.0 = Release|Any CPU
{6C2FA084-701B-4A28-8775-BF18B84E366B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C2FA084-701B-4A28-8775-BF18B84E366B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C2FA084-701B-4A28-8775-BF18B84E366B}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down
29 changes: 18 additions & 11 deletions Source/v2/Meadow.CLI/Commands/Current/App/AppTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ namespace Meadow.CLI.Commands.DeviceManagement;

internal static class AppTools
{
internal const string MeadowRootFolder = "meadow0";

internal static string ValidateAndSanitizeAppPath(string? path)
{
path ??= Directory.GetCurrentDirectory();
Expand Down Expand Up @@ -64,16 +62,25 @@ internal static async Task<bool> TrimApplication(string path,

if (configuration is not null)
{
file = candidates
.Where(c => c.DirectoryName.IndexOf(configuration, StringComparison.OrdinalIgnoreCase) >= 0)
.OrderByDescending(c => c.LastWriteTime)
.First();
var foundConfiguration = candidates.Where(c => c.DirectoryName?.IndexOf(configuration, StringComparison.OrdinalIgnoreCase) >= 0);

if (file == null)
if (foundConfiguration.Count() == 0)
{
logger?.LogError($"{Strings.NoCompiledApplicationFound} at '{path}'");
logger?.LogError($"{Strings.NoCompiledApplicationFound} {Strings.WithConfiguration} '{configuration}' {Strings.At} '{path}'");
return false;
}
else
{
file = foundConfiguration
.OrderByDescending(c => c.LastWriteTime)
.First();

if (file == null)
{
logger?.LogError($"{Strings.NoCompiledApplicationFound} {Strings.At} '{path}'");
return false;
}
}
}
else
{
Expand Down Expand Up @@ -116,15 +123,15 @@ internal static string SanitizeMeadowFilename(string fileName)

if (string.IsNullOrWhiteSpace(folder))
{
folder = Path.DirectorySeparatorChar + MeadowRootFolder;
folder = Path.DirectorySeparatorChar + AppManager.MeadowRootFolder;
}
else
{
if (!folder.StartsWith(Path.DirectorySeparatorChar))
{
if (!folder.StartsWith($"{MeadowRootFolder}"))
if (!folder.StartsWith($"{AppManager.MeadowRootFolder}"))
{
folder = $"{Path.DirectorySeparatorChar}{MeadowRootFolder}{Path.DirectorySeparatorChar}{folder}";
folder = $"{Path.DirectorySeparatorChar}{AppManager.MeadowRootFolder}{Path.DirectorySeparatorChar}{folder}";
}
else
{
Expand Down
24 changes: 24 additions & 0 deletions Source/v2/Meadow.CLI/Commands/Current/Config/ConfigRouteCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using CliFx.Attributes;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;

[Command("config route", Description = "Sets the communication route for HCOM")]
public class ConfigRouteCommand : BaseSettingsCommand<ConfigCommand>
{
[CommandParameter(0, Name = "Route", IsRequired = true)]
public string Route { get; init; }

public ConfigRouteCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(settingsManager, loggerFactory)
{ }


protected override ValueTask ExecuteCommand()
{
Logger?.LogInformation($"{Environment.NewLine}Setting route={Route}");
SettingsManager.SaveSetting("route", Route);

return ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using CliFx.Attributes;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;

[Command("config source", Description = "Sets the root folder for Meadow source directories")]
public class ConfigSourceCommand : BaseSettingsCommand<ConfigCommand>
{
[CommandParameter(0, Name = "Root", IsRequired = false)]
public string? Root { get; init; }

public ConfigSourceCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(settingsManager, loggerFactory)
{ }


protected override ValueTask ExecuteCommand()
{
var root = Root;

// if Root is null, as the user if they want to use the current folder
if (string.IsNullOrWhiteSpace(Root))
{
System.Console.Write("No root folder provided. You you want to use the current directory? (y/n) ");
if (System.Console.ReadLine()?.Trim() != "y")
{
System.Console.WriteLine("cancelled");
return ValueTask.CompletedTask;
}

root = Environment.CurrentDirectory;
}

root!.Trim('\'').Trim('"'); ;
Logger?.LogInformation($"{Environment.NewLine}Setting source={root}");
SettingsManager.SaveSetting("source", root!);

return ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using CliFx.Attributes;
using Meadow.Tools;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;

[Command("source checkout", Description = "Pulls a single-named branch of all Meadow source repositories")]
public class SourceCheckoutCommand : BaseCommand<AppBuildCommand>
{
private ISettingsManager _settingsManager;

[CommandParameter(0, Description = Strings.PathToMeadowProject, IsRequired = true)]
public string Branch { get; init; }

public SourceCheckoutCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(loggerFactory)
{
_settingsManager = settingsManager;
}

protected override ValueTask ExecuteCommand()
{
var root = new MeadowRoot(_settingsManager);

root.Checkout(Branch);

return default;
}
}
26 changes: 26 additions & 0 deletions Source/v2/Meadow.CLI/Commands/Current/Source/SourceFetchCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CliFx.Attributes;
using Meadow.Tools;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;

[Command("source fetch", Description = "Fetches each of the local Meadow source repositories")]
public class SourceFetchCommand : BaseCommand<AppBuildCommand>
{
private ISettingsManager _settingsManager;

public SourceFetchCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(loggerFactory)
{
_settingsManager = settingsManager;
}

protected override ValueTask ExecuteCommand()
{
var root = new MeadowRoot(_settingsManager);

root.Fetch();

return default;
}
}
47 changes: 47 additions & 0 deletions Source/v2/Meadow.CLI/Commands/Current/Source/SourcePullCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CliFx.Attributes;
using Meadow.Tools;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;

[Command("source clone", Description = "Clones any missing local Meadow source repositories")]
public class SourceCloneCommand : BaseCommand<AppBuildCommand>
{
private ISettingsManager _settingsManager;

public SourceCloneCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(loggerFactory)
{
_settingsManager = settingsManager;
}

protected override ValueTask ExecuteCommand()
{
var root = new MeadowRoot(_settingsManager);

root.Clone();

return default;
}
}

[Command("source pull", Description = "Pulls each of the local Meadow source repositories")]
public class SourcePullCommand : BaseCommand<AppBuildCommand>
{
private ISettingsManager _settingsManager;

public SourcePullCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(loggerFactory)
{
_settingsManager = settingsManager;
}

protected override ValueTask ExecuteCommand()
{
var root = new MeadowRoot(_settingsManager);

root.Pull();

return default;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using CliFx.Attributes;
using Meadow.Tools;
using Microsoft.Extensions.Logging;

namespace Meadow.CLI.Commands.DeviceManagement;

[Command("source status", Description = "Compares the local Meadow source repositories with the remotes")]
public class SourceStatusCommand : BaseCommand<AppBuildCommand>
{
private ISettingsManager _settingsManager;

public SourceStatusCommand(ISettingsManager settingsManager, ILoggerFactory loggerFactory)
: base(loggerFactory)
{
_settingsManager = settingsManager;
}

protected override ValueTask ExecuteCommand()
{
var root = new MeadowRoot(_settingsManager);

root.Status();

return default;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Meadow.CLI.Commands.DeviceManagement;

[Command("device clock", Description = "Gets or sets the device clock (in UTC time)")]
[Command("device clock", Description = "Gets or sets the device clock (in UTC time). Use either 'now' or a date/time inside single quotes")]
public class DeviceClockCommand : BaseDeviceCommand<DeviceInfoCommand>
{
[CommandParameter(0, Name = "Time", IsRequired = false)]
Expand Down
10 changes: 10 additions & 0 deletions Source/v2/Meadow.Cli/Commands/Current/File/FileDeleteCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ protected override async ValueTask ExecuteCommand()
private async Task DeleteFileRecursive(IMeadowDevice device, string directoryname, MeadowFileInfo fileInfo, CancellationToken cancellationToken)
{
var meadowFile = AppTools.SanitizeMeadowFilename(Path.Combine(directoryname, fileInfo.Name));

foreach (var folder in AppManager.PersistantFolders)
{
if (meadowFile.StartsWith($"/{AppManager.MeadowRootFolder}/{folder}"))
{
return;
}
}

if (fileInfo.IsDirectory)
{
// Add a backslash as we're a directory and not a file
Expand All @@ -92,5 +101,6 @@ private async Task DeleteFileRecursive(IMeadowDevice device, string directorynam
Logger?.LogInformation($"Deleting file '{meadowFile}' from device...");

await device.DeleteFile(meadowFile, cancellationToken);
await Task.Delay(100);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected override async ValueTask ExecuteCommand()

Logger?.LogInformation($"Reading file '{MeadowFile}' from device...\n");

var data = await device.ReadFileString(AppTools.SanitizeMeadowFilename(MeadowFile), CancellationToken);
var data = await device.ReadFileString(MeadowFile, CancellationToken);

if (data == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected override async ValueTask ExecuteCommand()
Logger?.LogInformation($"Getting file list...");
}

var files = await device.GetFileList(Folder ?? $"/{AppTools.MeadowRootFolder}/", Verbose, CancellationToken);
var files = await device.GetFileList(Folder ?? $"/{AppManager.MeadowRootFolder}/", Verbose, CancellationToken);

if (files == null || files.Length == 0)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ protected override async ValueTask ExecuteCommand()
}
else
{
await connection!.Device!.WriteFile(osFileWithoutBootloader, $"/{AppTools.MeadowRootFolder}/update/os/{package.OsWithoutBootloader}");
await connection!.Device!.WriteFile(osFileWithoutBootloader, $"/{AppManager.MeadowRootFolder}/update/os/{package.OsWithoutBootloader}");
}
}

Expand Down Expand Up @@ -361,7 +361,7 @@ private async Task<IMeadowConnection> FindMeadowConnection(IList<string> portsTo
}
else
{
await connection.Device!.WriteFile(runtimePath, $"/{AppTools.MeadowRootFolder}/update/os/{destinationFilename}");
await connection.Device!.WriteFile(runtimePath, $"/{AppManager.MeadowRootFolder}/update/os/{destinationFilename}");
}

return connection;
Expand Down Expand Up @@ -403,7 +403,8 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi
{
foreach (var file in fileList)
{
await connection!.Device!.WriteFile(file, $"/{AppTools.MeadowRootFolder}/update/os/{Path.GetFileName(file)}");
await connection!.Device!.WriteFile(file, $"/{AppManager.MeadowRootFolder}/update/os/{Path.GetFileName(file)}");
await Task.Delay(500);
}
}
}
Expand Down
16 changes: 0 additions & 16 deletions Source/v2/Meadow.Cli/Commands/Legacy/DownloadOsCommand.cs

This file was deleted.

Loading

0 comments on commit 2acce33

Please sign in to comment.