1
0
mirror of https://github.com/chylex/Backup-Essentials.git synced 2025-05-31 18:34:08 +02:00

Added passed argument parser

This commit is contained in:
chylex 2015-04-05 15:56:48 +02:00
parent 328d0e1aa4
commit d0ba1f7087
2 changed files with 37 additions and 0 deletions

View File

@ -96,6 +96,7 @@
<Compile Include="TestingWindow.xaml.cs">
<DependentUpon>TestingWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Utils\ProgramArgsParser.cs" />
<Compile Include="Utils\ScheduledUpdate.cs" />
<Compile Include="Utils\WindowsVersion.cs" />
<Page Include="Pages\About.xaml">

View File

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace BackupEssentials.Utils{
class ProgramArgsParser{
private string[] Args;
public ProgramArgsParser(string[] args){
this.Args = args;
}
/// <summary>
/// Returns true if the arguments contain a flag (-&lt;flag&gt;). The dash in front is handled automatically.
/// </summary>
public bool HasFlag(string flag){
return Args.Contains("-"+flag);
}
/// <summary>
/// Returns the next argument after a flag (-&lt;flag&gt;), as long as it is not another flag. The dash in front is handled automatically.
/// </summary>
public string GetValue(string flag, string defaultValue){
flag = "-"+flag;
for(int a = 0; a < Args.Length-1; a++){
if (Args[a].Equals(flag)){
return Args[a+1].StartsWith("-") ? defaultValue : Args[a+1];
}
}
return defaultValue;
}
}
}