Skip to content

Commit 0d1004a

Browse files
committed
Add internet connection check
1 parent 9973163 commit 0d1004a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/Atc.CodingRules.Updater.CLI/Commands/RootCommand.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace Atc.CodingRules.Updater.CLI.Commands;
22

3+
[SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "OK.")]
34
public class RootCommand : AsyncCommand<RootCommandSettings>
45
{
56
public override Task<int> ExecuteAsync(
@@ -14,6 +15,12 @@ public override Task<int> ExecuteAsync(
1415
private static async Task<int> ExecuteInternalAsync(
1516
RootCommandSettings settings)
1617
{
18+
if (!NetworkInformationHelper.HasConnection())
19+
{
20+
System.Console.WriteLine("This tool requires internet connection!");
21+
return ConsoleExitStatusCodes.Failure;
22+
}
23+
1724
if (settings.IsOptionValueTrue(settings.Version))
1825
{
1926
try
@@ -30,7 +37,6 @@ private static async Task<int> ExecuteInternalAsync(
3037
return ConsoleExitStatusCodes.Success;
3138
}
3239

33-
[SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "OK.")]
3440
private static void HandleVersionOption()
3541
{
3642
System.Console.WriteLine(CliHelper.GetCurrentVersion().ToString());

src/Atc.CodingRules.Updater.CLI/Commands/RunCommand.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// ReSharper disable SuggestBaseTypeForParameter
2-
3-
using Atc.CodingRules.Updater.CLI.Models.Options;
4-
52
namespace Atc.CodingRules.Updater.CLI.Commands;
63

4+
[SuppressMessage("Globalization", "CA1303:Do not pass literals as localized parameters", Justification = "OK.")]
75
public class RunCommand : AsyncCommand<RunCommandSettings>
86
{
97
private readonly ILogger<RunCommand> logger;
@@ -22,6 +20,12 @@ public override Task<int> ExecuteAsync(
2220
private async Task<int> ExecuteInternalAsync(
2321
RunCommandSettings settings)
2422
{
23+
if (!NetworkInformationHelper.HasConnection())
24+
{
25+
System.Console.WriteLine("This tool requires internet connection!");
26+
return ConsoleExitStatusCodes.Failure;
27+
}
28+
2529
ConsoleHelper.WriteHeader();
2630

2731
var projectPath = new DirectoryInfo(settings.ProjectPath);

src/Atc.CodingRules.Updater.CLI/GlobalUsings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
global using Atc.CodingRules.Updater.CLI.Commands.DescriptionAttributes;
1414
global using Atc.CodingRules.Updater.CLI.Commands.Settings;
1515
global using Atc.CodingRules.Updater.CLI.Extensions;
16+
global using Atc.CodingRules.Updater.CLI.Models.Options;
1617
global using Atc.Console.Spectre;
1718
global using Atc.Console.Spectre.CommandSettings;
1819
global using Atc.Console.Spectre.Factories;

0 commit comments

Comments
 (0)