command line parsing

This commit is contained in:
Lynne Megido 2020-09-26 21:59:06 +10:00
parent 8e78069fca
commit 8b60f2b602
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
3 changed files with 28 additions and 6 deletions

View File

@ -2,17 +2,23 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.CommandLine.DragonFruit;
using CsvHelper;
using BunyMuny;
using CsvHelper.Configuration.Attributes;
namespace BunyMuny {
class Program {
static int Main(string[] args) {
/// <summary>
/// BunyMuny parses the CSV output of various bank statement listings and converts it to something more human readable with nice visualisations.
/// </summary>
/// <param name="file">The CSV file to read</param>
/// <param name="rules">The JSON file to use for rules when parsing statement descriptions</param>
/// <returns></returns>
static int Main(string file = "test.csv", string rules = "rules.json") {
Bank bank = Bank.ME;
var statements = new List<Statement>();
using (var sr = new StreamReader("/mnt/code/cs/bunymuny/test.csv")) {
using (var sr = new StreamReader(file)) {
using (var csv = new CsvReader(sr, CultureInfo.InvariantCulture)) {
csv.Read();
csv.ReadHeader();
@ -40,6 +46,10 @@ namespace BunyMuny {
Value = value
});
break;
default:
Console.WriteLine(":(");
return 1;
}
}

View File

@ -3,12 +3,18 @@ using System;
namespace BunyMuny {
public class Statement {
public DateTime Date;
public string Description;
private string _description;
public string Description {
get => string.IsNullOrWhiteSpace(_description) ? OriginalDescription : _description;
set { _description = value; }
}
public string OriginalDescription;
public double Value;
public string Category;
public override string ToString() {
return $"${Math.Abs(Value)} {(Value < 0 ? "to" : "from")} {Description} on {Date.ToString("MMM d yyyy")}";
return $"${Math.Abs(Value)} {(Value < 0 ? "to" : "from")} {(Description)} on {Date.ToString("MMM d yyyy")}";
}
}
}

View File

@ -7,6 +7,12 @@
<ItemGroup>
<PackageReference Include="CsvHelper" Version="15.0.6" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20371.2" />
<PackageReference Include="System.CommandLine.DragonFruit" Version="0.3.0-alpha.20371.2" />
</ItemGroup>
<PropertyGroup>
<RunWorkingDirectory>$(MSBuildProjectDirectory)</RunWorkingDirectory>
</PropertyGroup>
</Project>