mirror of
https://github.com/sbrl/PolyFeed.git
synced 2024-11-22 06:23:02 +00:00
Start creating CLI
This commit is contained in:
parent
14fca32a5e
commit
b497ffb0d7
4 changed files with 43 additions and 8 deletions
|
@ -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))
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
<RootNamespace>PolyFeed</RootNamespace>
|
||||
<AssemblyName>PolyFeed</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
|
@ -130,6 +131,9 @@
|
|||
<Reference Include="Microsoft.SyndicationFeed.ReaderWriter">
|
||||
<HintPath>..\packages\Microsoft.SyndicationFeed.ReaderWriter.1.0.2\lib\netstandard1.3\Microsoft.SyndicationFeed.ReaderWriter.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Nett">
|
||||
<HintPath>..\packages\Nett.0.13.0\lib\net40\Nett.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="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();
|
||||
|
@ -45,12 +48,24 @@ namespace PolyFeed
|
|||
Console.WriteLine("Options:");
|
||||
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<string, TomlObject> item in config) {
|
||||
string key = item.Key;
|
||||
string value = item.Value.Get<TomlString>().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}";
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<package id="Microsoft.SyndicationFeed.ReaderWriter" version="1.0.2" targetFramework="net47" />
|
||||
<package id="Microsoft.Win32.Primitives" version="4.3.0" targetFramework="net47" />
|
||||
<package id="NETStandard.Library" version="2.0.3" targetFramework="net47" />
|
||||
<package id="Nett" version="0.13.0" targetFramework="net47" />
|
||||
<package id="Newtonsoft.Json" version="12.0.2" targetFramework="net47" />
|
||||
<package id="System.AppContext" version="4.3.0" targetFramework="net47" />
|
||||
<package id="System.Collections" version="4.3.0" targetFramework="net47" />
|
||||
|
|
Loading…
Reference in a new issue