mirror of
https://github.com/m-lamonaca/script-launcher.git
synced 2025-04-08 11:06:26 +00:00
Compare commits
No commits in common. "main" and "v0.1.6" have entirely different histories.
5 changed files with 39 additions and 36 deletions
17
README.md
17
README.md
|
@ -33,19 +33,18 @@ _**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 <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
|
||||
-h, --help Prints help information
|
||||
-x, --extensions Comma separated list of script extensions
|
||||
-d, --depth Search depth
|
||||
-e, --elevated Run with elevated privileges
|
||||
-g, --group Group scripts by folder
|
||||
-b, --brief Show brief information
|
||||
```
|
||||
|
||||
[CLI]: https://docs.microsoft.com/en-us/dotnet/core/tools/ ".NET CLI Docs"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
using Spectre.Console;
|
||||
using Spectre.Console.Cli;
|
||||
|
||||
|
@ -76,30 +76,27 @@ public sealed class RootCommand : AsyncCommand<RootCommandSettings>
|
|||
|
||||
public sealed class RootCommandSettings : CommandSettings
|
||||
{
|
||||
[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("Comma separated list of script extensions")]
|
||||
[CommandOption("-x|--extensions")]
|
||||
public string? Extensions { get; init; }
|
||||
|
||||
[Description("Search depth")]
|
||||
[CommandOption("-d|--depth")]
|
||||
[DefaultValue(3)]
|
||||
public int Depth { get; init; }
|
||||
public int Depth { get; init; } = 1;
|
||||
|
||||
[Description("Run with elevated privileges")]
|
||||
[CommandOption("-e|--elevated")]
|
||||
public bool Elevated { get; init; }
|
||||
public bool Elevated { get; init; } = false;
|
||||
|
||||
[Description("Group scripts by folder")]
|
||||
[CommandOption("-g|--group")]
|
||||
public bool Group { get; init; }
|
||||
public bool Group { get; init; } = false;
|
||||
|
||||
[Description("Show brief information")]
|
||||
[CommandOption("-b|--brief")]
|
||||
public bool Brief { get; init; }
|
||||
public bool Brief { get; init; } = false;
|
||||
|
||||
[Description("Starting directory (Default: .)")]
|
||||
[CommandArgument(0, "[path]")]
|
||||
[DefaultValue(".")]
|
||||
public string Directory { get; init; } = string.Empty;
|
||||
}
|
||||
[CommandArgument(0, "<path>")]
|
||||
public string Directory { get; init; } = ".";
|
||||
}
|
|
@ -2,6 +2,5 @@ using ScriptLauncher;
|
|||
using Spectre.Console.Cli;
|
||||
|
||||
var app = new CommandApp<RootCommand>();
|
||||
app.Configure(static x => x.SetApplicationName("scrl"));
|
||||
|
||||
app.Configure(x => x.SetApplicationName("scrl"));
|
||||
return app.Run(args);
|
||||
|
|
|
@ -2,15 +2,23 @@ namespace ScriptLauncher;
|
|||
|
||||
internal readonly struct ScriptFinder
|
||||
{
|
||||
public IEnumerable<string> Extensions { get; }
|
||||
private static readonly string[] DefaultExtensions = new[] { ".ps1", ".*sh", ".bat", ".cmd", ".nu" };
|
||||
private static readonly char[] DefaultSeparators = new[] { ',', ' ' };
|
||||
|
||||
public string[] Extensions { get; }
|
||||
public string RootDirectory { get; }
|
||||
private int Depth { get; }
|
||||
public int Depth { get; }
|
||||
|
||||
private readonly EnumerationOptions _options;
|
||||
|
||||
public ScriptFinder(IEnumerable<string> extensions, string directory, int depth)
|
||||
public ScriptFinder(string? extensions, string directory, int depth)
|
||||
{
|
||||
Extensions = extensions.ToHashSet().Select(static x => $".{x.TrimStart('.')}");
|
||||
Extensions =
|
||||
extensions
|
||||
?.Split(DefaultSeparators, StringSplitOptions.RemoveEmptyEntries)
|
||||
.ToHashSet()
|
||||
.Select(x => $".{x.TrimStart('.')}")
|
||||
.ToArray() ?? DefaultExtensions;
|
||||
|
||||
Depth = depth;
|
||||
RootDirectory = directory;
|
||||
|
@ -28,7 +36,7 @@ internal readonly struct ScriptFinder
|
|||
try
|
||||
{
|
||||
var filenames = Directory.GetFiles(RootDirectory, $"*{extension}", _options);
|
||||
return filenames.Select(static x => new FileInfo(x));
|
||||
return filenames.Select(x => new FileInfo(x));
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
|
@ -37,13 +45,13 @@ internal readonly struct ScriptFinder
|
|||
}
|
||||
|
||||
public FileInfo[] GetScripts() =>
|
||||
Extensions.Select(GetScriptFilesWithExtension).SelectMany(static x => x).ToArray();
|
||||
Extensions.Select(GetScriptFilesWithExtension).SelectMany(x => x).ToArray();
|
||||
|
||||
public IDictionary<DirectoryInfo, FileInfo[]> GetScriptsByDirectory() =>
|
||||
Extensions
|
||||
.Select(GetScriptFilesWithExtension)
|
||||
.SelectMany(static x => x)
|
||||
.GroupBy(static x => x.DirectoryName!)
|
||||
.OrderBy(static x => x.Key)
|
||||
.ToDictionary(static x => new DirectoryInfo(x.Key), static x => x.ToArray());
|
||||
.SelectMany(x => x)
|
||||
.GroupBy(x => x.DirectoryName!)
|
||||
.OrderBy(x => x.Key)
|
||||
.ToDictionary(x => new DirectoryInfo(x.Key), x => x.ToArray());
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AnalysisMode>All</AnalysisMode>
|
||||
<Version>0.1.7</Version>
|
||||
<Version>0.1.6</Version>
|
||||
<PackAsTool>true</PackAsTool>
|
||||
<Description>Tool to find and exec shell scripts</Description>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
|
|
Loading…
Add table
Reference in a new issue