Skip to content

Commit e12f849

Browse files
committed
feat: Support for running as a 'dotnet tool'
1 parent 2cb260b commit e12f849

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

.release-please-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
".": "4.1.0"
2+
".": "4.1.2"
33
}

src/AzureEventGridSimulator/Program.cs

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,9 @@ IHostApplicationLifetime lifetime
8989

9090
var simulatorSettings = app.ApplicationServices.GetService<SimulatorSettings>();
9191

92-
if (simulatorSettings is null)
92+
if (simulatorSettings is null || !simulatorSettings.Topics.Any())
9393
{
94-
Log.Fatal("Settings are not found. The application will now exit");
95-
lifetime.StopApplication();
96-
return;
97-
}
98-
99-
if (!simulatorSettings.Topics.Any())
100-
{
101-
Log.Fatal("There are no configured topics. The application will now exit");
94+
DisplayConfigurationHelp();
10295
lifetime.StopApplication();
10396
return;
10497
}
@@ -132,6 +125,53 @@ IHostApplicationLifetime lifetime
132125
}
133126
}
134127

128+
private static void DisplayConfigurationHelp()
129+
{
130+
var version = Assembly.GetExecutingAssembly().GetName().Version?.ToString(3) ?? "Unknown";
131+
132+
Console.WriteLine();
133+
Console.WriteLine($"Azure Event Grid Simulator v{version}");
134+
Console.WriteLine(new string('=', 50));
135+
Console.WriteLine();
136+
Console.WriteLine(
137+
"No topics configured. To get started, provide configuration using one of these methods:"
138+
);
139+
Console.WriteLine();
140+
Console.WriteLine("1. Create an appsettings.json file in the current directory:");
141+
Console.WriteLine();
142+
Console.WriteLine(" {");
143+
Console.WriteLine(" \"topics\": [");
144+
Console.WriteLine(" {");
145+
Console.WriteLine(" \"name\": \"MyTopic\",");
146+
Console.WriteLine(" \"port\": 60101,");
147+
Console.WriteLine(" \"key\": \"MyAccessKey=\",");
148+
Console.WriteLine(" \"subscribers\": [");
149+
Console.WriteLine(" {");
150+
Console.WriteLine(" \"name\": \"MySubscriber\",");
151+
Console.WriteLine(" \"endpoint\": \"https://localhost:5000/api/events\",");
152+
Console.WriteLine(" \"disableValidation\": true");
153+
Console.WriteLine(" }");
154+
Console.WriteLine(" ]");
155+
Console.WriteLine(" }");
156+
Console.WriteLine(" ]");
157+
Console.WriteLine(" }");
158+
Console.WriteLine();
159+
Console.WriteLine("2. Use the --ConfigFile argument to specify a config file path:");
160+
Console.WriteLine();
161+
Console.WriteLine(" azure-eventgrid-simulator --ConfigFile=/path/to/config.json");
162+
Console.WriteLine();
163+
Console.WriteLine("3. Use environment variables with the AEGS_ prefix:");
164+
Console.WriteLine();
165+
Console.WriteLine(
166+
" AEGS_topics__0__name=MyTopic AEGS_topics__0__port=60101 azure-eventgrid-simulator"
167+
);
168+
Console.WriteLine();
169+
Console.WriteLine(
170+
"For more information, visit: https://github.com/pmcilreavy/AzureEventGridSimulator"
171+
);
172+
Console.WriteLine();
173+
}
174+
135175
private static WebApplicationBuilder CreateWebHostBuilder(string[] args)
136176
{
137177
// Set up basic Console logger we can use to log to until we've finished building everything

0 commit comments

Comments
 (0)