-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathProgram.cs
More file actions
111 lines (102 loc) · 4.43 KB
/
Program.cs
File metadata and controls
111 lines (102 loc) · 4.43 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
104
105
106
107
108
109
110
111
using Terminal.Gui;
using Opcilloscope.App;
namespace Opcilloscope;
class Program
{
static int Main(string[] args)
{
try
{
#pragma warning disable IL2026 // Terminal.Gui Application.Init uses reflection and is not AOT-compatible
Application.Init();
#pragma warning restore IL2026
// Parse command-line arguments
// Note: If multiple arguments of the same type are provided (e.g., two config files),
// the last one specified will be used.
string? autoConnectUrl = null;
string? configPath = null;
for (int i = 0; i < args.Length; i++)
{
// Config file options: --config <path> or direct path ending with .cfg/.opcilloscope/.json
if ((args[i] == "--config" || args[i] == "-f") && i + 1 < args.Length)
{
configPath = args[i + 1];
i++; // Skip the next argument
}
else if (args[i].EndsWith(".cfg", StringComparison.OrdinalIgnoreCase) ||
args[i].EndsWith(".opcilloscope", StringComparison.OrdinalIgnoreCase) ||
(args[i].EndsWith(".json", StringComparison.OrdinalIgnoreCase) && File.Exists(args[i])))
{
configPath = args[i];
}
// Connection URL options: --connect <url> or direct opc.tcp:// URL
// Note: Direct URL connection is not currently implemented; use config files instead.
else if ((args[i] == "--connect" || args[i] == "-c") && i + 1 < args.Length)
{
autoConnectUrl = args[i + 1];
i++; // Skip the next argument
}
else if (args[i].StartsWith("opc.tcp://"))
{
autoConnectUrl = args[i];
}
else if (args[i] == "--help" || args[i] == "-h")
{
PrintUsage();
return 0;
}
}
var mainWindow = new MainWindow();
// Load config file if specified (takes precedence over URL)
if (!string.IsNullOrEmpty(configPath))
{
if (!File.Exists(configPath))
{
Console.Error.WriteLine($"Error: Configuration file not found: {configPath}");
Application.Shutdown();
return 1;
}
mainWindow.LoadConfigFromCommandLine(configPath);
}
// Otherwise, if auto-connect URL provided, show warning (not yet implemented)
else if (!string.IsNullOrEmpty(autoConnectUrl))
{
Console.Error.WriteLine(
$"Warning: Auto-connect via command-line URL ('{autoConnectUrl}') is not currently implemented. " +
"Please use a configuration file with an endpoint URL instead.");
}
Application.Run(mainWindow);
mainWindow.Dispose();
}
catch (Exception ex)
{
Console.Error.WriteLine($"Fatal error: {ex.Message}");
Console.Error.WriteLine(ex.StackTrace);
return 1;
}
finally
{
Application.Shutdown();
}
return 0;
}
private static void PrintUsage()
{
Console.WriteLine("opcilloscope - Terminal-based OPC UA Client");
Console.WriteLine();
Console.WriteLine("Usage: opcilloscope [options] [file]");
Console.WriteLine();
Console.WriteLine("Options:");
Console.WriteLine(" -f, --config <file> Load configuration file (.cfg, .opcilloscope, or .json)");
Console.WriteLine(" -h, --help Show this help message");
Console.WriteLine();
Console.WriteLine("Note: Direct server connection via --connect or opc.tcp:// URLs is not yet");
Console.WriteLine(" implemented. Please create a configuration file with the server URL.");
Console.WriteLine();
Console.WriteLine("Examples:");
Console.WriteLine(" opcilloscope Start with empty configuration");
Console.WriteLine(" opcilloscope production.cfg Load configuration file");
Console.WriteLine(" opcilloscope --config config.json Load configuration file");
Console.WriteLine();
}
}