Skip to content
Browse files

merge: be less hostile when try to merge ambiguous package name

Instead of 3 pages of unreadable mess we output names first and
then detailed package versions like that:

> $ dist/build/hackport/hackport merge Numbers
> Argument error: Ambiguous names: [PackageName "Numbers",PackageName "numbers"]
> ---
> PackageIdentifier {pkgName = PackageName "Numbers", pkgVersion = Version {versionBranch = [0,0], versionTags = []}}
> PackageIdentifier {pkgName = PackageName "Numbers", pkgVersion = Version {versionBranch = [0,1], versionTags = []}}
> PackageIdentifier {pkgName = PackageName "Numbers", pkgVersion = Version {versionBranch = [0,2], versionTags = []}}
> PackageIdentifier {pkgName = PackageName "Numbers", pkgVersion = Version {versionBranch = [0,2,1], versionTags = []}}
> ---
> PackageIdentifier {pkgName = PackageName "numbers", pkgVersion = Version {versionBranch = [2007,4,29], versionTags = []}}
> PackageIdentifier {pkgName = PackageName "numbers", pkgVersion = Version {versionBranch = [2007,9,23], versionTags = []}}

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
  • Loading branch information...
1 parent ed04a86 commit 67c546f099305169302b1d845a82242201118301 @trofi trofi committed Feb 27, 2012
Showing with 4 additions and 2 deletions.
  1. +4 −2 Merge.hs
View
6 Merge.hs
@@ -7,7 +7,7 @@ module Merge
import Control.Monad.Error
import Control.Exception
import Data.Maybe
-import Data.List
+import Data.List as L
import Distribution.Package
import Distribution.PackageDescription ( PackageDescription(..)
, FlagName(..)
@@ -123,7 +123,9 @@ merge verbosity repo _serverURI args overlayPath = do
case map snd (Index.searchByName index user_pname_str) of
[] -> throwEx (PackageNotFound user_pname_str)
[pkg] -> return pkg
- pkgs -> throwEx (ArgumentError ("Ambiguous name: " ++ unwords (map show pkgs)))
+ pkgs -> let names = map (pkgName . packageInfoId . L.head) pkgs
+ whole_list = map (L.intercalate "\n" . map (show . packageInfoId)) pkgs
+ in throwEx $ ArgumentError $ L.intercalate "\n---\n" $ ["Ambiguous names: " ++ show names] ++ whole_list
-- select a single package taking into account the user specified version
selectedPkg <-

0 comments on commit 67c546f

Please sign in to comment.
Something went wrong with that request. Please try again.