Skip to content

armgit / Filee

Public Imported from GitHub
0

Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.

fix(cli): polish 'engines' after #935

Yavuz Mete Afşar9527030e91dd
diff --git a/src/Filee.Cli/Cli.cs b/src/Filee.Cli/Cli.cs
index b325db35..10ffb4b0 100644
--- a/src/Filee.Cli/Cli.cs
+++ b/src/Filee.Cli/Cli.cs
@@ -1,6 +1,6 @@
// The "filee" commands: convert, watch, formats, presets, engines. Writes results for people (one line per file) or, with
-// --json, one JSON document for other programs. Exit codes: 0 everything converted, 1 some files failed,
-// 2 wrong arguments or a missing input, 3 nothing to convert.
+// --json, one JSON document for other programs. Exit codes: 0 nothing failed (skipped files included), 1 some
+// failed or were cancelled, 2 wrong arguments or a missing input, 3 nothing to convert.
using System.Text.Json;
using Filee.Core.Conversion;
diff --git a/src/Filee.Cli/EnginesCommand.cs b/src/Filee.Cli/EnginesCommand.cs
index 63bae710..02ae7299 100644
--- a/src/Filee.Cli/EnginesCommand.cs
+++ b/src/Filee.Cli/EnginesCommand.cs
@@ -55,9 +55,7 @@ internal static class EnginesCommand
json.WriteEndObject();
});
}
- if (options.Json)
- return;
- if (failed)
+ else if (failed)
errors.WriteLine($"filee: {result.Message}");
else if (!options.Quiet)
output.WriteLine(result.Message);
@@ -83,7 +81,7 @@ internal static class EnginesCommand
return Cli.Success;
}
- output.WriteLine($"{"ID",-12} {"STATUS",-16} {"VERSION",-8} SIZE");
+ var lines = new List<(string Id, string Status, string Version, string Size)> { ("ID", "STATUS", "VERSION", "SIZE") };
foreach (var (package, copy) in rows)
{
var downloadable = CanDownload(engines, package);
@@ -102,14 +100,21 @@ internal static class EnginesCommand
};
// The version Filee downloads; next to a copy Filee didn't download it would read as that copy's version.
var version = downloadable && copy.Status != EngineCopyStatus.OwnCopy ? Version(engines, package) : "";
- output.WriteLine($"{package.Id,-12} {status,-16} {version,-8} {size}");
+ lines.Add((package.Id, status, version, size));
}
+ // Columns as wide as their longest value: a version such as Tesseract's 5.4.0.20240606 on Windows fits.
+ var (idWidth, statusWidth, versionWidth) = (lines.Max(l => l.Id.Length), lines.Max(l => l.Status.Length), lines.Max(l => l.Version.Length));
+ foreach (var line in lines)
+ output.WriteLine($"{line.Id.PadRight(idWidth)} {line.Status.PadRight(statusWidth)} {line.Version.PadRight(versionWidth)} {line.Size}");
output.WriteLine();
output.WriteLine("Install one with: filee engines install <id>");
return Cli.Success;
}
- /// <summary>One package in the JSON of 'engines'; fields that don't apply are left out, as in 'convert --json'.</summary>
+ /// <summary>
+ /// One package in the JSON of 'engines'; fields that don't apply are left out, as in 'convert --json'. "version" is
+ /// the version Filee downloads, also next to "owncopy" (what 'install' would put in place of a copy on the PC).
+ /// </summary>
private static void WriteEngine(Utf8JsonWriter json, EngineInstaller engines, EnginePackage package, EngineCopy copy)
{
var downloadable = CanDownload(engines, package);
diff --git a/src/Filee.Cli/Help.cs b/src/Filee.Cli/Help.cs
index 981bc9b5..3a7069c6 100644
--- a/src/Filee.Cli/Help.cs
+++ b/src/Filee.Cli/Help.cs
@@ -58,6 +58,9 @@ internal static class Help
one with the same download and checks as the app. 'remove' only removes what Filee downloaded; your own copy
and one found on this computer are left alone.
+ In the JSON of the list, "version" is the version Filee downloads, also for an engine whose status is
+ "owncopy" (your own copy or one found on this computer).
+
Options:
--json Print the result as JSON; progress goes to stderr, one JSON object per line
--quiet Print nothing but errors
diff --git a/tests/Filee.Cli.Tests/EnginesCommandTests.cs b/tests/Filee.Cli.Tests/EnginesCommandTests.cs
index 7f25c575..0bdcba3e 100644
--- a/tests/Filee.Cli.Tests/EnginesCommandTests.cs
+++ b/tests/Filee.Cli.Tests/EnginesCommandTests.cs
@@ -112,6 +112,17 @@ public sealed class EnginesCommandTests : IDisposable
Assert.Contains("filee engines install <id>", output);
}
+ [Fact]
+ public async Task The_list_columns_fit_a_long_version()
+ {
+ _components["pandoc"] = _components["pandoc"] with { Version = "5.4.0.20240606" };
+ var lines = (await Run("engines")).Output.Split('\n');
+ var size = lines[0].IndexOf("SIZE", StringComparison.Ordinal);
+ var pandoc = lines.Single(l => l.StartsWith("pandoc ", StringComparison.Ordinal));
+ Assert.Contains("5.4.0.20240606 ", pandoc[..size]);
+ Assert.Matches(@"^\d+ MB download", pandoc[size..]);
+ }
+
[Fact]
public async Task Install_downloads_once_reports_progress_and_skips_what_is_installed()
{
@@ -271,7 +282,7 @@ public sealed class EnginesCommandTests : IDisposable
}
[Fact]
- public async Task Engines_go_to_the_apps_engines_folder_which_follows_FILEE_DATA_DIR()
+ public async Task Engines_go_to_the_apps_engines_folder()
{
await using var host = CliHost.Create(_settings);
Assert.Equal(EngineEnvironment.DownloadRoot, host.Engines.Root);