File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed
Sources/ContainerCommands/Image Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -38,3 +38,8 @@ extension Application {
3838 )
3939 }
4040}
41+
42+ /// `ImageCommand` errors.
43+ public enum ImageCommandError : Swift . Error {
44+ case invalidInput
45+ }
Original file line number Diff line number Diff line change @@ -34,14 +34,23 @@ extension Application {
3434 transform: { str in
3535 URL ( fileURLWithPath: str, relativeTo: . currentDirectory( ) ) . absoluteURL. path ( percentEncoded: false )
3636 } )
37- var input : String
37+ var input : String ?
3838
3939 @OptionGroup
4040 var global : Flags . Global
4141
4242 public func run( ) async throws {
43- guard FileManager . default. fileExists ( atPath: input) else {
44- print ( " File does not exist \( input) " )
43+ var filePath = " "
44+ if input == nil {
45+ print ( " Path to the image tar archive: " , terminator: " " )
46+ guard let userInput = readLine ( ) else {
47+ throw ImageCommandError . invalidInput
48+ }
49+ filePath = userInput
50+ }
51+
52+ guard FileManager . default. fileExists ( atPath: input ?? filePath) else {
53+ print ( " File does not exist \( input ?? filePath) " )
4554 Application . exit ( withError: ArgumentParser . ExitCode ( 1 ) )
4655 }
4756
@@ -57,7 +66,7 @@ extension Application {
5766 progress. start ( )
5867
5968 progress. set ( description: " Loading tar archive " )
60- let loaded = try await ClientImage . load ( from: input)
69+ let loaded = try await ClientImage . load ( from: input ?? filePath )
6170
6271 let taskManager = ProgressTaskCoordinator ( )
6372 let unpackTask = await taskManager. startTask ( )
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ extension Application {
4646 transform: { str in
4747 URL ( fileURLWithPath: str, relativeTo: . currentDirectory( ) ) . absoluteURL. path ( percentEncoded: false )
4848 } )
49- var output : String
49+ var output : String ?
5050
5151 @Option (
5252 help: " Platform for the saved image (format: os/arch[/variant], takes precedence over --os and --arch) "
@@ -59,6 +59,15 @@ extension Application {
5959 @Argument var references : [ String ]
6060
6161 public func run( ) async throws {
62+ var filePath = " "
63+ if output == nil {
64+ print ( " Pathname for the saved image: " , terminator: " " )
65+ guard let userInput = readLine ( ) else {
66+ throw ImageCommandError . invalidInput
67+ }
68+ filePath = userInput
69+ }
70+
6271 var p : Platform ?
6372 if let platform {
6473 p = try Platform ( from: platform)
@@ -90,7 +99,7 @@ extension Application {
9099 throw ContainerizationError ( . invalidArgument, message: " failed to save image(s) " )
91100
92101 }
93- try await ClientImage . save ( references: references, out: output, platform: p)
102+ try await ClientImage . save ( references: references, out: output ?? filePath , platform: p)
94103
95104 progress. finish ( )
96105 for reference in references {
You can’t perform that action at this time.
0 commit comments