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:
parent
328d0e1aa4
commit
d0ba1f7087
BackupEssentials
@ -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">
|
||||
|
36
BackupEssentials/Utils/ProgramArgsParser.cs
Normal file
36
BackupEssentials/Utils/ProgramArgsParser.cs
Normal 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 (-<flag>). 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 (-<flag>), 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;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user