Skip to content

Commit 4bf3083

Browse files
committed
Cleans up image subcommand options.
- Part of #515. - Order options alphabetically. - Use consistent descriptions for platform, os, arch. - Add os/arch options to push. - Rename ImageRemove to ImageDelete since delete is the primary command and rm is the alias.
1 parent 6eaf51b commit 4bf3083

File tree

10 files changed

+67
-48
lines changed

10 files changed

+67
-48
lines changed

Sources/ContainerCommands/BuildCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ extension Application {
8080

8181
@Option(
8282
name: .long,
83-
help: "add the platform to the build",
83+
help: "add the platform to the build (format: os/arch[/variant], takes precedence over --os and --arch)",
8484
transform: { val in val.split(separator: ",").map { String($0) } }
8585
)
8686
var platform: [[String]] = [[]]

Sources/ContainerCommands/Image/ImageCommand.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ extension Application {
2424
commandName: "image",
2525
abstract: "Manage images",
2626
subcommands: [
27+
ImageDelete.self,
2728
ImageInspect.self,
2829
ImageList.self,
2930
ImageLoad.self,
3031
ImagePrune.self,
3132
ImagePull.self,
3233
ImagePush.self,
33-
ImageRemove.self,
3434
ImageSave.self,
3535
ImageTag.self,
3636
],

Sources/ContainerCommands/Image/ImageRemove.swift renamed to Sources/ContainerCommands/Image/ImageDelete.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ extension Application {
2727
@Flag(name: .shortAndLong, help: "Remove all images")
2828
var all: Bool = false
2929

30-
@Argument
31-
var images: [String] = []
32-
3330
@OptionGroup
3431
var global: Flags.Global
32+
33+
@Argument
34+
var images: [String] = []
3535
}
3636

37-
public struct RemoveImageImplementation {
37+
struct DeleteImageImplementation {
3838
static func validate(options: RemoveImageOptions) throws {
3939
if options.images.count == 0 && !options.all {
4040
throw ContainerizationError(.invalidArgument, message: "no image specified and --all not supplied")
@@ -81,9 +81,7 @@ extension Application {
8181
}
8282
}
8383

84-
public struct ImageRemove: AsyncParsableCommand {
85-
public init() {}
86-
84+
public struct ImageDelete: AsyncParsableCommand {
8785
@OptionGroup
8886
var options: RemoveImageOptions
8987

@@ -92,12 +90,14 @@ extension Application {
9290
abstract: "Remove one or more images",
9391
aliases: ["rm"])
9492

93+
public init() {}
94+
9595
public func validate() throws {
96-
try RemoveImageImplementation.validate(options: options)
96+
try DeleteImageImplementation.validate(options: options)
9797
}
9898

9999
public mutating func run() async throws {
100-
try await RemoveImageImplementation.removeImage(options: options)
100+
try await DeleteImageImplementation.removeImage(options: options)
101101
}
102102
}
103103
}

Sources/ContainerCommands/Image/ImageInspect.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import SwiftProtobuf
2222

2323
extension Application {
2424
public struct ImageInspect: AsyncParsableCommand {
25-
public init() {}
2625
public static let configuration = CommandConfiguration(
2726
commandName: "inspect",
2827
abstract: "Display information about one or more images")
@@ -33,6 +32,8 @@ extension Application {
3332
@Argument(help: "Images to inspect")
3433
var images: [String]
3534

35+
public init() {}
36+
3637
public func run() async throws {
3738
var printable = [any Codable]()
3839
let result = try await ClientImage.get(names: images)

Sources/ContainerCommands/Image/ImageList.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ import SwiftProtobuf
2424

2525
extension Application {
2626
public struct ListImageOptions: ParsableArguments {
27-
public init() {}
27+
@Option(name: .long, help: "Format of the output")
28+
var format: ListFormat = .table
29+
2830
@Flag(name: .shortAndLong, help: "Only output the image name")
2931
var quiet = false
3032

3133
@Flag(name: .shortAndLong, help: "Verbose output")
3234
var verbose = false
3335

34-
@Option(name: .long, help: "Format of the output")
35-
var format: ListFormat = .table
36-
3736
@OptionGroup
3837
var global: Flags.Global
38+
39+
public init() {}
3940
}
4041

4142
struct ListImageImplementation {

Sources/ContainerCommands/Image/ImageLoad.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ extension Application {
2929
abstract: "Load images from an OCI compatible tar archive"
3030
)
3131

32-
@OptionGroup
33-
var global: Flags.Global
34-
3532
@Option(
36-
name: .shortAndLong, help: "Path to the tar archive to load images from", completion: .file(),
33+
name: .shortAndLong, help: "Path to the image tar archive", completion: .file(),
3734
transform: { str in
3835
URL(fileURLWithPath: str, relativeTo: .currentDirectory()).absoluteURL.path(percentEncoded: false)
3936
})
4037
var input: String
4138

39+
@OptionGroup
40+
var global: Flags.Global
41+
4242
public func run() async throws {
4343
guard FileManager.default.fileExists(atPath: input) else {
4444
print("File does not exist \(input)")

Sources/ContainerCommands/Image/ImagePull.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ extension Application {
3838
var progressFlags: Flags.Progress
3939

4040
@Option(
41-
help: "Platform string in the form 'os/arch/variant'. Example 'linux/arm64/v8', 'linux/amd64'. This takes precedence over --os and --arch"
41+
name: .shortAndLong,
42+
help: "Limit the pull to the specified architecture"
4243
)
43-
var platform: String?
44+
var arch: String?
4445

4546
@Option(
46-
help: "Set OS if image can target multiple operating systems"
47+
help: "Limit the pull to the specified OS"
4748
)
4849
var os: String?
4950

5051
@Option(
51-
name: [.customLong("arch"), .customShort("a")],
52-
help: "Set arch if image can target multiple architectures"
52+
help: "Limit the pull to the specified platform (format: os/arch[/variant], takes precedence over --os and --arch)"
5353
)
54-
var arch: String?
54+
var platform: String?
5555

5656
@Argument var reference: String
5757

Sources/ContainerCommands/Image/ImagePush.swift

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,46 @@ import TerminalProgress
2222

2323
extension Application {
2424
public struct ImagePush: AsyncParsableCommand {
25-
public init() {}
2625
public static let configuration = CommandConfiguration(
2726
commandName: "push",
2827
abstract: "Push an image"
2928
)
3029

31-
@OptionGroup
32-
var global: Flags.Global
33-
3430
@OptionGroup
3531
var registry: Flags.Registry
3632

3733
@OptionGroup
3834
var progressFlags: Flags.Progress
3935

40-
@Option(help: "Platform string in the form 'os/arch/variant'. Example 'linux/arm64/v8', 'linux/amd64'") var platform: String?
36+
@Option(
37+
name: [.customLong("arch"), .customShort("a")],
38+
help: "Limit the push to the specified architecture"
39+
)
40+
var arch: String?
41+
42+
@Option(
43+
help: "Limit the push to the specified OS"
44+
)
45+
var os: String?
46+
47+
@Option(help: "Limit the push to the specified platform (format: os/arch[/variant], takes precedence over --os and --arch)")
48+
var platform: String?
49+
50+
@OptionGroup
51+
var global: Flags.Global
4152

4253
@Argument var reference: String
4354

55+
public init() {}
56+
4457
public func run() async throws {
4558
var p: Platform?
4659
if let platform {
4760
p = try Platform(from: platform)
61+
} else if let arch {
62+
p = try Platform(from: "\(os ?? "linux")/\(arch)")
63+
} else if let os {
64+
p = try Platform(from: "\(os)/\(arch ?? Arch.hostArchitecture().rawValue)")
4865
}
4966

5067
let scheme = try RequestScheme(registry.scheme)

Sources/ContainerCommands/Image/ImageSave.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@ extension Application {
3030
abstract: "Save an image as an OCI compatible tar archive"
3131
)
3232

33-
@OptionGroup
34-
var global: Flags.Global
35-
3633
@Option(
37-
help: "Platform string in the form 'os/arch/variant'. Example 'linux/arm64/v8', 'linux/amd64'. This takes precedence over --os and --arch"
34+
name: [.customLong("arch"), .customShort("a")],
35+
help: "Architecture for the saved image"
3836
)
39-
var platform: String?
37+
var arch: String?
4038

4139
@Option(
42-
help: "Set OS if image can target multiple operating systems"
40+
help: "OS for the saved image"
4341
)
4442
var os: String?
4543

4644
@Option(
47-
name: [.customLong("arch"), .customShort("a")],
48-
help: "Set arch if image can target multiple architectures"
49-
)
50-
var arch: String?
51-
52-
@Option(
53-
name: .shortAndLong, help: "Path to save the image tar archive", completion: .file(),
45+
name: .shortAndLong, help: "Pathname for the saved image", completion: .file(),
5446
transform: { str in
5547
URL(fileURLWithPath: str, relativeTo: .currentDirectory()).absoluteURL.path(percentEncoded: false)
5648
})
5749
var output: String
5850

51+
@Option(
52+
help: "Platform for the saved image (format: os/arch[/variant], takes precedence over --os and --arch)"
53+
)
54+
var platform: String?
55+
56+
@OptionGroup
57+
var global: Flags.Global
58+
5959
@Argument var references: [String]
6060

6161
public func run() async throws {

Sources/ContainerCommands/Image/ImageTag.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ extension Application {
2222
public init() {}
2323
public static let configuration = CommandConfiguration(
2424
commandName: "tag",
25-
abstract: "Tag an image")
25+
abstract: "Create a new reference for an existing image")
2626

27-
@Argument(help: "SOURCE_IMAGE[:TAG]")
27+
@Argument(help: "the existing image reference (format: image-name[:tag])")
2828
var source: String
2929

30-
@Argument(help: "TARGET_IMAGE[:TAG]")
30+
@Argument(help: "the new image reference")
3131
var target: String
3232

3333
@OptionGroup
@@ -37,7 +37,7 @@ extension Application {
3737
let existing = try await ClientImage.get(reference: source)
3838
let targetReference = try ClientImage.normalizeReference(target)
3939
try await existing.tag(new: targetReference)
40-
print("Image \(source) tagged as \(target)")
40+
print(target)
4141
}
4242
}
4343
}

0 commit comments

Comments
 (0)