fix missing default values

This commit is contained in:
Marcello 2024-10-25 11:04:07 +02:00
parent a7166a5422
commit e09cfbffdd
Signed by: m-lamonaca
SSH key fingerprint: SHA256:8db8uii6Gweq7TbKixFBioW2T8CbgtyFETyYL3cr3zk
5 changed files with 33 additions and 33 deletions

View file

@ -33,15 +33,16 @@ _**NOTE**_: The option `-p:PublishTrimmed=true` may produce some *warnings*. If
```sh
USAGE:
scrl <path> [OPTIONS]
scrl [path] [OPTIONS]
ARGUMENTS:
<path> Starting directory (Default: .)
[path] Starting directory (Default: .)
OPTIONS:
DEFAULT
-h, --help Prints help information
-x, --extensions Comma separated list of script extensions
-d, --depth Search depth
-x, --extensions <EXTENSIONS> List of script extensions to search for
-d, --depth 3 Search depth
-e, --elevated Run with elevated privileges
-g, --group Group scripts by folder
-b, --brief Show brief information

View file

@ -1,5 +1,5 @@
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using Spectre.Console;
using Spectre.Console.Cli;
@ -76,27 +76,30 @@ public sealed class RootCommand : AsyncCommand<RootCommandSettings>
public sealed class RootCommandSettings : CommandSettings
{
[Description("Comma separated list of script extensions")]
[CommandOption("-x|--extensions")]
public string? Extensions { get; init; }
[Description("List of script extensions to search for")]
[CommandOption("-x|--extensions <EXTENSIONS>")]
[SuppressMessage("Performance", "CA1819:Properties should not return arrays")]
public string[] Extensions { get; init; } = [".ps1", ".*sh", ".bat", ".cmd", ".nu"];
[Description("Search depth")]
[CommandOption("-d|--depth")]
public int Depth { get; init; } = 1;
[DefaultValue(3)]
public int Depth { get; init; }
[Description("Run with elevated privileges")]
[CommandOption("-e|--elevated")]
public bool Elevated { get; init; } = false;
public bool Elevated { get; init; }
[Description("Group scripts by folder")]
[CommandOption("-g|--group")]
public bool Group { get; init; } = false;
public bool Group { get; init; }
[Description("Show brief information")]
[CommandOption("-b|--brief")]
public bool Brief { get; init; } = false;
public bool Brief { get; init; }
[Description("Starting directory (Default: .)")]
[CommandArgument(0, "<path>")]
public string Directory { get; init; } = ".";
[CommandArgument(0, "[path]")]
[DefaultValue(".")]
public string Directory { get; init; } = string.Empty;
}

View file

@ -2,5 +2,9 @@ using ScriptLauncher;
using Spectre.Console.Cli;
var app = new CommandApp<RootCommand>();
app.Configure(x => x.SetApplicationName("scrl"));
app.Configure(x =>
{
x.SetApplicationName("scrl");
});
return app.Run(args);

View file

@ -2,23 +2,15 @@ namespace ScriptLauncher;
internal readonly struct ScriptFinder
{
private static readonly string[] DefaultExtensions = new[] { ".ps1", ".*sh", ".bat", ".cmd", ".nu" };
private static readonly char[] DefaultSeparators = new[] { ',', ' ' };
public string[] Extensions { get; }
public IEnumerable<string> Extensions { get; }
public string RootDirectory { get; }
public int Depth { get; }
private int Depth { get; }
private readonly EnumerationOptions _options;
public ScriptFinder(string? extensions, string directory, int depth)
public ScriptFinder(IEnumerable<string> extensions, string directory, int depth)
{
Extensions =
extensions
?.Split(DefaultSeparators, StringSplitOptions.RemoveEmptyEntries)
.ToHashSet()
.Select(x => $".{x.TrimStart('.')}")
.ToArray() ?? DefaultExtensions;
Extensions = extensions.ToHashSet().Select(x => $".{x.TrimStart('.')}");
Depth = depth;
RootDirectory = directory;

View file

@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AnalysisMode>All</AnalysisMode>
<Version>0.1.6</Version>
<Version>0.1.7</Version>
<PackAsTool>true</PackAsTool>
<Description>Tool to find and exec shell scripts</Description>
<PackageReadmeFile>README.md</PackageReadmeFile>