Add a --names-only flag for list --simple-output
authorIan Lynagh <igloo@earth.li>
Fri, 7 Sep 2007 18:19:44 +0000 (18:19 +0000)
committerIan Lynagh <igloo@earth.li>
Fri, 7 Sep 2007 18:19:44 +0000 (18:19 +0000)
We use this in the testsuite to find out which libraries we should run
the tests from.

utils/ghc-pkg/Main.hs

index 02370e2..8c106b0 100644 (file)
@@ -99,6 +99,7 @@ data Flag
   | FlagAutoGHCiLibs
   | FlagDefinedName String String
   | FlagSimpleOutput
+  | FlagNamesOnly
   deriving Eq
 
 flags :: [OptDescr Flag]
@@ -124,7 +125,9 @@ flags = [
   Option ['V'] ["version"] (NoArg FlagVersion)
         "output version information and exit",
   Option [] ["simple-output"] (NoArg FlagSimpleOutput)
-        "print output in easy-to-parse format for some commands"
+        "print output in easy-to-parse format for some commands",
+  Option [] ["names-only"] (NoArg FlagNamesOnly)
+        "only print package names, not versions; can only be used with list --simple-output"
   ]
  where
   toDefined str =
@@ -491,7 +494,9 @@ listPackages flags mPackageName = do
                    where doc = text (showPackageId (package p))
 
         show_simple db_stack = do
-          let pkgs = map showPackageId $ sortBy compPkgIdVer $
+          let showPkg = if FlagNamesOnly `elem` flags then pkgName
+                                                      else showPackageId
+              pkgs = map showPkg $ sortBy compPkgIdVer $
                           map package (concatMap snd db_stack)
           when (null pkgs) $ die "no matches"
           hPutStrLn stdout $ concat $ intersperse " " pkgs