mirror of
				https://github.com/GayPizzaSpecifications/darwin-apk.git
				synced 2025-11-04 07:59:38 +00:00 
			
		
		
		
	Simple info/show command
This commit is contained in:
		@ -7,12 +7,18 @@ public struct ApkIndex: Sendable {
 | 
				
			|||||||
  public let packages: [ApkIndexPackage]
 | 
					  public let packages: [ApkIndexPackage]
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
extension ApkIndex {
 | 
					public extension ApkIndex {
 | 
				
			||||||
  func first(name: String) -> ApkIndexPackage? {
 | 
					  func first(name: String) -> ApkIndexPackage? {
 | 
				
			||||||
    self.packages.first {
 | 
					    self.packages.first {
 | 
				
			||||||
      $0.name == name
 | 
					      $0.name == name
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  func filter(name: String) -> [ApkIndexPackage] {
 | 
				
			||||||
 | 
					    self.packages.filter {
 | 
				
			||||||
 | 
					      $0.name == name
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public extension ApkIndex {
 | 
					public extension ApkIndex {
 | 
				
			||||||
 | 
				
			|||||||
@ -15,6 +15,7 @@ struct DarwinApkCLI: AsyncParsableCommand {
 | 
				
			|||||||
      DpkRemoveCommand.self,
 | 
					      DpkRemoveCommand.self,
 | 
				
			||||||
      DpkUpdateCommand.self,
 | 
					      DpkUpdateCommand.self,
 | 
				
			||||||
      DpkUpgradeCommand.self,
 | 
					      DpkUpgradeCommand.self,
 | 
				
			||||||
      DpkSearchCommand.self
 | 
					      DpkSearchCommand.self,
 | 
				
			||||||
 | 
					      DpkInfoCommand.self
 | 
				
			||||||
    ])
 | 
					    ])
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										33
									
								
								Sources/dpk-cli/Subcommands/DpkInfoCommand.swift
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								Sources/dpk-cli/Subcommands/DpkInfoCommand.swift
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,33 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * darwin-apk © 2024 Gay Pizza Specifications
 | 
				
			||||||
 | 
					 * SPDX-License-Identifier: Apache-2.0
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import ArgumentParser
 | 
				
			||||||
 | 
					import darwin_apk
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct DpkInfoCommand: AsyncParsableCommand {
 | 
				
			||||||
 | 
					  static let configuration = CommandConfiguration(
 | 
				
			||||||
 | 
					    commandName: "info",
 | 
				
			||||||
 | 
					    abstract: "Show information about a package",
 | 
				
			||||||
 | 
					    aliases: [ "S", "show" ])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  @Argument(help: "One or more package names to print information about.")
 | 
				
			||||||
 | 
					  var packages: [String]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  func run() async throws(ExitCode) {
 | 
				
			||||||
 | 
					    let localRepositories = try await ApkRepositoriesConfig()
 | 
				
			||||||
 | 
					    let index: ApkIndex
 | 
				
			||||||
 | 
					    do {
 | 
				
			||||||
 | 
					      index = try await ApkIndexReader.resolve(localRepositories, fetch: .local)
 | 
				
			||||||
 | 
					    } catch {
 | 
				
			||||||
 | 
					      eprint("Failed to build package index: \(error.localizedDescription)")
 | 
				
			||||||
 | 
					      throw .failure
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    self.packages.lazy
 | 
				
			||||||
 | 
					      .flatMap(index.filter)
 | 
				
			||||||
 | 
					      .map(\.description)
 | 
				
			||||||
 | 
					      .forEach { print($0) }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user