Skip to content

Commit dcfc91d

Browse files
committed
Moved the logging options to the json file, meaning the cli is back to only having a single option to run. Updated readme
1 parent c910de3 commit dcfc91d

File tree

4 files changed

+34
-22
lines changed

4 files changed

+34
-22
lines changed

README.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,43 @@ There are 2 ways to run this. As a .NET Tool installed on your machine, or downl
3232
- --config-file, -d
3333
- Required
3434
- Path to the file to use for config values when updating code
35-
- --output-file, -o
36-
- Optional
37-
- If this is set, it will be the file to write logs to, in addition to the console
38-
- --log-level, -l
39-
- Optional
40-
- Verbosity level to log. Valid values are: Verbose, Info, Warn, Error. Default value: verbose.
35+
- --help, -h
36+
- Outputs CLI help
4137

4238
## Config File
4339

4440
The config file holds all values to determine what changes to make. The reason this is separate from CLI input arguments is to let a developer store this config in different repos but have this .NET Tool installed globally on their machine. That makes it easy to let other developers run this tool with specific settings for each repository, while only needing to provide a single CLI input argument.
4541

46-
Below are the list of properties in the config file. All fields are required.
42+
Below are the list of properties in the config file.
4743

4844
- RootDirectory
45+
- Required
4946
- Root directory to run from. Code Updater will search all child directories within this for projects to update.
5047
- IgnorePatterns
48+
- Required
5149
- String to ignore within file paths when looking for projects to update. This is OS sensitive, so use \ as the path separator for Windows, and / as the path separator everywhere else. Eg: `\my-skip-path\` will ignore all projects that have the text `\my-skip-path\` within the full path. Note this example will only happen on Windows because that uses backslashes for path separators.- NpmBuildCommand
5250
- NpmBuildCommand
51+
- Required
5352
- After upgrading all of the code, this application will attempt to build all applications it updated. This option sets the npm command to run to do the build.
5453
- Npm command to run to "compile" the npm directory. Default value is `publish`. Format run is: npm run <npmBuildCommand>.
5554
- DotNetTargetFramework
55+
- Required
5656
- Target Framework to set in all *.CsProj files
5757
- DotNetLangVersion
58+
- Required
5859
- C# language version to set in all *.CsProj files
5960
- EnableNetAnalyzers
61+
- Required
6062
- Boolean value to set the `EnableNetAnalyzers` csproj element to. If the `EnableNetAnalyzers` element does not exist in the project file, it will be added.
6163
- EnforceCodeStyleInBuild
64+
- Required
6265
- Boolean value to set the `EnforceCodeStyleInBuild` csproj element to. If the `EnableNetAnalyzers` element does not exist in the project file, it will be added.
66+
- OutputFile
67+
- Optional
68+
- If this is set, it will be the file to write logs to, in addition to the console
69+
- LogLevel
70+
- Optional
71+
- Verbosity level to log. Valid values are: Verbose, Info, Warn, Error. Default value: verbose.
6372

6473
### Example Config File
6574

src/CodeUpdater/CodeUpdater/Options/CommandOptions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,4 @@ public class CommandOptions
1313
{
1414
[Option(shortName: 'c', longName: "config-file", Required = true, HelpText = "Path to the file to use for config values when updating code")]
1515
public required string ConfigFile { get; set; }
16-
17-
[Option(shortName: 'o', longName: "output-file", Required = false, HelpText = "If this is set, it will be the file to write logs to, in addition to the console")]
18-
public string? OutputFile { get; set; }
19-
20-
[Option(shortName: 'l', longName: "log-level", Required = false, HelpText = "Verbosity level to log. Valid values are: Verbose, Info, Warn, Error. Default value: verbose.")]
21-
public string LogLevel { get; set; } = "verbose";
2216
}

src/CodeUpdater/CodeUpdater/Options/UpdateOptions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,14 @@ public class UpdateOptions
5555
/// </summary>
5656
[Required]
5757
public required bool EnforceCodeStyleInBuild { get; set; }
58+
59+
/// <summary>
60+
/// If this is set, it will be the file to write logs to, in addition to the console
61+
/// </summary>
62+
public string? OutputFile { get; set; }
63+
64+
/// <summary>
65+
/// Verbosity level to log. Valid values are: Verbose, Info, Warn, Error. Default value: verbose.
66+
/// </summary>
67+
public string? LogLevel { get; set; } = "verbose";
5868
}

src/CodeUpdater/CodeUpdater/Program.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,10 @@ await Parser.Default.ParseArguments<CommandOptions>(args)
2020
await RunAsync(options);
2121
});
2222

23-
static async ValueTask RunAsync(CommandOptions options)
23+
static async ValueTask RunAsync(CommandOptions commandOptions)
2424
{
25-
var logger = SetupLogger(options);
26-
27-
var updateOptions = await LoadUpdateOptionsAsync(options.ConfigFile);
25+
var updateOptions = await LoadUpdateOptionsAsync(commandOptions.ConfigFile);
26+
var logger = SetupLogger(updateOptions);
2827

2928
var runProcessHelper = new RunProcessHelper(logger);
3029
var workLocator = new WorkLocator(logger);
@@ -56,23 +55,23 @@ static async ValueTask RunAsync(CommandOptions options)
5655
OutputSummary(updateWork, csUpdates, npmUpdates, compileResults, logger);
5756
}
5857

59-
static ILogger SetupLogger(CommandOptions options)
58+
static ILogger SetupLogger(UpdateOptions updateOptions)
6059
{
6160
var loggerConfig = new LoggerConfiguration()
6261
.WriteTo.Console();
6362

64-
if (!string.IsNullOrWhiteSpace(options.OutputFile))
63+
if (!string.IsNullOrWhiteSpace(updateOptions.OutputFile))
6564
{
66-
loggerConfig = loggerConfig.WriteTo.File(options.OutputFile);
65+
loggerConfig = loggerConfig.WriteTo.File(updateOptions.OutputFile);
6766
}
6867

69-
if (string.IsNullOrWhiteSpace(options.LogLevel))
68+
if (string.IsNullOrWhiteSpace(updateOptions.LogLevel))
7069
{
7170
loggerConfig = loggerConfig.MinimumLevel.Verbose();
7271
}
7372
else
7473
{
75-
loggerConfig = options.LogLevel.ToLower() switch
74+
loggerConfig = updateOptions.LogLevel.ToLower() switch
7675
{
7776
"verbose" => loggerConfig.MinimumLevel.Verbose(),
7877
"info" => loggerConfig.MinimumLevel.Information(),

0 commit comments

Comments
 (0)