-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
103 lines (89 loc) · 3.52 KB
/
Copy pathProgram.cs
File metadata and controls
103 lines (89 loc) · 3.52 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using DotNetEnv;
using System.CommandLine;
namespace IndxCloudLoader
{
internal partial class Program
{
#region Private Fields
private static readonly string uri;
private static readonly string bearerToken;
private static readonly string userEmail;
private static readonly string userPassword;
#endregion Private Fields
#region Private Methods
static Program()
{
// Load environment variables from .env.local file
Env.Load(".env.local");
uri = Environment.GetEnvironmentVariable("API_URI") ?? "https://localhost:5001/";
bearerToken = Environment.GetEnvironmentVariable("BEARER_TOKEN") ?? "";
userEmail = Environment.GetEnvironmentVariable("USER_EMAIL") ?? "";
userPassword = Environment.GetEnvironmentVariable("USER_PASSWORD") ?? "";
}
private static async Task<int> Main(string[] args)
{
// Create root command
var rootCommand = new RootCommand("IndxCloudLoader - Load and configure datasets for IndxCloudApi");
// Add dataset option
var datasetOption = new Option<string>(
aliases: new[] { "--dataset", "-d" },
description: "Dataset to load (tmdb or pokedex). If not provided, interactive mode will prompt for selection."
);
rootCommand.AddOption(datasetOption);
// Add handler
rootCommand.SetHandler(async (string dataset) =>
{
try
{
// If no dataset provided, show interactive menu
if (string.IsNullOrEmpty(dataset))
{
dataset = ShowInteractiveMenu();
if (dataset == null)
{
ConsoleHelper.WriteWarning("No dataset selected. Exiting.");
return;
}
}
await LoadDataset(dataset);
}
catch (Exception ex)
{
ConsoleHelper.WriteError($"Fatal error: {ex.Message}");
if (ex.InnerException != null)
{
ConsoleHelper.WriteError($" Inner exception: {ex.InnerException.Message}");
}
Environment.Exit(-1);
}
}, datasetOption);
return await rootCommand.InvokeAsync(args);
}
private static string ShowInteractiveMenu()
{
ConsoleHelper.WriteHeader("Dataset Selection");
Console.WriteLine();
var datasets = DatasetConfig.GetAvailableDatasets();
Console.WriteLine("Available datasets:");
for (int i = 0; i < datasets.Length; i++)
{
Console.WriteLine($" {i + 1}. {datasets[i]}");
}
Console.WriteLine($" 0. Exit");
Console.WriteLine();
Console.Write("Select dataset (enter number): ");
if (int.TryParse(Console.ReadLine(), out int choice))
{
if (choice == 0)
return null;
if (choice > 0 && choice <= datasets.Length)
{
return datasets[choice - 1];
}
}
ConsoleHelper.WriteWarning("Invalid selection.");
return null;
}
#endregion Private Methods
}
}