From b497ffb0d731fc1c349dd3ce1e5dc76c4cbae619 Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Sun, 28 Jul 2019 18:15:00 +0100 Subject: [PATCH] Start creating CLI --- PolyFeed/FeedBuilder.cs | 2 +- PolyFeed/PolyFeed.csproj | 6 +++++- PolyFeed/Program.cs | 42 ++++++++++++++++++++++++++++++++++------ PolyFeed/packages.config | 1 + 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/PolyFeed/FeedBuilder.cs b/PolyFeed/FeedBuilder.cs index b783e69..65c9bd1 100644 --- a/PolyFeed/FeedBuilder.cs +++ b/PolyFeed/FeedBuilder.cs @@ -29,7 +29,7 @@ namespace PolyFeed // Write the header - await feed.WriteGenerator("Polyfeed", "https://gitlab.com/sbrl/PolyFeed.git", Program.getProgramVersion()); + await feed.WriteGenerator("Polyfeed", "https://gitlab.com/sbrl/PolyFeed.git", Program.GetProgramVersion()); await feed.WriteId(source.Url); string lastModified = response.Headers.Get("last-modified"); if (string.IsNullOrWhiteSpace(lastModified)) diff --git a/PolyFeed/PolyFeed.csproj b/PolyFeed/PolyFeed.csproj index 87cbe20..3fdd947 100644 --- a/PolyFeed/PolyFeed.csproj +++ b/PolyFeed/PolyFeed.csproj @@ -8,6 +8,7 @@ PolyFeed PolyFeed v4.7 + true true @@ -130,6 +131,9 @@ ..\packages\Microsoft.SyndicationFeed.ReaderWriter.1.0.2\lib\netstandard1.3\Microsoft.SyndicationFeed.ReaderWriter.dll + + ..\packages\Nett.0.13.0\lib\net40\Nett.dll + @@ -152,4 +156,4 @@ - \ No newline at end of file + diff --git a/PolyFeed/Program.cs b/PolyFeed/Program.cs index ddda4bc..e45effd 100644 --- a/PolyFeed/Program.cs +++ b/PolyFeed/Program.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Reflection; +using Nett; namespace PolyFeed { @@ -9,7 +10,9 @@ namespace PolyFeed { public readonly string ProgramName = "PolyFeed"; public readonly string Description = "creates Atom feeds from websites that don't support it"; - // Settings here + + public string ConfigFilepath = "feed.toml"; + public string OutputFilepath = "feed.atom"; } class Program @@ -33,7 +36,7 @@ namespace PolyFeed { case "-h": case "--help": - Console.WriteLine($"{settings.ProgramName}, {getProgramVersion()}"); + Console.WriteLine($"{settings.ProgramName}, {GetProgramVersion()}"); Console.WriteLine(" By Starbeamrainbowlabs"); Console.WriteLine(); @@ -43,14 +46,26 @@ namespace PolyFeed Console.WriteLine($" ./{Path.GetFileName(Assembly.GetExecutingAssembly().Location)} [arguments]"); Console.WriteLine(); Console.WriteLine("Options:"); - Console.WriteLine(" -h --help Displays this message"); - Console.WriteLine(" -v --version Outputs the version number of this program"); + Console.WriteLine(" -h --help Displays this message"); + Console.WriteLine(" -v --version Outputs the version number of this program"); + Console.WriteLine(" -c --config Specifies the location of the feed configuration file to use to generate a feed (default: feed.toml)"); + Console.WriteLine(" -o --output Specifies the location to write the output feed to (default: feed.atom)"); return 0; case "-v": case "--version": - Console.WriteLine($"{settings.ProgramName}\t{getProgramVersion()}"); + Console.WriteLine($"{settings.ProgramName}\t{GetProgramVersion()}"); return 0; + + case "-c": + case "--config": + settings.ConfigFilepath = args[++i]; + break; + + case "-o": + case "--output": + settings.OutputFilepath = args[++i]; + break; } } @@ -64,10 +79,25 @@ namespace PolyFeed return 0; } + private static void run() + { + FeedSource feedSource = new FeedSource(); + TomlTable config = Toml.ReadFile(settings.ConfigFilepath, TomlSettings.Create()); + + foreach (KeyValuePair item in config) { + string key = item.Key; + string value = item.Value.Get().Value; + feedSource.GetType().GetProperty(value).SetValue( + feedSource, + value + ); + } + } + #region Helper Methods - public static string getProgramVersion() + public static string GetProgramVersion() { Version version = Assembly.GetExecutingAssembly().GetName().Version; return $"{version.Major}.{version.Minor}"; diff --git a/PolyFeed/packages.config b/PolyFeed/packages.config index 0756eba..e8f658c 100644 --- a/PolyFeed/packages.config +++ b/PolyFeed/packages.config @@ -7,6 +7,7 @@ +