File tree Expand file tree Collapse file tree 1 file changed +35
-1
lines changed
Sources/ContainerCommands/System/DNS Expand file tree Collapse file tree 1 file changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,12 @@ extension Application {
2626 aliases: [ " ls " ]
2727 )
2828
29+ @Option ( name: . long, help: " Format of the output " )
30+ var format : ListFormat = . table
31+
32+ @Flag ( name: . shortAndLong, help: " Only output the domain " )
33+ var quiet = false
34+
2935 @OptionGroup
3036 var global : Flags . Global
3137
@@ -34,7 +40,35 @@ extension Application {
3440 public func run( ) async throws {
3541 let resolver : HostDNSResolver = HostDNSResolver ( )
3642 let domains = resolver. listDomains ( )
37- print ( domains. joined ( separator: " \n " ) )
43+ try printDomains ( domains: domains, format: format)
44+ }
45+
46+ private func createHeader( ) -> [ [ String ] ] {
47+ [ [ " DOMAIN " ] ]
48+ }
49+
50+ func printDomains( domains: [ String ] , format: ListFormat ) throws {
51+ if format == . json {
52+ let data = try JSONEncoder ( ) . encode ( domains)
53+ print ( String ( data: data, encoding: . utf8) !)
54+
55+ return
56+ }
57+
58+ if self . quiet {
59+ domains. forEach { domain in
60+ print ( domain)
61+ }
62+ return
63+ }
64+
65+ var rows = createHeader ( )
66+ for domain in domains {
67+ rows. append ( [ domain] )
68+ }
69+
70+ let formatter = TableOutput ( rows: rows)
71+ print ( formatter. format ( ) )
3872 }
3973
4074 }
You can’t perform that action at this time.
0 commit comments