Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Sources/ContainerCommands/System/DNS/DNSCreate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,19 @@ import Foundation

extension Application {
public struct DNSCreate: AsyncParsableCommand {
public init() {}
public static let configuration = CommandConfiguration(
commandName: "create",
abstract: "Create a local DNS domain for containers (must run as an administrator)"
)

@Argument(help: "the local domain name")
@OptionGroup
var global: Flags.Global

@Argument(help: "The local domain name")
var domainName: String

public init() {}

public func run() async throws {
let resolver: HostDNSResolver = HostDNSResolver()
do {
Expand Down
8 changes: 6 additions & 2 deletions Sources/ContainerCommands/System/DNS/DNSDelete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ import Foundation

extension Application {
public struct DNSDelete: AsyncParsableCommand {
public init() {}
public static let configuration = CommandConfiguration(
commandName: "delete",
abstract: "Delete a local DNS domain (must run as an administrator)",
aliases: ["rm"]
)

@Argument(help: "the local domain name")
@OptionGroup
var global: Flags.Global

@Argument(help: "The local domain name")
var domainName: String

public init() {}

public func run() async throws {
let resolver = HostDNSResolver()
do {
Expand Down
6 changes: 5 additions & 1 deletion Sources/ContainerCommands/System/DNS/DNSList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ import Foundation

extension Application {
public struct DNSList: AsyncParsableCommand {
public init() {}
public static let configuration = CommandConfiguration(
commandName: "list",
abstract: "List local DNS domains",
aliases: ["ls"]
)

@OptionGroup
var global: Flags.Global

public init() {}

public func run() async throws {
let resolver: HostDNSResolver = HostDNSResolver()
let domains = resolver.listDomains()
Expand Down
28 changes: 16 additions & 12 deletions Sources/ContainerCommands/System/Kernel/KernelSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,30 @@ import TerminalProgress

extension Application {
public struct KernelSet: AsyncParsableCommand {
public init() {}
public static let configuration = CommandConfiguration(
commandName: "set",
abstract: "Set the default kernel"
)

@Option(name: .customLong("binary"), help: "Path to the binary to set as the default kernel. If used with --tar, this points to a location inside the tar")
var binaryPath: String? = nil
@Option(name: .long, help: "The architecture of the kernel binary (values: amd64, arm64)")
var arch: String = ContainerizationOCI.Platform.current.architecture.description

@Option(name: .customLong("tar"), help: "Filesystem path or remote URL to a tar ball that contains the kernel to use")
var tarPath: String? = nil
@Option(name: .customLong("binary"), help: "Path to the kernel file (or archive member, if used with --tar)")
var binaryPath: String? = nil

@Option(name: .customLong("arch"), help: "The architecture of the kernel binary. One of (amd64, arm64)")
var architecture: String = ContainerizationOCI.Platform.current.architecture.description
@Flag(name: .long, help: "Overwrites an existing kernel with the same name")
var force: Bool = false

@Flag(name: .customLong("recommended"), help: "Download and install the recommended kernel as the default. This flag ignores any other arguments")
@Flag(name: .long, help: "Download and install the recommended kernel as the default (takes precedence over all other flags)")
var recommended: Bool = false

@Flag(name: .long, help: "Force install of kernel. If a kernel exists with the same name, it will be overwritten.")
var force: Bool = false
@Option(name: .customLong("tar"), help: "Filesystem path or remote URL to a tar archive containing a kernel file")
var tarPath: String? = nil

@OptionGroup
var global: Flags.Global

public init() {}

public func run() async throws {
if recommended {
Expand Down Expand Up @@ -91,13 +95,13 @@ extension Application {
}

private func getSystemPlatform() throws -> SystemPlatform {
switch architecture {
switch arch {
case "arm64":
return .linuxArm
case "amd64":
return .linuxAmd
default:
throw ContainerizationError(.unsupported, message: "Unsupported architecture \(architecture)")
throw ContainerizationError(.unsupported, message: "Unsupported architecture \(arch)")
}
}

Expand Down
6 changes: 3 additions & 3 deletions Sources/ContainerCommands/System/Property/PropertyClear.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import Foundation

extension Application {
public struct PropertyClear: AsyncParsableCommand {
public init() {}

public static let configuration = CommandConfiguration(
commandName: "clear",
abstract: "Clear a property value"
Expand All @@ -32,9 +30,11 @@ extension Application {
@OptionGroup
var global: Flags.Global

@Argument(help: "the property ID")
@Argument(help: "The property ID")
var id: String

public init() {}

public func run() async throws {
guard let key = DefaultsStore.Keys(rawValue: id) else {
throw ContainerizationError(.invalidArgument, message: "invalid property ID: \(id)")
Expand Down
6 changes: 3 additions & 3 deletions Sources/ContainerCommands/System/Property/PropertyGet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import Foundation

extension Application {
public struct PropertyGet: AsyncParsableCommand {
public init() {}

public static let configuration = CommandConfiguration(
commandName: "get",
abstract: "Retrieve a property value"
Expand All @@ -32,9 +30,11 @@ extension Application {
@OptionGroup
var global: Flags.Global

@Argument(help: "the property ID")
@Argument(help: "The property ID")
var id: String

public init() {}

public func run() async throws {
let value = DefaultsStore.allValues()
.filter { id == $0.id }
Expand Down
10 changes: 5 additions & 5 deletions Sources/ContainerCommands/System/Property/PropertyList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ import Foundation

extension Application {
public struct PropertyList: AsyncParsableCommand {
public init() {}

public static let configuration = CommandConfiguration(
commandName: "list",
abstract: "List system properties",
aliases: ["ls"]
)

@Flag(name: .shortAndLong, help: "Only output the network name")
var quiet = false

@Option(name: .long, help: "Format of the output")
var format: ListFormat = .table

@Flag(name: .shortAndLong, help: "Only output the property ID")
var quiet = false

@OptionGroup
var global: Flags.Global

public init() {}

public func run() async throws {
let vals = DefaultsStore.allValues()
try printValues(vals, format: format)
Expand Down
8 changes: 4 additions & 4 deletions Sources/ContainerCommands/System/Property/PropertySet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import Foundation

extension Application {
public struct PropertySet: AsyncParsableCommand {
public init() {}

public static let configuration = CommandConfiguration(
commandName: "set",
abstract: "Set a property value"
Expand All @@ -34,12 +32,14 @@ extension Application {
@OptionGroup
var global: Flags.Global

@Argument(help: "the property ID")
@Argument(help: "The property ID")
var id: String

@Argument(help: "the property value")
@Argument(help: "The property value")
var value: String

public init() {}

public func run() async throws {
guard let key = DefaultsStore.Keys(rawValue: id) else {
throw ContainerizationError(.invalidArgument, message: "invalid property ID: \(id)")
Expand Down
12 changes: 6 additions & 6 deletions Sources/ContainerCommands/System/SystemLogs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ import OSLog

extension Application {
public struct SystemLogs: AsyncParsableCommand {
public init() {}

public static let subsystem = "com.apple.container"

public static let configuration = CommandConfiguration(
commandName: "logs",
abstract: "Fetch system logs for `container` services"
)

@OptionGroup
var global: Flags.Global
@Flag(name: .shortAndLong, help: "Follow log output")
var follow: Bool = false

@Option(
name: .long,
help: "Fetch logs starting from the specified time period (minus the current time); supported formats: m, h, d"
)
var last: String = "5m"

@Flag(name: .shortAndLong, help: "Follow log output")
var follow: Bool = false
@OptionGroup
var global: Flags.Global

public init() {}

public func run() async throws {
let process = Process()
Expand Down
16 changes: 9 additions & 7 deletions Sources/ContainerCommands/System/SystemStart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import TerminalProgress

extension Application {
public struct SystemStart: AsyncParsableCommand {
public init() {}
public static let configuration = CommandConfiguration(
commandName: "start",
abstract: "Start `container` services"
Expand All @@ -42,14 +41,17 @@ extension Application {
transform: { URL(filePath: $0) })
var installRoot = InstallRoot.defaultURL

@Flag(name: .long, help: "Enable debug logging for the runtime daemon.")
var debug = false

@Flag(
name: .long, inversion: .prefixedEnableDisable,
help: "Specify whether the default kernel should be installed or not. The default behavior is to prompt the user for a response.")
name: .long,
inversion: .prefixedEnableDisable,
help: "Specify whether the default kernel should be installed or not (default: prompt user)")
var kernelInstall: Bool?

@OptionGroup
var global: Flags.Global

public init() {}

public func run() async throws {
// Without the true path to the binary in the plist, `container-apiserver` won't launch properly.
// TODO: Use plugin loader for API server.
Expand All @@ -60,7 +62,7 @@ extension Application {

var args = [executableUrl.absolutePath()]

if debug {
if global.debug {
args.append("--debug")
}

Expand Down
8 changes: 6 additions & 2 deletions Sources/ContainerCommands/System/SystemStatus.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ import Logging

extension Application {
public struct SystemStatus: AsyncParsableCommand {
public init() {}
public static let configuration = CommandConfiguration(
commandName: "status",
abstract: "Show the status of `container` services"
)

@Option(name: .shortAndLong, help: "Launchd prefix for `container` services")
@Option(name: .shortAndLong, help: "Launchd prefix for services")
var prefix: String = "com.apple.container."

@OptionGroup
var global: Flags.Global

public init() {}

public func run() async throws {
let isRegistered = try ServiceManager.isRegistered(fullServiceLabel: "\(prefix)apiserver")
if !isRegistered {
Expand Down
9 changes: 6 additions & 3 deletions Sources/ContainerCommands/System/SystemStop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import Logging

extension Application {
public struct SystemStop: AsyncParsableCommand {
public init() {}

private static let stopTimeoutSeconds: Int32 = 5
private static let shutdownTimeoutSeconds: Int32 = 20

Expand All @@ -33,9 +31,14 @@ extension Application {
abstract: "Stop all `container` services"
)

@Option(name: .shortAndLong, help: "Launchd prefix for `container` services")
@Option(name: .shortAndLong, help: "Launchd prefix for services")
var prefix: String = "com.apple.container."

@OptionGroup
var global: Flags.Global

public init() {}

public func run() async throws {
let log = Logger(
label: "com.apple.container.cli",
Expand Down