Skip to content

Commit ad1fd78

Browse files
authored
Run ReSharper code cleanup (#59)
1 parent bb0ba6d commit ad1fd78

50 files changed

Lines changed: 2117 additions & 2161 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build/Build.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class Build : NukeBuild
2626
/// - JetBrains Rider https://nuke.build/rider
2727
/// - Microsoft VisualStudio https://nuke.build/visualstudio
2828
/// - Microsoft VSCode https://nuke.build/vscode
29-
3029
[Parameter("Configuration to build - Default is 'Debug' (local) or 'Release' (server)")]
3130
readonly Configuration Configuration = IsLocalBuild ? Configuration.Debug : Configuration.Release;
3231

@@ -44,7 +43,7 @@ class Build : NukeBuild
4443
[OctoVersion(UpdateBuildNumber = true, BranchParameter = nameof(BranchName),
4544
AutoDetectBranchParameter = nameof(AutoDetectBranch), Framework = "net6.0")]
4645
readonly OctoVersionInfo OctoVersionInfo;
47-
46+
4847
AbsolutePath SourceDirectory => RootDirectory / "source";
4948
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
5049
AbsolutePath LocalPackagesDirectory => RootDirectory / ".." / "LocalPackages";
@@ -178,4 +177,4 @@ static void ReplaceTextInFiles(AbsolutePath path, string oldValue, string newVal
178177
.DependsOn(CopyToLocalPackages);
179178

180179
public static int Main() => Execute<Build>(x => x.Default);
181-
}
180+
}

build/Configuration.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@
77
[TypeConverter(typeof(TypeConverter<Configuration>))]
88
public class Configuration : Enumeration
99
{
10-
public static Configuration Debug = new Configuration { Value = nameof(Debug) };
11-
public static Configuration Release = new Configuration { Value = nameof(Release) };
10+
public static Configuration Debug = new()
11+
{ Value = nameof(Debug) };
12+
13+
public static Configuration Release = new()
14+
{ Value = nameof(Release) };
1215

1316
public static implicit operator string(Configuration configuration)
1417
=> configuration.Value;

global.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"sdk": {
3-
"version": "6.0.300",
4-
"rollForward": "latestFeature"
5-
}
6-
}
2+
"sdk": {
3+
"version": "6.0.300",
4+
"rollForward": "latestFeature"
5+
}
6+
}

octoversion.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"NonPreReleaseTags": ["refs/heads/main", "refs/heads/master"]
2+
"NonPreReleaseTags": ["refs/heads/main", "refs/heads/master"]
33
}

source/CommandLine/CommandLocator.cs

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,50 @@
33
using System.Linq;
44
using Octopus.CommandLine.Commands;
55

6-
namespace Octopus.CommandLine
7-
{
8-
public class CommandLocator : ICommandLocator
9-
{
10-
readonly IEnumerable<ICommand> commands;
6+
namespace Octopus.CommandLine;
117

12-
public CommandLocator(IEnumerable<ICommand> commands)
13-
=> this.commands = commands;
8+
public class CommandLocator : ICommandLocator
9+
{
10+
readonly IEnumerable<ICommand> commands;
1411

15-
public ICommandMetadata[] List()
16-
{
17-
return commands
18-
.Where(t => t.CommandMetadata != null)
19-
.Select(t => t.CommandMetadata)
20-
.ToArray();
21-
}
12+
public CommandLocator(IEnumerable<ICommand> commands)
13+
=> this.commands = commands;
2214

23-
public ICommand Find(string name)
24-
{
25-
name = name.Trim().ToLowerInvariant();
15+
public ICommandMetadata[] List()
16+
{
17+
return commands
18+
.Where(t => t.CommandMetadata != null)
19+
.Select(t => t.CommandMetadata)
20+
.ToArray();
21+
}
2622

27-
var found = commands
28-
.Where(command => command.CommandMetadata != null)
29-
.FirstOrDefault(command => command.CommandMetadata.Name == name || command.CommandMetadata.Aliases.Any(a => a == name));
23+
public ICommand Find(string name)
24+
{
25+
name = name.Trim().ToLowerInvariant();
3026

31-
return found;
32-
}
27+
var found = commands
28+
.Where(command => command.CommandMetadata != null)
29+
.FirstOrDefault(command => command.CommandMetadata.Name == name || command.CommandMetadata.Aliases.Any(a => a == name));
3330

34-
public ICommand GetCommand(string[] args)
35-
{
36-
var first = GetFirstArgument(args);
31+
return found;
32+
}
3733

38-
if (string.IsNullOrWhiteSpace(first))
39-
// if help is unavailable, it means the registration of commands is messed up, and HelpCommand wasn't available
40-
return Find("help") ?? throw new CommandException($"Error: No 'help' command found. Help is unavailable.{Environment.NewLine}"
41-
+ $"Developers - please ensure that all implementations of {nameof(ICommand)} within the CommandLine library are registered.");
34+
public ICommand GetCommand(string[] args)
35+
{
36+
var first = GetFirstArgument(args);
4237

43-
var command = Find(first);
44-
if (command == null)
45-
throw new CommandException("Error: Unrecognized command '" + first + "'");
38+
if (string.IsNullOrWhiteSpace(first))
39+
// if help is unavailable, it means the registration of commands is messed up, and HelpCommand wasn't available
40+
return Find("help") ?? throw new CommandException($"Error: No 'help' command found. Help is unavailable.{Environment.NewLine}"
41+
+ $"Developers - please ensure that all implementations of {nameof(ICommand)} within the CommandLine library are registered.");
4642

47-
return command;
48-
}
43+
var command = Find(first);
44+
if (command == null)
45+
throw new CommandException("Error: Unrecognized command '" + first + "'");
4946

50-
static string GetFirstArgument(IEnumerable<string> args)
51-
=> (args.FirstOrDefault() ?? string.Empty).ToLowerInvariant().TrimStart('-', '/');
47+
return command;
5248
}
49+
50+
static string GetFirstArgument(IEnumerable<string> args)
51+
=> (args.FirstOrDefault() ?? string.Empty).ToLowerInvariant().TrimStart('-', '/');
5352
}

source/CommandLine/CommandOutputProvider.cs

Lines changed: 109 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -7,139 +7,138 @@
77
using Serilog;
88
using Serilog.Events;
99

10-
namespace Octopus.CommandLine
10+
namespace Octopus.CommandLine;
11+
12+
public class CommandOutputProvider : ICommandOutputProvider
1113
{
12-
public class CommandOutputProvider : ICommandOutputProvider
13-
{
14-
readonly ILogger logger;
14+
readonly ILogger logger;
1515

16-
readonly string applicationName;
17-
readonly ICommandOutputJsonSerializer commandOutputJsonSerializer;
16+
readonly string applicationName;
17+
readonly ICommandOutputJsonSerializer commandOutputJsonSerializer;
1818

19-
public CommandOutputProvider(string applicationName, string applicationVersion, ILogger logger)
20-
: this(applicationName, applicationVersion, new DefaultCommandOutputJsonSerializer(), logger)
21-
{
22-
}
19+
public CommandOutputProvider(string applicationName, string applicationVersion, ILogger logger)
20+
: this(applicationName, applicationVersion, new DefaultCommandOutputJsonSerializer(), logger)
21+
{
22+
}
2323

24-
public CommandOutputProvider(string applicationName, string applicationVersion, ICommandOutputJsonSerializer commandOutputJsonSerializer, ILogger logger)
25-
{
26-
this.applicationVersion = applicationVersion;
27-
this.applicationName = applicationName;
28-
this.commandOutputJsonSerializer = commandOutputJsonSerializer;
29-
this.logger = logger;
30-
PrintMessages = true; // unless told otherwise
31-
}
24+
public CommandOutputProvider(string applicationName, string applicationVersion, ICommandOutputJsonSerializer commandOutputJsonSerializer, ILogger logger)
25+
{
26+
this.applicationVersion = applicationVersion;
27+
this.applicationName = applicationName;
28+
this.commandOutputJsonSerializer = commandOutputJsonSerializer;
29+
this.logger = logger;
30+
PrintMessages = true; // unless told otherwise
31+
}
3232

33-
public string applicationVersion { get; }
33+
public string applicationVersion { get; }
3434

35-
public bool PrintMessages { get; set; }
35+
public bool PrintMessages { get; set; }
3636

37-
public void PrintHeader()
37+
public void PrintHeader()
38+
{
39+
if (PrintMessages)
3840
{
39-
if (PrintMessages)
40-
{
41-
logger.Information($"{applicationName}, version {applicationVersion}");
42-
logger.Information(string.Empty);
43-
}
41+
logger.Information($"{applicationName}, version {applicationVersion}");
42+
logger.Information(string.Empty);
4443
}
44+
}
4545

46-
public void PrintCommandHelpHeader(string executable, string commandName, string description, TextWriter textWriter)
47-
{
48-
if (PrintMessages)
49-
{
50-
Console.ResetColor();
51-
textWriter.WriteLine(description);
52-
textWriter.WriteLine();
53-
textWriter.Write("Usage: ");
54-
Console.ForegroundColor = ConsoleColor.White;
55-
textWriter.WriteLine($"{executable} {commandName} [<options>]");
56-
Console.ResetColor();
57-
textWriter.WriteLine();
58-
textWriter.WriteLine("Where [<options>] is any of: ");
59-
textWriter.WriteLine();
60-
}
46+
public void PrintCommandHelpHeader(string executable, string commandName, string description, TextWriter textWriter)
47+
{
48+
if (PrintMessages)
49+
{
50+
Console.ResetColor();
51+
textWriter.WriteLine(description);
52+
textWriter.WriteLine();
53+
textWriter.Write("Usage: ");
54+
Console.ForegroundColor = ConsoleColor.White;
55+
textWriter.WriteLine($"{executable} {commandName} [<options>]");
56+
Console.ResetColor();
57+
textWriter.WriteLine();
58+
textWriter.WriteLine("Where [<options>] is any of: ");
59+
textWriter.WriteLine();
6160
}
61+
}
6262

63-
public void PrintCommandOptions(Options options, TextWriter writer)
64-
{
65-
if (PrintMessages)
66-
foreach (var g in options.OptionSets.Keys.Reverse())
67-
{
68-
writer.WriteLine($"{g}: ");
69-
writer.WriteLine();
70-
options.OptionSets[g].WriteOptionDescriptions(writer);
71-
writer.WriteLine();
72-
}
73-
}
63+
public void PrintCommandOptions(Options options, TextWriter writer)
64+
{
65+
if (PrintMessages)
66+
foreach (var g in options.OptionSets.Keys.Reverse())
67+
{
68+
writer.WriteLine($"{g}: ");
69+
writer.WriteLine();
70+
options.OptionSets[g].WriteOptionDescriptions(writer);
71+
writer.WriteLine();
72+
}
73+
}
7474

75-
public void Debug(string template, string propertyValue)
76-
{
77-
if (PrintMessages)
78-
logger.Debug(template, propertyValue);
79-
}
75+
public void Debug(string template, string propertyValue)
76+
{
77+
if (PrintMessages)
78+
logger.Debug(template, propertyValue);
79+
}
8080

81-
public void Debug(string template, params object[] propertyValues)
82-
{
83-
if (PrintMessages)
84-
logger.Debug(template, propertyValues);
85-
}
81+
public void Debug(string template, params object[] propertyValues)
82+
{
83+
if (PrintMessages)
84+
logger.Debug(template, propertyValues);
85+
}
8686

87-
public void Information(string template, string propertyValue)
88-
{
89-
if (PrintMessages)
90-
logger.Information(template, propertyValue);
91-
}
87+
public void Information(string template, string propertyValue)
88+
{
89+
if (PrintMessages)
90+
logger.Information(template, propertyValue);
91+
}
9292

93-
public void Information(string template, params object[] propertyValues)
94-
{
95-
if (PrintMessages)
96-
logger.Information(template, propertyValues);
97-
}
93+
public void Information(string template, params object[] propertyValues)
94+
{
95+
if (PrintMessages)
96+
logger.Information(template, propertyValues);
97+
}
9898

99-
public void Json(object o)
100-
{
101-
logger.Information(commandOutputJsonSerializer.SerializeObjectToJson(o));
102-
}
99+
public void Json(object o)
100+
{
101+
logger.Information(commandOutputJsonSerializer.SerializeObjectToJson(o));
102+
}
103103

104-
public void Json(object o, TextWriter writer)
104+
public void Json(object o, TextWriter writer)
105+
{
106+
var settings = new JsonSerializerSettings
105107
{
106-
var settings = new JsonSerializerSettings
107-
{
108-
NullValueHandling = NullValueHandling.Ignore,
109-
Formatting = Formatting.Indented,
110-
Converters = new JsonConverterCollection { new StringEnumConverter() }
111-
};
112-
writer.WriteLine(JsonConvert.SerializeObject(o, settings));
113-
}
108+
NullValueHandling = NullValueHandling.Ignore,
109+
Formatting = Formatting.Indented,
110+
Converters = new JsonConverterCollection { new StringEnumConverter() }
111+
};
112+
writer.WriteLine(JsonConvert.SerializeObject(o, settings));
113+
}
114114

115-
public void Warning(string s)
116-
{
117-
if (PrintMessages)
118-
logger.Warning(s);
119-
}
115+
public void Warning(string s)
116+
{
117+
if (PrintMessages)
118+
logger.Warning(s);
119+
}
120120

121-
public void Warning(string template, params object[] propertyValues)
122-
{
123-
if (PrintMessages)
124-
logger.Warning(template, propertyValues);
125-
}
121+
public void Warning(string template, params object[] propertyValues)
122+
{
123+
if (PrintMessages)
124+
logger.Warning(template, propertyValues);
125+
}
126126

127-
public void Error(string template, params object[] propertyValues)
128-
{
129-
if (PrintMessages)
130-
logger.Error(template, propertyValues);
131-
}
127+
public void Error(string template, params object[] propertyValues)
128+
{
129+
if (PrintMessages)
130+
logger.Error(template, propertyValues);
131+
}
132132

133-
public void Write(LogEventLevel logEventLevel, string messageTemplate, params object[] propertyValues)
134-
{
135-
if (PrintMessages)
136-
logger.Write(logEventLevel, messageTemplate, propertyValues);
137-
}
133+
public void Write(LogEventLevel logEventLevel, string messageTemplate, params object[] propertyValues)
134+
{
135+
if (PrintMessages)
136+
logger.Write(logEventLevel, messageTemplate, propertyValues);
137+
}
138138

139-
public void Error(Exception ex, string messageTemplate)
140-
{
141-
if (PrintMessages)
142-
logger.Error(ex, messageTemplate);
143-
}
139+
public void Error(Exception ex, string messageTemplate)
140+
{
141+
if (PrintMessages)
142+
logger.Error(ex, messageTemplate);
144143
}
145144
}

0 commit comments

Comments
 (0)