Skip to content

Commit

Permalink
Merge pull request #592 from WildernessLabs/feature/source
Browse files Browse the repository at this point in the history
added source code capabilities to CLIv2
  • Loading branch information
adrianstevens authored Sep 3, 2024
2 parents bd192f1 + 1ed5bcc commit 96e66bf
Show file tree
Hide file tree
Showing 12 changed files with 526 additions and 1 deletion.
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
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;
}
}
1 change: 1 addition & 0 deletions Source/v2/Meadow.Cli/Meadow.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<ItemGroup>
<ProjectReference Include="..\Meadow.Dfu\Meadow.Dfu.csproj" />
<ProjectReference Include="..\Meadow.Linker\Meadow.Linker.csproj" />
<ProjectReference Include="..\Meadow.Repository\Meadow.Repository.csproj" />
<ProjectReference Include="..\Meadow.Tooling.Core\Meadow.Tooling.Core.csproj" />
<ProjectReference Include="..\Meadow.UsbLib\Meadow.UsbLib.csproj" />
</ItemGroup>
Expand Down
24 changes: 24 additions & 0 deletions Source/v2/Meadow.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,30 @@
"commandName": "Project",
"commandLineArgs": "flash os"
},
"source status": {
"commandName": "Project",
"commandLineArgs": "source status"
},
"source checkout": {
"commandName": "Project",
"commandLineArgs": "source checkout develop"
},
"source fetch": {
"commandName": "Project",
"commandLineArgs": "source fetch"
},
"source pull": {
"commandName": "Project",
"commandLineArgs": "source pull"
},
"source clone": {
"commandName": "Project",
"commandLineArgs": "source clone"
},
"config source": {
"commandName": "Project",
"commandLineArgs": "config source 'C:\\repos\\wilderness'"
},
"WSL": {
"commandName": "WSL2",
"distributionName": ""
Expand Down
17 changes: 17 additions & 0 deletions Source/v2/Meadow.Repository/Meadow.Repository.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.30.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Meadow.Tooling.Core\Meadow.Tooling.Core.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit 96e66bf

Please sign in to comment.