Skip to content

Commit 81c9008

Browse files
committed
Fix warnings
1 parent 614564d commit 81c9008

File tree

9 files changed

+50
-35
lines changed

9 files changed

+50
-35
lines changed

src/Moryx.Cli.Commands/AddThing.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ public class AddConfig
4646
/// <summary>
4747
/// Name of the solution file (<SolutionName>.sln)
4848
/// </summary>
49-
public string SolutionName { get; set; }
49+
public required string SolutionName { get; set; }
5050

5151
/// <summary>
5252
/// Type of this thing, like `module`. Used for displaying user outputs
5353
/// </summary>
54-
public string Thing { get; set; }
54+
public required string Thing { get; set; }
5555

5656
/// <summary>
5757
/// Actual name identifiere of the *thing* to be added
5858
/// </summary>
59-
public string ThingName { get; set; }
59+
public required string ThingName { get; set; }
6060

6161
/// <summary>
6262
/// *Thing*s placeholder
6363
/// </summary>
64-
public IEnumerable<string> ThingPlaceholders { get; set; }
64+
public required IEnumerable<string> ThingPlaceholders { get; set; }
6565
}
6666
}

src/Moryx.Cli.Commands/Extensions/ConfigExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public static TemplateSettings LoadSettings(string dir, string solutionName, str
2020
public static Config.Models.Configuration ToConfiguration(this NewOptions options, string profile = "default")
2121
{
2222
var result = Config.Models.Configuration.DefaultConfiguration();
23-
result.Profiles[profile].Repository = options.Template;
24-
result.Profiles[profile].Branch = options.Branch;
23+
result.Profiles[profile].Repository = options.Template ?? DefaultValues.DefaultTemplate;
24+
result.Profiles[profile].Branch = options.Branch ?? DefaultValues.DefaultBranch;
2525
return result;
2626
}
2727
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Moryx.Cli.Commands.Options
8+
{
9+
public static class DefaultValues
10+
{
11+
public const string DefaultTemplate = "https://github.com/PHOENIXCONTACT/MORYX-Template.git";
12+
public const string DefaultBranch = "machine";
13+
}
14+
}

src/Moryx.Cli.Config/Models/Configuration.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ namespace Moryx.Cli.Config.Models
55
{
66
public class Configuration
77
{
8-
public Dictionary<string, Profile> Profiles { get; set; }
8+
public required Dictionary<string, Profile> Profiles { get; set; }
99

1010
public static Configuration Load(string directory) {
1111
try
1212
{
1313
using var file = File.OpenText(GetFilename(directory));
1414
var serializer = new JsonSerializer();
15-
return (Configuration)serializer.Deserialize(file, typeof(Configuration))
16-
?? DefaultConfiguration();
15+
return serializer.Deserialize(file, typeof(Configuration)) as Configuration ?? DefaultConfiguration();
1716
} catch (Exception)
1817
{
1918
return DefaultConfiguration();

src/Moryx.Cli.Config/Models/Profile.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
{
33
public class Profile
44
{
5-
public string Branch { get;set; }
6-
public string Repository { get; set; }
5+
public required string Branch { get;set; }
6+
public required string Repository { get; set; }
77
}
88
}

src/Moryx.Cli.Template/Models/TemplateSettings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
{
33
public class TemplateSettings
44
{
5-
public string Branch { get; set; }
6-
public string Repository { get; set; }
5+
public required string Branch { get; set; }
6+
public required string Repository { get; set; }
77
public bool Pull { get; set; }
8-
public string AppName { get; set; }
8+
public required string AppName { get; set; }
99
public string ProfileName { get; set; } = "default";
10-
public string TargetDirectory { get; set; }
10+
public required string TargetDirectory { get; set; }
1111
public string SourceDirectory { get => Path.Combine(TemplatesRoot(), ProfileName, Branch); }
1212

1313

src/Moryx.Cli.Template/Template.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ public static string GetSolutionName(string dir, Action<string> onError)
277277

278278
public class ProjectFileInfo
279279
{
280-
public string Name { get; set; }
281-
public string Filename { get; set; }
282-
public string Extension { get; set; }
280+
public required string Name { get; set; }
281+
public required string Filename { get; set; }
282+
public required string Extension { get; set; }
283283

284284

285285
public override bool Equals(object? obj)
@@ -301,6 +301,8 @@ internal class ListComparer : IEqualityComparer<string>
301301

302302
public bool Equals(string? x, string? y)
303303
{
304+
if (x == null || y == null)
305+
return false;
304306
return y.Contains(x);
305307
}
306308

src/Moryx.Cli/CommandLine/Add.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ internal class AddProductSettings : AddSettings
3333

3434
[Description("A Git repository url that will be used for the project template.")]
3535
[CommandOption("-t|--template-url")]
36-
public string? Template { get; set; }
36+
public new string? Template { get; set; }
3737

3838
[Description("Branch to use with the template repository.")]
3939
[CommandOption("-b|--branch")]
40-
public string? Branch { get; set; }
40+
public new string? Branch { get; set; }
4141

4242
[Description("Update the template repository.")]
4343
[CommandOption("--pull"), DefaultValue(false)]
44-
public bool Pull { get; set; }
44+
public new bool Pull { get; set; }
4545
}
4646

4747
public override int Execute([NotNull] CommandContext context, [NotNull] AddProductSettings settings)
@@ -70,15 +70,15 @@ internal class AddStepSettings : AddSettings
7070

7171
[Description("A Git repository url that will be used for the project template.")]
7272
[CommandOption("-t|--template-url")]
73-
public string? Template { get; set; }
73+
public new string? Template { get; set; }
7474

7575
[Description("Branch to use with the template repository.")]
7676
[CommandOption("-b|--branch")]
77-
public string? Branch { get; set; }
77+
public new string? Branch { get; set; }
7878

7979
[Description("Update the template repository.")]
8080
[CommandOption("--pull"), DefaultValue(false)]
81-
public bool Pull { get; set; }
81+
public new bool Pull { get; set; }
8282
}
8383

8484
public override int Execute([NotNull] CommandContext context, [NotNull] AddStepSettings settings)
@@ -107,15 +107,15 @@ internal class AddModuleSettings : AddSettings
107107

108108
[Description("A Git repository url that will be used for the project template.")]
109109
[CommandOption("-t|--template-url")]
110-
public string? Template { get; set; }
110+
public new string? Template { get; set; }
111111

112112
[Description("Branch to use with the template repository.")]
113113
[CommandOption("-b|--branch")]
114-
public string? Branch { get; set; }
114+
public new string? Branch { get; set; }
115115

116116
[Description("Update the template repository.")]
117117
[CommandOption("--pull"), DefaultValue(false)]
118-
public bool Pull { get; set; }
118+
public new bool Pull { get; set; }
119119
}
120120

121121
public override int Execute([NotNull] CommandContext context, [NotNull] AddModuleSettings settings)
@@ -144,15 +144,15 @@ internal class AddResourcesSettings : AddSettings
144144

145145
[Description("A Git repository url that will be used for the project template.")]
146146
[CommandOption("-t|--template-url")]
147-
public string? Template { get; set; }
147+
public new string? Template { get; set; }
148148

149149
[Description("Branch to use with the template repository.")]
150150
[CommandOption("-b|--branch")]
151-
public string? Branch { get; set; }
151+
public new string? Branch { get; set; }
152152

153153
[Description("Update the template repository.")]
154154
[CommandOption("--pull"), DefaultValue(false)]
155-
public bool Pull { get; set; }
155+
public new bool Pull { get; set; }
156156
}
157157

158158
public override int Execute([NotNull] CommandContext context, [NotNull] AddResourcesSettings settings)
@@ -189,15 +189,15 @@ internal class AddStatesSettings : AddSettings
189189

190190
[Description("A Git repository url that will be used for the project template.")]
191191
[CommandOption("-t|--template-url")]
192-
public string? Template { get; set; }
192+
public new string? Template { get; set; }
193193

194194
[Description("Branch to use with the template repository.")]
195195
[CommandOption("-b|--branch")]
196-
public string? Branch { get; set; }
196+
public new string? Branch { get; set; }
197197

198198
[Description("Update the template repository.")]
199199
[CommandOption("--pull"), DefaultValue(false)]
200-
public bool Pull { get; set; }
200+
public new bool Pull { get; set; }
201201
}
202202

203203
public override int Execute([NotNull] CommandContext context, [NotNull] AddStatesSettings settings)

src/Moryx.Cli/CommandLine/New.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ internal class Settings : CommandSettings
3030
public bool NoGitInit { get; set; }
3131

3232
[Description("A Git repository url that will be used for the project template.")]
33-
[CommandOption("-t|--template-url"), DefaultValue("https://github.com/PHOENIXCONTACT/MORYX-Template.git")]
33+
[CommandOption("-t|--template-url"), DefaultValue(DefaultValues.DefaultTemplate)]
3434
public string? Template { get; set; }
3535

3636
[Description("Branch to use with the template repository.")]
37-
[CommandOption("-b|--branch"), DefaultValue("machine")]
37+
[CommandOption("-b|--branch"), DefaultValue(DefaultValues.DefaultBranch)]
3838
public string? Branch { get; set; }
3939

4040
[Description("Update the template repository.")]

0 commit comments

Comments
 (0)