Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing quotes and refactor path handling for App Run Meadow command. #469

Merged
22 changes: 15 additions & 7 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppRunCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CliFx.Attributes;
using CliFx.Exceptions;
using Meadow.Hcom;
using Meadow.Package;
using Microsoft.Extensions.Logging;
Expand All @@ -17,7 +18,7 @@ public class AppRunCommand : BaseDeviceCommand<AppRunCommand>
[CommandOption('c', Description = "The build configuration to compile", IsRequired = false)]
public string? Configuration { get; set; }

[CommandParameter(0, Name = "Path to folder containing the built application", IsRequired = false)]
[CommandParameter(0, Name = "Path to folder containing the application to build.", IsRequired = false)]
public string? Path { get; init; }

public AppRunCommand(IPackageManager packageManager, MeadowConnectionManager connectionManager, ILoggerFactory loggerFactory)
Expand All @@ -28,21 +29,28 @@ public AppRunCommand(IPackageManager packageManager, MeadowConnectionManager con

protected override async ValueTask ExecuteCommand()
{
var connection = await GetCurrentConnection();
string path = Path ?? Directory.GetCurrentDirectory();

if (connection == null)
// is the path a file?
if (!File.Exists(path))
{
return;
// is it a valid directory?
if (!Directory.Exists(path))
{
throw new CommandException($"Invalid application path '{path}'", (int)CommandErrors.FileNotFound);
}
}

string path = Path ?? AppDomain.CurrentDomain.BaseDirectory;
Configuration ??= "Release";

if (!Directory.Exists(path))
var connection = await GetCurrentConnection();

if (connection == null)
{
Logger?.LogError($"Target directory '{path}' not found");
return;
}


var lastFile = string.Empty;

// in order to deploy, the runtime must be disabled
Expand Down
8 changes: 6 additions & 2 deletions Source/v2/Meadow.Package/PackageManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private bool CleanApplication(string projectFilePath, string configuration = "Re
{
var proc = new Process();
proc.StartInfo.FileName = "dotnet";
proc.StartInfo.Arguments = $"clean {projectFilePath} -c {configuration}";
proc.StartInfo.Arguments = $"clean \"{projectFilePath}\" -c {configuration}";

proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.ErrorDialog = false;
Expand Down Expand Up @@ -230,7 +230,11 @@ private void CreateEntry(ZipArchive archive, string fromFile, string entryPath)

public static FileInfo[] GetAvailableBuiltConfigurations(string rootFolder, string appName = "App.dll")
{
rootFolder = Path.GetFullPath(rootFolder);
// check if we were give path to a project file, not the folder of the project file.
if (File.Exists(rootFolder))
{
rootFolder = Path.GetDirectoryName(rootFolder) ?? ""; // extreact the folder name or if invalid, use the current directory.
}
if (!Directory.Exists(rootFolder)) { throw new DirectoryNotFoundException($"Directory not found '{rootFolder}'. Check path to project file."); }

//see if this is a fully qualified path to the app.dll
Expand Down
Loading