Skip to content

Commit

Permalink
Add editorconfig
Browse files Browse the repository at this point in the history
  • Loading branch information
intelligide committed Jun 17, 2023
1 parent 3945c14 commit 8c533ac
Show file tree
Hide file tree
Showing 16 changed files with 419 additions and 58 deletions.
361 changes: 361 additions & 0 deletions .editorconfig

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/HelixCoreServerCtl/AppConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ public static AppConfig Instance
{
InitInstance();
}
#pragma warning disable CS8603
#pragma warning disable CS8603
// Assigned in InitInstance method.
return appConfig;
#pragma warning restore CS8603
#pragma warning restore CS8603
}
}
}
2 changes: 1 addition & 1 deletion src/HelixCoreServerCtl/AppPaths.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ private class AppPathsJson
public string PidFileDirectory { get; set; } = default!;

public string DefaultServerRootDirectory { get; set; } = default!;

public string P4DExecute { get; set; } = default!;
}

Expand Down
2 changes: 1 addition & 1 deletion src/HelixCoreServerCtl/Commands/CheckpointCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public async Task<int> Execute()
var service = ServiceManager.Instance.FindServiceByName(ServiceName);
if (service is not null)
{
return await service.ExecAsync("-jc");
return await service.ExecAsync("-jc");
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/HelixCoreServerCtl/Commands/ExecCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class ExecCommand : IAsyncCommand
public string ServiceName { get; set; } = null!;

[Value(1, MetaValue = "<exec args>")]
public IEnumerable<string> More { get; set; } = null!;
public IEnumerable<string> More { get; set; } = null!;

[Option('f', "force", Default = false, HelpText = "Force exec to execute the command even if that p4d instance is currently running.")]
public bool Force { get; set; }
Expand Down
40 changes: 20 additions & 20 deletions src/HelixCoreServerCtl/Commands/NewCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ public async Task<int> Execute()

// TODO: Validate input

ServiceName ??= Prompt.Input<string>("Perforce Service name", validators: new[]
{
ServiceName ??= Prompt.Input<string>("Perforce Service name", validators: new[]
{
Validators.Required(),
Validators.RegularExpression(@"^[\w\-]+$", "Service name should only alphanumeric symbols"),
Validators.MaxLength(32),
PerforcePromptValidators.ServiceNameNotExists(),
});

var defaultRootDirectory = Path.Combine(AppConfig.Instance.DefaultServerRootDirectory!, ServiceName);
RootDirectory ??= Prompt.Input<string>("Perforce Server root (P4ROOT)", defaultRootDirectory, validators: new[]
RootDirectory ??= Prompt.Input<string>("Perforce Server root (P4ROOT)", defaultRootDirectory, validators: new[]
{
Validators.Required(),
PerforcePromptValidators.P4RootDirectoryNotConfigured(this),
Expand All @@ -96,14 +96,14 @@ public async Task<int> Execute()
PerforcePromptValidators.ValidP4Port(),
PerforcePromptValidators.P4PortNotUsed(),
});
SuperUserName ??= Prompt.Input<string>("Perforce super-user login", validators: new[]
SuperUserName ??= Prompt.Input<string>("Perforce super-user login", validators: new[]
{
Validators.Required(),
Validators.MinLength(3),
});
SuperUserPassword ??= Prompt.Password("Perforce super-user password", validators: new[]
{
Validators.Required(),
SuperUserPassword ??= Prompt.Password("Perforce super-user password", validators: new[]
{
Validators.Required(),
Validators.MinLength(8),
Validators.RegularExpression(@"(?=.*\d)(?=.*[a-z])(?=.*[A-Z])", "Password should be mixed case or contain non alphabetic characters"),
});
Expand All @@ -119,19 +119,19 @@ public async Task<int> Execute()
var includePath = appConfig.Includes?.FirstOrDefault();
if (includePath is not null)
{
defaultServiceFileName = Path.Combine(includePath, $"{ServiceName}.conf");
defaultServiceFileName = Path.Combine(includePath, $"{ServiceName}.conf");
if (System.IO.File.Exists(defaultServiceFileName))
{
int counter = 1;
do
{
defaultServiceFileName = Path.Combine(includePath, $"{ServiceName}{counter}.conf");
defaultServiceFileName = Path.Combine(includePath, $"{ServiceName}{counter}.conf");
counter++;
} while (System.IO.File.Exists(defaultServiceFileName) || counter < 99);
}
}

serviceFileName ??= Prompt.Input<string>("Service config path (where to save the .conf file)", defaultServiceFileName, validators: new[]
serviceFileName ??= Prompt.Input<string>("Service config path (where to save the .conf file)", defaultServiceFileName, validators: new[]
{
Validators.Required(),
PerforcePromptValidators.FileNotExists(),
Expand All @@ -152,7 +152,7 @@ public async Task<int> Execute()
Console.WriteLine($"Configuring p4d service '{ServiceName}' with the information you specified...");

FilePermissions oldUmaskPerms = Mono.Unix.Native.Syscall.umask(FilePermissions.S_IRWXG | FilePermissions.S_IRWXO);

Directory.CreateDirectory(RootDirectory);
Directory.CreateDirectory(Path.Combine(RootDirectory, "root"));
Directory.CreateDirectory(Path.Combine(RootDirectory, "journals"));
Expand Down Expand Up @@ -180,7 +180,7 @@ public async Task<int> Execute()
int r = Mono.Unix.Native.Syscall.chmod(SSLDirectory, Mono.Unix.Native.FilePermissions.S_IRWXU);
UnixMarshal.ThrowExceptionForLastErrorIf(r);
}
if (!System.IO.File.Exists(Path.Combine(SSLDirectory, "certificate.txt")) &&
if (!System.IO.File.Exists(Path.Combine(SSLDirectory, "certificate.txt")) &&
!System.IO.File.Exists(Path.Combine(SSLDirectory, "privatekey.txt")))
{
await RunP4D("-Gc").WaitForExitAsync();
Expand Down Expand Up @@ -236,7 +236,7 @@ public async Task<int> Execute()
con.UserName = SuperUserName;

P4.Options connectOptions = new P4.Options();
connectOptions["ProgramName"] ="p4dctl-ng";
connectOptions["ProgramName"] = "p4dctl-ng";
var programVersion = Assembly.GetExecutingAssembly().GetName().Version;
if (programVersion is not null)
{
Expand All @@ -246,7 +246,7 @@ public async Task<int> Execute()
if (!NoSSL.Value)
{
con.TrustAndConnect(connectOptions, "-y", null);
}
}
else
{
con.Connect(connectOptions);
Expand Down Expand Up @@ -303,7 +303,7 @@ public async Task<int> Execute()

Console.WriteLine("Enabling unload and spec depots");

var specDepot = new P4.Depot
var specDepot = new P4.Depot
{
Id = "spec",
Type = P4.DepotType.Spec,
Expand All @@ -314,7 +314,7 @@ public async Task<int> Execute()
specDepot = repository.CreateDepot(specDepot);
repository.AdminUpdateSpecDepot();

var unloadDepot = new P4.Depot
var unloadDepot = new P4.Depot
{
Id = "unload",
Type = P4.DepotType.Unload,
Expand Down Expand Up @@ -410,13 +410,13 @@ public async Task<int> Execute()

con.Disconnect();
}
#if !DEBUG
#if !DEBUG
catch (Exception e)
{
Console.Error.WriteLine($"Error when initializing the server: {e.Message}");
return 1;
}
#endif
#endif
finally
{
if (settingValues is not null)
Expand All @@ -440,7 +440,7 @@ public async Task<int> Execute()
return 0;
}

private Process RunP4D(string arguments, IDictionary<string, string?>? environment = null, bool silent = true)
private Process RunP4D(string arguments, IDictionary<string, string?>? environment = null, bool silent = true)
{
if (CaseSensitivity.HasValue)
{
Expand Down Expand Up @@ -538,7 +538,7 @@ private static class PerforcePromptValidators
return ValidationResult.Success;
}
foreach(var endPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
foreach (var endPoint in IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpListeners())
{
if (endPoint.Port == p4Port.PortNumber)
{
Expand Down
4 changes: 2 additions & 2 deletions src/HelixCoreServerCtl/Commands/RestartCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task<int> Execute()
else
{
logConfiguration.WriteTo.Console(
outputTemplate: "{Message:lj}{NewLine}{Exception}",
outputTemplate: "{Message:lj}{NewLine}{Exception}",
theme: ConsoleTheme.None,
standardErrorFromLevel: LogEventLevel.Error);
}
Expand All @@ -47,7 +47,7 @@ public async Task<int> Execute()
}
else
{
List<Service> serviceList = new List<Service>();
List<Service> serviceList = new List<Service>();
services = serviceList;
foreach (var serviceName in ServiceNames)
{
Expand Down
4 changes: 2 additions & 2 deletions src/HelixCoreServerCtl/Commands/StartCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task<int> Execute()
else
{
logConfiguration.WriteTo.Console(
outputTemplate: "{Message:lj}{NewLine}{Exception}",
outputTemplate: "{Message:lj}{NewLine}{Exception}",
theme: ConsoleTheme.None,
standardErrorFromLevel: LogEventLevel.Error);
}
Expand All @@ -44,7 +44,7 @@ public async Task<int> Execute()
}
else
{
List<Service> serviceList = new List<Service>();
List<Service> serviceList = new List<Service>();
services = serviceList;
foreach (var serviceName in ServiceNames)
{
Expand Down
4 changes: 2 additions & 2 deletions src/HelixCoreServerCtl/Commands/StatusCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public int Execute()
else
{
logConfiguration.WriteTo.Console(
outputTemplate: "{Message:lj}{NewLine}{Exception}",
outputTemplate: "{Message:lj}{NewLine}{Exception}",
theme: ConsoleTheme.None,
standardErrorFromLevel: LogEventLevel.Error);
}
Expand All @@ -43,7 +43,7 @@ public int Execute()
}
else
{
List<Service> serviceList = new List<Service>();
List<Service> serviceList = new List<Service>();
services = serviceList;
foreach (var serviceName in ServiceNames)
{
Expand Down
6 changes: 3 additions & 3 deletions src/HelixCoreServerCtl/Commands/StopCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal class StopCommand : IAsyncCommand
public bool Silent { get; set; }

private Logger? log;

public async Task<int> Execute()
{
var logConfiguration = new LoggerConfiguration();
Expand All @@ -30,7 +30,7 @@ public async Task<int> Execute()
else
{
logConfiguration.WriteTo.Console(
outputTemplate: "{Message:lj}{NewLine}{Exception}",
outputTemplate: "{Message:lj}{NewLine}{Exception}",
theme: ConsoleTheme.None,
standardErrorFromLevel: LogEventLevel.Error);
}
Expand All @@ -44,7 +44,7 @@ public async Task<int> Execute()
}
else
{
List<Service> serviceList = new List<Service>();
List<Service> serviceList = new List<Service>();
services = serviceList;
foreach (var serviceName in ServiceNames)
{
Expand Down
2 changes: 1 addition & 1 deletion src/HelixCoreServerCtl/Commands/UpgradeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public async Task<int> Execute()
}
else
{
List<Service> serviceList = new List<Service>();
List<Service> serviceList = new List<Service>();
services = serviceList;
foreach (var serviceName in ServiceNames)
{
Expand Down
2 changes: 1 addition & 1 deletion src/HelixCoreServerCtl/Interop/ProcessExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ static class ProcessExtensions
public static void Kill(this Process process, Signum signal)
{
int r = Syscall.kill(process.Id, signal);
UnixMarshal.ThrowExceptionForLastErrorIf(r);
UnixMarshal.ThrowExceptionForLastErrorIf(r);
}
}
4 changes: 2 additions & 2 deletions src/HelixCoreServerCtl/PerforceApi/P4Port.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static bool TryParse(string portStr, [NotNullWhen(true)] out P4Port? resu
result = null;
return false;
}

if (portNumber < 1025 || portNumber > 65535)
{
result = null;
Expand Down Expand Up @@ -102,7 +102,7 @@ public override string ToString()
}

builder.Append(PortNumber);

return builder.ToString();
}
}
29 changes: 15 additions & 14 deletions src/HelixCoreServerCtl/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
try
{
#endif
AppConfig.InitInstance();
AppConfig.Instance.Validate();
AppConfig.InitInstance();
AppConfig.Instance.Validate();

Type[] commands = new Type[]
{
Type[] commands = new Type[]
{
typeof(NewCommand),
typeof(StartCommand),
typeof(StopCommand),
Expand All @@ -19,18 +19,19 @@
typeof(CheckpointCommand),
typeof(ExecCommand),
typeof(UpgradeCommand),
};
};

var parser = new Parser(with => {
with.EnableDashDash = true;
with.HelpWriter = Console.Error;
});
var parser = new Parser(with =>
{
with.EnableDashDash = true;
with.HelpWriter = Console.Error;
});

return await parser.ParseArguments(args, commands)
.MapResult(
(ICommand command) => Task.FromResult(command.Execute()),
async (IAsyncCommand command) => await command.Execute(),
_ => Task.FromResult(1));
return await parser.ParseArguments(args, commands)
.MapResult(
(ICommand command) => Task.FromResult(command.Execute()),
async (IAsyncCommand command) => await command.Execute(),
_ => Task.FromResult(1));
#if !DEBUG
}
catch (Exception exception)
Expand Down
9 changes: 4 additions & 5 deletions src/HelixCoreServerCtl/Service.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

using System.Diagnostics;
using Mono.Unix.Native;

Expand All @@ -19,7 +18,7 @@ internal class Service
public int ProcessID { get; private set; } = -1;

private Process? _process;
public Process? Process
public Process? Process
{
get
{
Expand All @@ -29,21 +28,21 @@ public Process? Process
{
_process = Process.GetProcessById(ProcessID);
}
catch(ArgumentException)
catch (ArgumentException)
{
// Process with the specified Id is not running.
// Catch the exception but do nothing
}
}
return _process;
}
private set
private set
{
_process = value;
}
}

public bool IsRunning
public bool IsRunning
{
get
{
Expand Down
2 changes: 1 addition & 1 deletion src/HelixCoreServerCtl/Utils/TemporaryDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public TemporaryDirectory()
{
Directory.Delete(Path, true);
}

Directory.CreateDirectory(Path);
}

Expand Down

0 comments on commit 8c533ac

Please sign in to comment.