I’ve reworked this. I’ve split all code related to outputting package information into 3 orthogonal concepts:
Mode: output information about the root(s) only vs. about the entire graph
Style: output verbosity brief or detailed
Format: output as JSON vs. text
This leads to a better separation of concerns. And it’s conceptually easier to understand. The 2 by 2 matrix of Mode vs. Style looks like this:
|
Root |
Graph |
Brief |
package and its targets — similar to current describe
|
package and its dependencies — similar to current show-dependencies
|
Detailed |
(almost) all details about the package — similar to current dump-package
|
(almost) all details about the package and its dependencies and their targets — not available in current swift package
|
With this approach the exact same information gets output for both JSON and text outputs — it’s just formatted differently. I’ve removed the flatlist
output format — you can still get to it through swift package completion-tool list-dependencies
, which makes for a better place for it to live at, IMHO.
Since 3 of the 4 squares in the above table match the current show-dependencies
, dump-package
, and describe
, I’d opt for mapping all of them into the same code and deprecating 2 of the existing 3. Alternatively, we could keep them as shorthands.
There’s no .dot
output. I’d be happy to add that back, and then I’d try to make it work for all 4 Style combinations listed above. It may be better to do that separately, though.
The above separation of concerns between Mode, Style, and Format is reflected in the code as well, which should make it easier to maintain and/or extend.
Below is the output for the example-package-dealer
project. Note how the JSON and text output match.
% swift dump-package --type json --style brief --mode root
Output
[
{
"modules" : [
{
"c99name" : "Dealer",
"moduleType" : "SwiftTarget",
"name" : "Dealer",
"path" : "\/Users\/deggert\/Projects\/example-package-dealer\/Sources\/Dealer",
"sources" : [
"main.swift"
],
"type" : "executable"
}
],
"name" : "dealer",
"path" : "\/Users\/deggert\/Projects\/example-package-dealer"
}
]
% swift dump-package --type json --style brief --mode graph
Output
[
{
"dependencies" : [
{
"dependencies" : [
{
"dependencies" : [
],
"name" : "FisherYates",
"path" : "\/Users\/deggert\/Projects\/example-package-dealer\/.build\/checkouts\/example-package-fisheryates-42cbd8bd",
"url" : "https:\/\/github.com\/apple\/example-package-fisheryates.git",
"version" : "2.0.5"
},
{
"dependencies" : [
],
"name" : "PlayingCard",
"path" : "\/Users\/deggert\/Projects\/example-package-dealer\/.build\/checkouts\/example-package-playingcard-bdaf050a",
"url" : "https:\/\/github.com\/apple\/example-package-playingcard.git",
"version" : "3.0.4"
}
],
"name" : "DeckOfPlayingCards",
"path" : "\/Users\/deggert\/Projects\/example-package-dealer\/.build\/checkouts\/example-package-deckofplayingcards-7c0a2312",
"url" : "https:\/\/github.com\/apple\/example-package-deckofplayingcards.git",
"version" : "3.0.4"
}
],
"name" : "dealer",
"path" : "\/Users\/deggert\/Projects\/example-package-dealer",
"url" : "\/Users\/deggert\/Projects\/example-package-dealer",
"version" : "unspecified"
}
]
% swift dump-package --type json --style detailed --mode root
Output
[
{
"dependencies" : [
{
"requirement" : {
"range" : [
{
"lowerBound" : "3.0.0",
"upperBound" : "4.0.0"
}
]
},
"url" : "https:\/\/github.com\/apple\/example-package-deckofplayingcards.git"
}
],
"manifestVersion" : "v4",
"name" : "dealer",
"products" : [
{
"name" : "Dealer",
"targets" : [
"Dealer"
],
"type" : {
"executable" : null
}
}
],
"targets" : [
{
"dependencies" : [
{
"byName" : [
"DeckOfPlayingCards"
]
}
],
"exclude" : [
],
"name" : "Dealer",
"type" : "regular"
}
]
}
]
% swift dump-package --type json --style detailed --mode graph
Output
{
"packages" : [
{
"dependencies" : [
{
"name" : "FisherYates",
"version" : "2.0.5"
},
{
"name" : "PlayingCard",
"version" : "3.0.4"
}
],
"manifestVersion" : "v4",
"name" : "DeckOfPlayingCards",
"products" : [
{
"name" : "DeckOfPlayingCards"
},
{
"linuxMainTarget" : "DeckOfPlayingCardsPackageTests",
"name" : "DeckOfPlayingCardsPackageTests"
}
],
"targets" : [
{
"c99name" : "DeckOfPlayingCards",
"dependencies" : [
{
"name" : "FisherYates",
"productName" : "FisherYates",
"type" : "product"
},
{
"name" : "PlayingCard",
"productName" : "PlayingCard",
"type" : "product"
}
],
"name" : "DeckOfPlayingCards",
"type" : "library"
},
{
"c99name" : "DeckOfPlayingCardsTests",
"dependencies" : [
{
"name" : "DeckOfPlayingCards",
"type" : "target"
}
],
"name" : "DeckOfPlayingCardsTests",
"type" : "test"
}
],
"version" : "3.0.4"
},
{
"dependencies" : [
],
"manifestVersion" : "v4",
"name" : "FisherYates",
"products" : [
{
"name" : "FisherYates"
},
{
"linuxMainTarget" : "FisherYatesPackageTests",
"name" : "FisherYatesPackageTests"
}
],
"targets" : [
{
"c99name" : "FisherYates",
"dependencies" : [
],
"name" : "FisherYates",
"type" : "library"
},
{
"c99name" : "FisherYatesTests",
"dependencies" : [
{
"name" : "FisherYates",
"type" : "target"
}
],
"name" : "FisherYatesTests",
"type" : "test"
}
],
"version" : "2.0.5"
},
{
"dependencies" : [
],
"manifestVersion" : "v4",
"name" : "PlayingCard",
"products" : [
{
"name" : "PlayingCard"
},
{
"linuxMainTarget" : "PlayingCardPackageTests",
"name" : "PlayingCardPackageTests"
}
],
"targets" : [
{
"c99name" : "PlayingCard",
"dependencies" : [
],
"name" : "PlayingCard",
"type" : "library"
},
{
"c99name" : "PlayingCardTests",
"dependencies" : [
{
"name" : "PlayingCard",
"type" : "target"
}
],
"name" : "PlayingCardTests",
"type" : "test"
}
],
"version" : "3.0.4"
},
{
"dependencies" : [
{
"name" : "DeckOfPlayingCards",
"version" : "3.0.4"
}
],
"manifestVersion" : "v4",
"name" : "dealer",
"products" : [
{
"executableModule" : "Dealer",
"name" : "Dealer"
}
],
"targets" : [
{
"c99name" : "Dealer",
"dependencies" : [
{
"name" : "DeckOfPlayingCards",
"productName" : "DeckOfPlayingCards",
"type" : "product"
}
],
"name" : "Dealer",
"type" : "executable"
}
]
}
],
"reachableProducts" : [
"Dealer",
"DeckOfPlayingCards",
"FisherYates",
"PlayingCard"
],
"reachableTargets" : [
"Dealer",
"DeckOfPlayingCards",
"FisherYates",
"PlayingCard"
],
"rootPackages" : [
"dealer"
]
}
% swift dump-package --type text --style brief --mode root
Output
Name: dealer
Path: /Users/deggert/Projects/example-package-dealer
Modules:
Name: Dealer
C99name: Dealer
Type: executable
Module type: SwiftTarget
Path: /Users/deggert/Projects/example-package-dealer/Sources/Dealer
Sources: main.swift
% swift dump-package --type text --style brief --mode graph
Output
Name: dealer
Url: /Users/deggert/Projects/example-package-dealer
Version: unspecified
Path: /Users/deggert/Projects/example-package-dealer
Dependencies:
Name: DeckOfPlayingCards
Url: https://github.com/apple/example-package-deckofplayingcards.git
Version: 3.0.4
Path: /Users/deggert/Projects/example-package-dealer/.build/checkouts/example-package-deckofplayingcards-7c0a2312
Dependencies:
Name: FisherYates
Url: https://github.com/apple/example-package-fisheryates.git
Version: 2.0.5
Path: /Users/deggert/Projects/example-package-dealer/.build/checkouts/example-package-fisheryates-42cbd8bd
Dependencies:
Name: PlayingCard
Url: https://github.com/apple/example-package-playingcard.git
Version: 3.0.4
Path: /Users/deggert/Projects/example-package-dealer/.build/checkouts/example-package-playingcard-bdaf050a
Dependencies:
% swift dump-package --type text --style detailed --mode root
Output
Name: dealer
Manifest version: v4
Dependencies:
Url: https://github.com/apple/example-package-deckofplayingcards.git
Requirement:
Range:
Lower bound: 3.0.0
Upper bound: 4.0.0
Products:
Name: Dealer
Targets: Dealer
Type:
Executable:
Targets:
Name: Dealer
Exclude:
Dependencies:
By name: DeckOfPlayingCards
Type: regular
% swift dump-package --type text --style detailed --mode graph
Output
Root packages: dealer
Packages:
Name: DeckOfPlayingCards
Version: 3.0.4
Manifest version: v4
Targets:
Name: DeckOfPlayingCards
C99name: DeckOfPlayingCards
Type: library
Dependencies:
Type: product
Name: FisherYates
Product name: FisherYates
Type: product
Name: PlayingCard
Product name: PlayingCard
Name: DeckOfPlayingCardsTests
C99name: DeckOfPlayingCardsTests
Type: test
Dependencies:
Type: target
Name: DeckOfPlayingCards
Products:
Name: DeckOfPlayingCards
Name: DeckOfPlayingCardsPackageTests
Linux main target: DeckOfPlayingCardsPackageTests
Dependencies:
Name: FisherYates
Version: 2.0.5
Name: PlayingCard
Version: 3.0.4
Name: FisherYates
Version: 2.0.5
Manifest version: v4
Targets:
Name: FisherYates
C99name: FisherYates
Type: library
Dependencies:
Name: FisherYatesTests
C99name: FisherYatesTests
Type: test
Dependencies:
Type: target
Name: FisherYates
Products:
Name: FisherYates
Name: FisherYatesPackageTests
Linux main target: FisherYatesPackageTests
Dependencies:
Name: PlayingCard
Version: 3.0.4
Manifest version: v4
Targets:
Name: PlayingCard
C99name: PlayingCard
Type: library
Dependencies:
Name: PlayingCardTests
C99name: PlayingCardTests
Type: test
Dependencies:
Type: target
Name: PlayingCard
Products:
Name: PlayingCard
Name: PlayingCardPackageTests
Linux main target: PlayingCardPackageTests
Dependencies:
Name: dealer
Manifest version: v4
Targets:
Name: Dealer
C99name: Dealer
Type: executable
Dependencies:
Type: product
Name: DeckOfPlayingCards
Product name: DeckOfPlayingCards
Products:
Name: Dealer
Executable module: Dealer
Dependencies:
Name: DeckOfPlayingCards
Version: 3.0.4
Reachable targets:
Dealer
DeckOfPlayingCards
FisherYates
PlayingCard
Reachable products:
Dealer
DeckOfPlayingCards
FisherYates
PlayingCard