Skip to content

Commit c5f8b2e

Browse files
committed
style: format codebase with csharpier
1 parent 45b4dec commit c5f8b2e

87 files changed

Lines changed: 988 additions & 653 deletions

File tree

Some content is hidden

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

src/.idea/.idea.port/.idea/indexLayout.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.idea/.idea.port/.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.idea/.idea.src.dir/.idea/indexLayout.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/.idea/.idea.src.dir/.idea/projectSettingsUpdater.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Commands/Commit/CommitCliCommand.cs

Lines changed: 94 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -14,83 +14,108 @@ internal class CommitCliCommand(
1414
IGetDigestsByIdQuery getDigestsByIdQuery,
1515
IGetContainersQuery getContainersQuery,
1616
IStopAndRemoveContainerCommand stopAndRemoveContainerCommand,
17-
ListCliCommand listCliCommand)
18-
: AsyncCommand<CommitSettings>
17+
ListCliCommand listCliCommand
18+
) : AsyncCommand<CommitSettings>
1919
{
2020
public override async Task<int> ExecuteAsync(CommandContext context, CommitSettings settings)
2121
{
22-
var container = await GetContainerAsync(settings) ??
23-
throw new InvalidOperationException("No running container found");
22+
var container =
23+
await GetContainerAsync(settings)
24+
?? throw new InvalidOperationException("No running container found");
2425

25-
await Spinner.StartAsync("Committing container", async ctx =>
26-
{
27-
string newTag;
28-
string imageName;
29-
string tagPrefix;
30-
if (settings.Overwrite)
31-
{
32-
newTag = container.ImageTag ??
33-
throw new InvalidOperationException(
34-
"When using --overwrite, container must have an image tag");
35-
imageName = container.ImageIdentifier;
36-
tagPrefix = container.TagPrefix;
37-
}
38-
else
26+
await Spinner.StartAsync(
27+
"Committing container",
28+
async ctx =>
3929
{
40-
var tag = settings.Tag ?? $"{DateTime.Now:yyyyMMddhhmmss}";
41-
(imageName, tagPrefix, newTag) = await GetNewTagAsync(container, tag);
42-
}
43-
44-
45-
ctx.Status = $"Looking for existing container named '{container.ContainerName}'";
46-
var containerWithSameTag = await getContainersQuery
47-
.QueryByContainerIdentifierAndTagAsync(container.ContainerIdentifier, newTag)
48-
.ToListAsync();
49-
50-
ctx.Status = $"Creating image from running container '{container.ContainerName}'";
51-
newTag = await createImageFromContainerCommand.ExecuteAsync(container, imageName, tagPrefix, newTag);
52-
53-
ctx.Status = $"Removing containers named '{container.ContainerName}'";
54-
await Task.WhenAll(containerWithSameTag.Select(async container1 =>
55-
await stopAndRemoveContainerCommand.ExecuteAsync(container1.Id)));
56-
57-
if (settings.Overwrite)
58-
{
59-
if (newTag == null)
60-
throw new InvalidOperationException("newTag is null");
61-
62-
if (container.ImageTag == null)
63-
throw new InvalidOperationException(
64-
"Switch argument not supported when creating image from untagged container");
65-
66-
ctx.Status = "Launching new image";
67-
var id = await createContainerCommand.ExecuteAsync(container, tagPrefix, newTag);
68-
await runContainerCommand.ExecuteAsync(id);
69-
}
70-
else if (settings.Switch)
71-
{
72-
if (newTag == null)
73-
throw new InvalidOperationException("newTag is null");
74-
75-
if (container.ImageTag == null)
76-
throw new InvalidOperationException(
77-
"Switch argument not supported when creating image from untagged container");
78-
79-
ctx.Status = $"Stopping running container '{container.ContainerName}'";
80-
await stopContainerCommand.ExecuteAsync(container.Id);
81-
82-
ctx.Status = "Launching new image";
83-
var id = await createContainerCommand.ExecuteAsync(container, tagPrefix, newTag);
84-
await runContainerCommand.ExecuteAsync(id);
30+
string newTag;
31+
string imageName;
32+
string tagPrefix;
33+
if (settings.Overwrite)
34+
{
35+
newTag =
36+
container.ImageTag
37+
?? throw new InvalidOperationException(
38+
"When using --overwrite, container must have an image tag"
39+
);
40+
imageName = container.ImageIdentifier;
41+
tagPrefix = container.TagPrefix;
42+
}
43+
else
44+
{
45+
var tag = settings.Tag ?? $"{DateTime.Now:yyyyMMddhhmmss}";
46+
(imageName, tagPrefix, newTag) = await GetNewTagAsync(container, tag);
47+
}
48+
49+
ctx.Status = $"Looking for existing container named '{container.ContainerName}'";
50+
var containerWithSameTag = await getContainersQuery
51+
.QueryByContainerIdentifierAndTagAsync(container.ContainerIdentifier, newTag)
52+
.ToListAsync();
53+
54+
ctx.Status = $"Creating image from running container '{container.ContainerName}'";
55+
newTag = await createImageFromContainerCommand.ExecuteAsync(
56+
container,
57+
imageName,
58+
tagPrefix,
59+
newTag
60+
);
61+
62+
ctx.Status = $"Removing containers named '{container.ContainerName}'";
63+
await Task.WhenAll(
64+
containerWithSameTag.Select(async container1 =>
65+
await stopAndRemoveContainerCommand.ExecuteAsync(container1.Id)
66+
)
67+
);
68+
69+
if (settings.Overwrite)
70+
{
71+
if (newTag == null)
72+
throw new InvalidOperationException("newTag is null");
73+
74+
if (container.ImageTag == null)
75+
throw new InvalidOperationException(
76+
"Switch argument not supported when creating image from untagged container"
77+
);
78+
79+
ctx.Status = "Launching new image";
80+
var id = await createContainerCommand.ExecuteAsync(
81+
container,
82+
tagPrefix,
83+
newTag
84+
);
85+
await runContainerCommand.ExecuteAsync(id);
86+
}
87+
else if (settings.Switch)
88+
{
89+
if (newTag == null)
90+
throw new InvalidOperationException("newTag is null");
91+
92+
if (container.ImageTag == null)
93+
throw new InvalidOperationException(
94+
"Switch argument not supported when creating image from untagged container"
95+
);
96+
97+
ctx.Status = $"Stopping running container '{container.ContainerName}'";
98+
await stopContainerCommand.ExecuteAsync(container.Id);
99+
100+
ctx.Status = "Launching new image";
101+
var id = await createContainerCommand.ExecuteAsync(
102+
container,
103+
tagPrefix,
104+
newTag
105+
);
106+
await runContainerCommand.ExecuteAsync(id);
107+
}
85108
}
86-
});
109+
);
87110

88111
await listCliCommand.ExecuteAsync();
89112
return 0;
90113
}
91114

92-
private async Task<(string imageName, string tagPrefix, string newTag)> GetNewTagAsync(Container container,
93-
string tag)
115+
private async Task<(string imageName, string tagPrefix, string newTag)> GetNewTagAsync(
116+
Container container,
117+
string tag
118+
)
94119
{
95120
var image = await getImageQuery.QueryAsync(container.ImageIdentifier, container.ImageTag);
96121
string imageName;
@@ -101,7 +126,8 @@ await Task.WhenAll(containerWithSameTag.Select(async container1 =>
101126
var digest = digests?.SingleOrDefault();
102127
if (digest == null || !DigestHelper.TryGetImageNameAndId(digest, out var nameNameAndId))
103128
throw new InvalidOperationException(
104-
$"Unable to determine image name from running container '{container.ContainerName}'");
129+
$"Unable to determine image name from running container '{container.ContainerName}'"
130+
);
105131
imageName = nameNameAndId.imageName;
106132
}
107133
else
@@ -128,4 +154,4 @@ await Task.WhenAll(containerWithSameTag.Select(async container1 =>
128154
var identifier = containerNamePrompt.GetIdentifierOfContainerFromUser(containers, "commit");
129155
return containers.SingleOrDefault(c => c.ContainerName == identifier);
130156
}
131-
}
157+
}

src/Commands/Commit/CommitSettings.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ public class CommitSettings : CommandSettings, IContainerIdentifierSettings
77
[CommandArgument(0, "[ContainerIdentifier]")]
88
public string? ContainerIdentifier { get; set; }
99

10-
[CommandOption("-t|--tag")]
10+
[CommandOption("-t|--tag")]
1111
public string? Tag { get; set; }
1212

13-
[CommandOption("-s|--switch")]
13+
[CommandOption("-s|--switch")]
1414
public bool Switch { get; set; }
1515

16-
[CommandOption("-o|--overwrite")]
16+
[CommandOption("-o|--overwrite")]
1717
public bool Overwrite { get; set; }
18-
}
18+
}

src/Commands/Commit/CreateImageFromContainerCommand.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,35 @@
33

44
namespace port.Commands.Commit;
55

6-
internal class CreateImageFromContainerCommand(IDockerClient dockerClient) : ICreateImageFromContainerCommand
6+
internal class CreateImageFromContainerCommand(IDockerClient dockerClient)
7+
: ICreateImageFromContainerCommand
78
{
8-
public async Task<string> ExecuteAsync(Container container, string imageName, string tagPrefix, string newTag)
9+
public async Task<string> ExecuteAsync(
10+
Container container,
11+
string imageName,
12+
string tagPrefix,
13+
string newTag
14+
)
915
{
1016
var labels = new Dictionary<string, string>();
1117
var identifier = container.GetLabel(Constants.IdentifierLabel);
12-
if (identifier is not null) labels.Add(Constants.IdentifierLabel, identifier);
18+
if (identifier is not null)
19+
labels.Add(Constants.IdentifierLabel, identifier);
1320
var baseTag = container.GetLabel(Constants.BaseTagLabel);
14-
if (baseTag is not null) labels.Add(Constants.BaseTagLabel, baseTag);
21+
if (baseTag is not null)
22+
labels.Add(Constants.BaseTagLabel, baseTag);
1523
labels.Add(Constants.TagPrefix, tagPrefix);
16-
if (baseTag == newTag) throw new InvalidOperationException("Can not overwrite base tags");
17-
await dockerClient.Images.CommitContainerChangesAsync(new CommitContainerChangesParameters
18-
{
19-
ContainerID = container.Id,
20-
RepositoryName = imageName,
21-
Tag = newTag,
22-
Config = new Docker.DotNet.Models.Config
24+
if (baseTag == newTag)
25+
throw new InvalidOperationException("Can not overwrite base tags");
26+
await dockerClient.Images.CommitContainerChangesAsync(
27+
new CommitContainerChangesParameters
2328
{
24-
Labels = labels
29+
ContainerID = container.Id,
30+
RepositoryName = imageName,
31+
Tag = newTag,
32+
Config = new Docker.DotNet.Models.Config { Labels = labels },
2533
}
26-
});
34+
);
2735
return newTag;
2836
}
29-
}
37+
}

src/Commands/Commit/GetDigestsByIdQuery.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,10 @@ public GetDigestsByIdQuery(IDockerClient dockerClient)
1616
{
1717
var parameters = new ImagesListParameters
1818
{
19-
Filters = new Dictionary<string, IDictionary<string, bool>>()
19+
Filters = new Dictionary<string, IDictionary<string, bool>>(),
2020
};
2121
var imagesListResponses = await _dockerClient.Images.ListImagesAsync(parameters);
22-
var imagesListResponse = imagesListResponses
23-
.SingleOrDefault(e => e.ID == imageId);
22+
var imagesListResponse = imagesListResponses.SingleOrDefault(e => e.ID == imageId);
2423
return imagesListResponse?.RepoDigests;
2524
}
26-
}
25+
}

src/Commands/Commit/ICreateImageFromContainerCommand.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,10 @@ namespace port.Commands.Commit;
22

33
public interface ICreateImageFromContainerCommand
44
{
5-
Task<string> ExecuteAsync(Container container, string imageName, string tagPrefix, string newTag);
6-
}
5+
Task<string> ExecuteAsync(
6+
Container container,
7+
string imageName,
8+
string tagPrefix,
9+
string newTag
10+
);
11+
}

src/Commands/Commit/IGetDigestsByIdQuery.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ namespace port.Commands.Commit;
33
internal interface IGetDigestsByIdQuery
44
{
55
Task<IList<string>?> QueryAsync(string imageId);
6-
}
6+
}

0 commit comments

Comments
 (0)