about summary refs log tree commit diff
path: root/ModerationClient/Services/CommandLineConfiguration.cs
blob: 4debd5c0ff478dc0a2aaa138b5eebd1968f90c9b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using ArcaneLibs;
using Microsoft.Extensions.Logging;

namespace ModerationClient.Services;

public class CommandLineConfiguration {
    public CommandLineConfiguration(ILogger<CommandLineConfiguration> logger) {
        var args = Environment.GetCommandLineArgs();
        logger.LogInformation("Command line arguments: " + string.Join(", ", args));
        for (var i = 0; i < args.Length; i++) {
            logger.LogInformation("Processing argument: " + args[i]);
            switch (args[i]) {
                case "--profile":
                case "-p":
                    if (args.Length <= i + 1 || args[i + 1].StartsWith("-")) {
                        throw new ArgumentException("No profile specified");
                    }

                    Profile = args[++i];
                    logger.LogInformation("Set profile to: " + Profile);
                    break;
                case "--temporary":
                    IsTemporary = true;
                    logger.LogInformation("Using temporary profile");
                    break;
                case "--profile-dir":
                    ProfileDirectory = args[++i];
                    break;
                case "--scale":
                    Scale = float.Parse(args[++i]);
                    break;
            }
        }

        if (string.IsNullOrWhiteSpace(ProfileDirectory))
            ProfileDirectory = IsTemporary
                ? Directory.CreateTempSubdirectory("ModerationClient-tmp").FullName
                : Util.ExpandPath($"$HOME/.local/share/ModerationClient/{Profile}");

        logger.LogInformation("Profile directory: " + ProfileDirectory);
        Directory.CreateDirectory(ProfileDirectory);
    }

    public string Profile { get; private set; } = "default";
    public bool IsTemporary { get; private set; }

    public string ProfileDirectory { get; private set; }
    public float Scale { get; private set; } = 1f;
}