Skip to content

Commit

Permalink
MergeStartupArgs(args)
Browse files Browse the repository at this point in the history
This commit contains some new changes and additions.

## Additions
- LocalAdmin now starts by merging command-line args and args contained in `laargs.txt`. This can help with providing a quick & easy way to launch LocalAdmin without having to type arguments each time.

## Changes
- `LocalAdmin V2.csproj` now includes `laargs.txt`.

That's all.
---
ALEXWARELLC
  • Loading branch information
iamalexrouse committed Sep 26, 2023
1 parent 26b22b7 commit 9dc59c8
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private static async Task Main(string[] args)
while (true)
{
using var la = new LocalAdmin();
await la.Start(args);
await la.Start(StartupArgManager.MergeStartupArgs(args));
}
// ReSharper disable once FunctionNeverReturns
}
Expand Down
40 changes: 40 additions & 0 deletions Core/StartupArgManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.IO;

namespace LocalAdmin.V2.Core
{
public sealed class StartupArgManager
{
/// <summary>
/// Path to startup arguments file.
/// </summary>
private const string StartupArgsPath = "laargs.txt";

/// <summary>
/// Merges Command-line arguments and arguments in <paramref name="StartupArgsPath"/>
/// </summary>
/// <param name="CMDArgs">Runtime Command-Line Arguments</param>
/// <returns>Merged Arguments</returns>
public static string[] MergeStartupArgs(string[] CMDArgs)
{
List<string> StartupArgs = new List<string>();
foreach (string arg in CMDArgs)
{
if (!StartupArgs.Contains(arg))
StartupArgs.Add(arg);
}

foreach (string farg in File.ReadAllLines(Path.GetFullPath(StartupArgsPath)))
{
if (!farg.StartsWith("#") && !farg.StartsWith(" "))
{
if (!StartupArgs.Contains(farg))
StartupArgs.Add(farg);
}
}

return StartupArgs.ToArray();
}
}
}
4 changes: 4 additions & 0 deletions LocalAdmin V2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
</PropertyGroup>

<ItemGroup>
<Content Include="laargs.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="LICENSE">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand All @@ -64,6 +67,7 @@

<None Remove=".editorconfig" />
<None Remove=".gitignore" />
<None Remove="laargs.txt" />
<None Remove="LocalAdmin V2.sln.DotSettings" />
<None Remove="nuget.config" />
<None Remove="Properties\launchSettings.json" />
Expand Down
2 changes: 2 additions & 0 deletions laargs.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Place any arguments you want to use automatically here.
# Any line that starts with '#' or ' ' will be avoided.

0 comments on commit 9dc59c8

Please sign in to comment.