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

Change current directory. Improve a couple error returns #463

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Source/v2/Meadow.CLI/CommandErrors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ public enum CommandErrors
Success = 0,
GeneralError = 1,
UserCancelled = 2,
FileNotFound = 3,
DirectoryNotFound = 4,
}
}
8 changes: 4 additions & 4 deletions Source/v2/Meadow.Cli/Commands/Current/App/AppBuildCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CliFx.Attributes;
using CliFx.Exceptions;
using Meadow.Package;
using Microsoft.Extensions.Logging;

Expand All @@ -23,16 +24,15 @@ public AppBuildCommand(IPackageManager packageManager, ILoggerFactory loggerFact

protected override ValueTask ExecuteCommand()
{
string path = Path ?? AppDomain.CurrentDomain.BaseDirectory;
string path = Path ?? Directory.GetCurrentDirectory();

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

Expand All @@ -45,7 +45,7 @@ protected override ValueTask ExecuteCommand()

if (!success)
{
Logger?.LogError($"Build failed!");
throw new CommandException($"Build failed.", (int)CommandErrors.GeneralError);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CliFx.Attributes;
using CliFx.Exceptions;
using Meadow.Cloud.Client;
using Meadow.Cloud.Client.Identity;
using Meadow.Package;
Expand Down Expand Up @@ -42,26 +43,25 @@ public CloudPackageCreateCommand(

protected override async ValueTask ExecuteCommand()
{
ProjectPath ??= AppDomain.CurrentDomain.BaseDirectory;
ProjectPath ??= Directory.GetCurrentDirectory();
ProjectPath = Path.GetFullPath(ProjectPath);
if (!Directory.Exists(ProjectPath))
{
throw new DirectoryNotFoundException($"Directory not found '{ProjectPath}'. Check path to project file.");
throw new CommandException($"Directory not found '{ProjectPath}'. Check path to project file.", (int)CommandErrors.DirectoryNotFound);
}

// build
Logger?.LogInformation($"Building {Configuration} version of application...");
if (!_packageManager.BuildApplication(ProjectPath, Configuration, true, CancellationToken))
{
return;
throw new CommandException($"Build failed.", (int)CommandErrors.GeneralError);
}

var candidates = PackageManager.GetAvailableBuiltConfigurations(ProjectPath, "App.dll");

if (candidates.Length == 0)
{
Logger?.LogError($"Cannot find a compiled application at '{ProjectPath}'");
return;
throw new CommandException($"Cannot find a compiled application at '{ProjectPath}'", (int)CommandErrors.FileNotFound);
}

var store = _fileManager.Firmware["Meadow F7"];
Expand All @@ -86,7 +86,7 @@ protected override async ValueTask ExecuteCommand()
}
else
{
Logger?.LogError($"Package assembly failed.");
throw new CommandException($"Package assembly failed.", (int)CommandErrors.GeneralError);
}
}
}
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static async Task<int> Main(string[] args)
if (File.Exists("appsettings.json"))
{
var config = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();

Expand Down
Loading