This repository has been archived by the owner on Feb 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from TheBerkin/dev
Rant 2.0
- Loading branch information
Showing
262 changed files
with
15,979 additions
and
6,582 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Rant.Common | ||
{ | ||
internal static class CmdLine | ||
{ | ||
private static readonly Dictionary<string, string> Arguments = new Dictionary<string, string>(); | ||
private static readonly HashSet<string> Flags = new HashSet<string>(); | ||
private static readonly List<string> Paths = new List<String>(); | ||
|
||
/// <summary> | ||
/// Determines whether the user specified a question mark as the argument. | ||
/// </summary> | ||
public static readonly bool Help; | ||
|
||
static CmdLine() | ||
{ | ||
var args = Environment.GetCommandLineArgs().Skip(1).ToArray(); | ||
int argc = args.Length; | ||
if (argc == 0) return; | ||
|
||
if (argc == 1 && args[0] == "?") | ||
{ | ||
Help = true; | ||
return; | ||
} | ||
|
||
bool isProperty = false; | ||
|
||
for (int i = 0; i < args.Length; i++) | ||
{ | ||
if (isProperty) | ||
{ | ||
Arguments[args[i - 1].TrimStart('-')] = args[i]; | ||
isProperty = false; | ||
} | ||
else if (args[i].StartsWith("--")) | ||
{ | ||
Flags.Add(args[i].TrimStart('-')); | ||
} | ||
else if (args[i].StartsWith("-")) | ||
{ | ||
isProperty = true; | ||
} | ||
else | ||
{ | ||
Paths.Add(args[i]); | ||
} | ||
} | ||
} | ||
|
||
public static string[] GetPaths() => Paths.ToArray(); | ||
|
||
public static string Property(string name) | ||
{ | ||
string arg; | ||
if (!Arguments.TryGetValue(name.ToLower(), out arg)) | ||
{ | ||
arg = ""; | ||
} | ||
return arg; | ||
} | ||
|
||
public static string Property(string name, string defaultValue) | ||
{ | ||
string arg; | ||
return !Arguments.TryGetValue(name.ToLower(), out arg) ? defaultValue : arg; | ||
} | ||
|
||
public static bool Flag(string name) => Flags.Contains(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.