Skip to content

Commit d9ada63

Browse files
committed
Refactored constructors to use primary constructors.
1 parent 84162ff commit d9ada63

13 files changed

+22
-53
lines changed

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/CdCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
options: "bookmark|roaming",
66
disableProxyOutput: true,
77
example: "//View current working directory|cd|//Traverse down one directory|//Change working directory|cd ..|cd \"C:\\ProgramData\"|//Set bookmark as the working directory using name|cd --bookmark program|//Set bookmark as the working directory using index|cd --bookmark 0|//Set first existing bookmark (if any) as working directory|cd --bookmark")]
8-
public class CdCommand : CommandBase<CommandsConfiguration>, IWorkingDirectoryChangesListener
8+
public class CdCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration), IWorkingDirectoryChangesListener
99
{
1010
public static string WorkingDirectory = AppContext.BaseDirectory;
1111
public static Action<string[], string[]>? WorkingDirectoryChanged;
12-
public CdCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
12+
1313
public override RunResult Run()
1414
{
1515
var path = WorkingDirectory;

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/ClsCommand.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
[PowerCommandTest( tests: " ")]
44
[PowerCommandDesign(description: "Clears the console",
55
disableProxyOutput: true)]
6-
public class ClsCommand : CommandBase<CommandsConfiguration>
6+
public class ClsCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
77
{
8-
public ClsCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
98
public override RunResult Run()
109
{
1110
Console.Clear();
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
namespace PainKiller.PowerCommands.Core.Commands;
22

3-
public class CommandTemplate : CommandBase<CommandsConfiguration>
3+
public class CommandTemplate(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
44
{
5-
public CommandTemplate(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
6-
7-
public override RunResult Run()
8-
{
9-
return Ok();
10-
}
5+
public override RunResult Run() => Ok();
116
}

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/CommandsCommand.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
options: "this|reserved|default|!update|add-proxy",
77
disableProxyOutput: true,
88
example: "//Show all commands|commands|//Show your custom commands|commands --this|//Show reserved commands|commands --reserved|//Search for commands matching \"encrypt\"|commands \"encrypt\"|//Show default command|commands --default|//Update the dir command (command must exist in the configured PowerCommands project)|commands --update dir|//Add a proxy|commands --add-proxy")]
9-
public class CommandsCommand : CommandBase<CommandsConfiguration>
9+
public class CommandsCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
1010
{
11-
public CommandsCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
12-
1311
public override RunResult Run()
1412
{
1513
Input.DoBadOptionCheck(this);

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/DescribeCommand.cs

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
options: "docs|clear",
77
disableProxyOutput: true,
88
example: "describe exit|describe cls|describe log|//Open documentation about options (if any)|describe options --doc")]
9-
public class DescribeCommand : CommandBase<CommandsConfiguration>
9+
public class DescribeCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
1010
{
11-
public DescribeCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
12-
1311
public override RunResult Run()
1412
{
1513
if(Input.HasOption("docs")) ShowDoc();
@@ -43,8 +41,8 @@ public void ShowDoc()
4341

4442
private void ShowCommand()
4543
{
46-
var identifier = string.IsNullOrEmpty(Input.SingleArgument) ? "describe" : Input.SingleArgument;
47-
var command = IPowerCommandsRuntime.DefaultInstance?.Commands.FirstOrDefault(c => c.Identifier == identifier);
44+
var commandIdentifier = string.IsNullOrEmpty(Input.SingleArgument) ? "describe" : Input.SingleArgument;
45+
var command = IPowerCommandsRuntime.DefaultInstance?.Commands.FirstOrDefault(c => c.Identifier == commandIdentifier);
4846
if (command == null)
4947
{
5048
if (Input.Identifier != nameof(DescribeCommand).ToLower().Replace("command", "")) WriteLine($"Command with identifier:{Input.Identifier} not found");

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/DirCommand.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
[PowerCommandDesign(description: "List the content of the working directory or this applications app directory, with the option to open the directory with the File explorer ",
44
options: "open|app",
55
example: "//List the content and open the current working directory|dir --open|//Open the AppData roaming directory|dir --app --open")]
6-
public class DirCommand : CommandBase<CommandsConfiguration>
6+
public class DirCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
77
{
8-
public DirCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
9-
108
public override RunResult Run()
119
{
1210
var directory = Input.HasOption("app") ? ConfigurationGlobals.ApplicationDataFolder : CdCommand.WorkingDirectory;

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/ExitCommand.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@
55
suggestions: "y",
66
disableProxyOutput: true,
77
example: "exit|exit y|exit Yes")]
8-
public class ExitCommand : CommandBase<CommandsConfiguration>
8+
public class ExitCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
99
{
10-
public ExitCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
1110
public override RunResult Run()
1211
{
1312
if (Input.Arguments.Length > 0 && Input.Arguments.First().ToLower().StartsWith("y")) return new RunResult(this, Input, output: "exit program", RunResultStatus.Quit);

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/LogCommand.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
suggestions: "view|archive",
77
disableProxyOutput: true,
88
example: "//View a list with all the logfiles|log|//Archive the logs into a zip file.|log archive|//View content of the current log|log view|//Filter the log show only posts matching the provided process tag, this requires that you are using process tags when logging in your command(s).|log --process created")]
9-
public class LogCommand : CommandBase<CommandsConfiguration>
9+
public class LogCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
1010
{
11-
public LogCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
12-
1311
public override RunResult Run()
1412
{
1513
if (Input.Options.Length == 0) List();

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/PowerCommandCommand.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
quotes: "<path>",
88
disableProxyOutput: true,
99
example: "//create new VS solution|powercommand new --solution testproject --output \"C:\\Temp\\\"|//Create new PowerCommand named Demo|powercommand new --command Demo|//Update powercommands core, this will first delete current Core projects and than apply the new Core projects|powercommand update|//Only update template(s)|powercommand update --templates|//Update with backup|powercommand update --backup|//Create a new command|powercommand new --command MyNewCommand")]
10-
public class PowerCommandCommand : CommandBase<CommandsConfiguration>
10+
public class PowerCommandCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
1111
{
1212
private readonly ArtifactPathsConfiguration _artifact = ConfigurationService.Service.Get<ArtifactPathsConfiguration>().Configuration;
13-
public PowerCommandCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
13+
1414
public override RunResult Run()
1515
{
1616
var name = Input.HasOption("solution") ? Input.GetOptionValue("solution") : Input.GetOptionValue("template");

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/ProxyCommando.cs

+5-16
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,16 @@
44
options: "retry-interval-seconds|no-quit",
55
example: "//Use the retry-interval-seconds option to decide how long pause it should be between retries|//\nUse the --no-quit option to tell the proxy application to not quit after the command is run.",
66
disableProxyOutput: true)]
7-
public class ProxyCommando : CommandBase<CommandsConfiguration>
7+
public class ProxyCommando(string identifier, CommandsConfiguration configuration, string name, string workingDirectory, string aliasName)
8+
: CommandBase<CommandsConfiguration>(string.IsNullOrEmpty(aliasName) ? identifier : aliasName, configuration)
89
{
9-
private readonly string _name;
10-
private readonly string _workingDirctory;
11-
private readonly string _aliasName;
12-
private readonly string _identifier;
13-
14-
public ProxyCommando(string identifier, CommandsConfiguration configuration, string name, string workingDirectory, string aliasName) : base(string.IsNullOrEmpty(aliasName) ? identifier : aliasName, configuration)
15-
{
16-
_identifier = identifier;
17-
_name = name;
18-
_workingDirctory = workingDirectory;
19-
_aliasName = aliasName;
20-
}
2110
public override RunResult Run()
2211
{
2312
WriteProcessLog("Proxy", $"{Input.Raw}");
24-
var input = (Identifier == _identifier) ? Input.Raw.Interpret(Configuration.DefaultCommand) : Input.Raw.Replace(_aliasName, _identifier).Interpret(Configuration.DefaultCommand);
13+
var input = (Identifier == identifier) ? Input.Raw.Interpret(Configuration.DefaultCommand) : Input.Raw.Replace(aliasName, identifier).Interpret(Configuration.DefaultCommand);
2514
var start = DateTime.Now;
2615
var quitOption = Input.HasOption("no-quit") ? "" : " --justRunOnceThenQuitPowerCommand";
27-
ShellService.Service.Execute(_name, $"{input.Raw}{quitOption}", _workingDirctory, WriteLine, useShellExecute: true);
16+
ShellService.Service.Execute(name, $"{input.Raw}{quitOption}", workingDirectory, WriteLine, useShellExecute: true);
2817

2918
var retries = 0;
3019
var maxRetries = 10;
@@ -48,5 +37,5 @@ public override RunResult Run()
4837
}
4938
return Ok();
5039
}
51-
private string GetOutputFilename() => Path.Combine(ConfigurationGlobals.ApplicationDataFolder, $"proxy_{_identifier}.data");
40+
private string GetOutputFilename() => Path.Combine(ConfigurationGlobals.ApplicationDataFolder, $"proxy_{identifier}.data");
5241
}

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/SecretCommand.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ namespace PainKiller.PowerCommands.Core.Commands;
66
options: "create|initialize|configuration|remove|salt",
77
disableProxyOutput: true,
88
example: "//View all declared secrets|secret|secret --create \"mycommand-pass\"|secret --remove \"mycommand-pass\"|//Initialize your machine with a new encryption key (stops if this is already done)|secret --initialize")]
9-
public class SecretCommand : CommandBase<CommandsConfiguration>
9+
public class SecretCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
1010
{
11-
public SecretCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
1211
public override RunResult Run()
1312
{
1413
if (Input.HasOption("initialize")) return Init();

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/TestCommand.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
options: "all|!command|trace",
55
disableProxyOutput: true,
66
example: "//Test a specific command|test --command commandName|//Test all commands (default) option could be omitted|test --all")]
7-
public class TestCommand : CommandBase<CommandsConfiguration>
7+
public class TestCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
88
{
9-
public TestCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
10-
119
public override RunResult Run()
1210
{
1311
Console.Clear();

src/PainKiller.PowerCommands/Core/PainKiller.PowerCommands.Core/Commands/VersionCommand.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ namespace PainKiller.PowerCommands.Core.Commands;
55
[PowerCommandTest(tests: " ")]
66
[PowerCommandDesign(description:"Shows current version for the Core components.",
77
disableProxyOutput: true)]
8-
public class VersionCommand : CommandBase<CommandsConfiguration>
8+
public class VersionCommand(string identifier, CommandsConfiguration configuration) : CommandBase<CommandsConfiguration>(identifier, configuration)
99
{
10-
public VersionCommand(string identifier, CommandsConfiguration configuration) : base(identifier, configuration) { }
11-
1210
public override RunResult Run()
1311
{
1412
WriteLine($" {nameof(Core)}: {ReflectionService.Service.GetVersion(Assembly.Load($"PainKiller.PowerCommands.Core"))}");

0 commit comments

Comments
 (0)