summaryrefslogtreecommitdiff
path: root/Program.cs
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2026-05-27 02:06:02 +1000
committerJake Mannens <jake@asger.xyz>2026-05-27 02:06:26 +1000
commit0d4efb175c6538af3f750e3342295a9b0e8b5b43 (patch)
tree44cb047f3ebd3d6a02d75a2540f17aaca0bb4dc1 /Program.cs
Initial commitdev
Diffstat (limited to 'Program.cs')
-rw-r--r--Program.cs71
1 files changed, 71 insertions, 0 deletions
diff --git a/Program.cs b/Program.cs
new file mode 100644
index 0000000..db48b83
--- /dev/null
+++ b/Program.cs
@@ -0,0 +1,71 @@
+using HyperBooru.ApiClient;
+using System.CommandLine;
+
+namespace HyperBooru.CommandLine;
+
+public static class Program {
+ public static readonly Option<string> UrlOption = new("--url") {
+ Description = "API base URL to connect to",
+ Required = true
+ };
+
+ public static readonly Option<string> UsernameOption = new("--username") {
+ Description = "Username to connect with",
+ Required = true
+ };
+
+ public static readonly Option<string> PasswordOption = new("--password") {
+ Description = "Password to connect with",
+ Required = true
+ };
+
+ public static readonly Option<FileInfo> FileOption = new("--file") {
+ Description = "File to upload",
+ Required = true
+ };
+
+ public static readonly Option<bool> SkipCertCheckOption = new("--skip-cert-check") {
+ Description = "Don't validate server CA certificate"
+ };
+
+ public static readonly Option[] Options = [
+ UrlOption,
+ UsernameOption,
+ PasswordOption,
+ FileOption,
+ SkipCertCheckOption
+ ];
+
+ public static void Main(string[] args) {
+ var rootCommand = new RootCommand();
+ foreach(var o in Options)
+ rootCommand.Options.Add(o);
+
+ var parseResult = rootCommand.Parse(args);
+ if(parseResult.Errors.Count != 0) {
+ foreach(var error in parseResult.Errors)
+ Console.Error.WriteLine(error.Message);
+ Environment.Exit(1);
+ }
+
+ var session = new HBSession(
+ new Uri(parseResult.GetValue(UrlOption)!),
+ parseResult.GetValue(SkipCertCheckOption));
+
+ session.LoginAsync(
+ parseResult.GetValue(UsernameOption)!,
+ parseResult.GetValue(PasswordOption)!)
+ .GetAwaiter()
+ .GetResult();
+
+ try {
+ var media = session.Media.UploadAsync(
+ parseResult.GetValue(FileOption)!.FullName, null, false).GetAwaiter().GetResult();
+
+ Console.WriteLine(media.MediaId);
+ } catch(Exception e) {
+ Console.Error.WriteLine($"An error occurred: {e.Message}");
+ Environment.Exit(1);
+ }
+ }
+}