diff --git a/.gitignore b/.gitignore index 244e09a..66c6bf8 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,7 @@ bld/ *.nupkg *.nuget.props *.nuget.targets + # Vim [._]*.s[a-v][a-z] [._]*.sw[a-p] @@ -34,8 +35,7 @@ tags [._]*.un~ # Visual Studio Code -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json +.vscode/ + +# HabitSharp secrets +habitsharp.json diff --git a/HabitSharp.Client/HabitSharp.Client.csproj b/HabitSharp.Client/HabitSharp.Client.csproj new file mode 100644 index 0000000..b9c4c38 --- /dev/null +++ b/HabitSharp.Client/HabitSharp.Client.csproj @@ -0,0 +1,26 @@ + + + + + + + + + + + + + Exe + netcoreapp2.1 + HabitSharp.Client + HabitSharp.Client + 0.1.0 + Lucidiot + Lucidiot + Command-line tool for Habitica. + https://gitlab.com/Lucidiot/HabitSharp/blob/master/LICENSE + git + https://gitlab.com/Lucidiot/HabitSharp + + + diff --git a/HabitSharp.Client/Program.cs b/HabitSharp.Client/Program.cs new file mode 100644 index 0000000..1f56c75 --- /dev/null +++ b/HabitSharp.Client/Program.cs @@ -0,0 +1,73 @@ +using System; +using System.IO; +using HabitSharp; +using McMaster.Extensions.CommandLineUtils; +using Microsoft.Extensions.Configuration; + +namespace HabitClient +{ + class Program + { + private static HabiticaApi GetClient() { + // TODO: Gracefully handle missing config and create a boilerplate + var config = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) // TODO: Use home dir? + .AddJsonFile("habitsharp.json") + .Build(); + // TODO: Bind to config object? + return new HabiticaApi(config["userId"], config["apiKey"]); + } + + static void Main(string[] args) + { + var api = GetClient(); + + var app = new CommandLineApplication { + Name = "habitica", + Description = "An command-line tool for the Habitica API" + }; + app.HelpOption(inherited: true); + + app.Command("tags", tagCmd => { + tagCmd.Description = "Manage tags"; + tagCmd.OnExecute(() => { + Console.WriteLine("Specify a subcommand"); + tagCmd.ShowHelp(); + return 1; + }); + + tagCmd.Command("list", listCmd => { + listCmd.Description = "List all tags"; + listCmd.OnExecute(() => { + var tags = api.Tags.List(); + Console.WriteLine("Habitica version " + tags.AppVersion.ToString()); + foreach (Tag t in tags.Data) { + Console.Write($"{t.Id}: {t.Name}"); + Console.WriteLine(t.Challenge ? " (Challenge Tag)" : ""); + } + }); + }); + + tagCmd.Command("clear", clearCmd => { + clearCmd.Description = "Delete all tags"; + clearCmd.OnExecute(() => { + var tags = api.Tags.List(); + Console.WriteLine("Habitica version " + tags.AppVersion.ToString()); + foreach (Tag t in tags.Data) { + Console.WriteLine($"Deleting tag {t.Name}"); + api.Tags.Delete(t); + } + }); + }); + }); + + app.OnExecute(() => { + Console.WriteLine("Specify a subcommand"); + app.ShowHelp(); + return 1; + }); + + app.Execute(args); + } + } +}