diff --git a/cardano-wallet.cabal b/cardano-wallet.cabal index 16a4cd2e886..7c18bea6703 100644 --- a/cardano-wallet.cabal +++ b/cardano-wallet.cabal @@ -45,6 +45,8 @@ executable cardano-wallet , text , text-class , warp + other-modules: + Paths_cardano_wallet hs-source-dirs: exe/wallet main-is: @@ -72,6 +74,8 @@ executable cardano-wallet-launcher , say , text , text-class + other-modules: + Paths_cardano_wallet hs-source-dirs: exe/launcher main-is: diff --git a/exe/launcher/Main.hs b/exe/launcher/Main.hs index 33e0a2e147a..914e0037cc1 100644 --- a/exe/launcher/Main.hs +++ b/exe/launcher/Main.hs @@ -6,7 +6,7 @@ module Main where import Prelude import Cardano.CLI - ( Port, help, parseArgWith, showVersion ) + ( Port, help, parseArgWith ) import Cardano.Launcher ( Command (Command) , ProcessHasExited (ProcessHasExited) @@ -22,8 +22,12 @@ import Control.Monad ( when ) import Data.Text.Class ( FromText (..), ToText (..) ) +import Data.Version + ( showVersion ) import Fmt ( blockListF, fmt ) +import Paths_cardano_wallet + ( version ) import Say ( sayErr ) import System.Console.Docopt @@ -39,7 +43,7 @@ import System.Console.Docopt import System.Environment ( getArgs ) import System.Exit - ( exitWith ) + ( exitSuccess, exitWith ) import qualified Data.Text as T @@ -72,7 +76,9 @@ main = do args <- parseArgsOrExit cli =<< getArgs when (args `isPresent` (longOption "help")) $ help cli when (args `isPresent` (shortOption 'h')) $ help cli - when (args `isPresent` (longOption "version")) showVersion + when (args `isPresent` (longOption "version")) $ do + putStrLn (showVersion version) + exitSuccess network <- args `parseArg` longOption "network" bridgePort <- args `parseArg` longOption "http-bridge-port" diff --git a/exe/wallet/Main.hs b/exe/wallet/Main.hs index d6494d57086..afd0b6066d4 100644 --- a/exe/wallet/Main.hs +++ b/exe/wallet/Main.hs @@ -34,7 +34,6 @@ import Cardano.CLI , parseArgWith , putErrLn , setUtf8Encoding - , showVersion ) import Cardano.Wallet ( newWalletLayer ) @@ -78,8 +77,12 @@ import Data.Text ( Text ) import Data.Text.Class ( FromText (..), ToText (..) ) +import Data.Version + ( showVersion ) import Network.HTTP.Client ( Manager, defaultManagerSettings, newManager ) +import Paths_cardano_wallet + ( version ) import Servant ( (:<|>) (..), (:>) ) import Servant.Client @@ -102,7 +105,7 @@ import System.Console.Docopt import System.Environment ( getArgs ) import System.Exit - ( exitFailure ) + ( exitFailure, exitSuccess ) import System.IO ( BufferMode (NoBuffering), hSetBuffering, stderr, stdout ) @@ -260,7 +263,9 @@ exec execServer manager args wId <- args `parseArg` argument "wallet-id" runClient Aeson.encodePretty $ listAddresses (ApiT wId) Nothing - | args `isPresent` longOption "version" = showVersion + | args `isPresent` longOption "version" = do + putStrLn (showVersion version) + exitSuccess | otherwise = exitWithUsage cli diff --git a/lib/cli/cardano-wallet-cli.cabal b/lib/cli/cardano-wallet-cli.cabal index 62668156dd7..0c50c306534 100644 --- a/lib/cli/cardano-wallet-cli.cabal +++ b/lib/cli/cardano-wallet-cli.cabal @@ -31,12 +31,9 @@ library -Werror build-depends: base - , bytestring , ansi-terminal , docopt - , file-embed , fmt - , regex-applicative , text , text-class hs-source-dirs: diff --git a/lib/cli/src/Cardano/CLI.hs b/lib/cli/src/Cardano/CLI.hs index c4e978d9683..18d6e53a237 100644 --- a/lib/cli/src/Cardano/CLI.hs +++ b/lib/cli/src/Cardano/CLI.hs @@ -4,7 +4,6 @@ {-# LANGUAGE KindSignatures #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE TemplateHaskell #-} -- | -- Copyright: © 2018-2019 IOHK @@ -34,20 +33,13 @@ module Cardano.CLI , hGetLine , getSensitiveLine , hGetSensitiveLine - - -- * Show version - , showVersion ) where import Prelude hiding ( getLine ) -import Control.Applicative - ( many ) import Control.Exception ( bracket ) -import Data.FileEmbed - ( embedFile ) import Data.Functor ( (<$) ) import qualified Data.List.NonEmpty as NE @@ -96,10 +88,7 @@ import System.IO , stdout , utf8 ) -import Text.Regex.Applicative - ( anySym, few, match, string, sym ) -import qualified Data.ByteString.Char8 as B8 import qualified Data.Text as T import qualified Data.Text.IO as TIO @@ -270,20 +259,6 @@ getSensitiveLine = hGetSensitiveLine (stdin, stderr) Internals -------------------------------------------------------------------------------} -showVersion :: IO () -showVersion = do - let cabal = B8.unpack $(embedFile "../../cardano-wallet.cabal") - let re = few anySym - *> string "version:" *> many (sym ' ') *> few anySym - <* sym '\n' <* many anySym - case match re cabal of - Nothing -> do - putErrLn "Couldn't find program version!" - exitFailure - Just version -> do - TIO.putStrLn $ T.pack version - exitSuccess - withBuffering :: Handle -> BufferMode -> IO a -> IO a withBuffering h buffering action = bracket aFirst aLast aBetween where diff --git a/lib/http-bridge/cardano-wallet-http-bridge.cabal b/lib/http-bridge/cardano-wallet-http-bridge.cabal index 28e233b4a3c..fc0be528c1d 100644 --- a/lib/http-bridge/cardano-wallet-http-bridge.cabal +++ b/lib/http-bridge/cardano-wallet-http-bridge.cabal @@ -179,6 +179,7 @@ test-suite integration Test.Integration.Scenario.CLI.Mnemonics Test.Integration.Scenario.CLI.Transactions Test.Integration.Scenario.CLI.Wallets + Paths_cardano_wallet_http_bridge benchmark restore default-language: diff --git a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs index 15b89fd27c4..4b03d3140ec 100644 --- a/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs +++ b/lib/http-bridge/test/integration/Test/Integration/Scenario/CLI/Mnemonics.hs @@ -11,8 +11,10 @@ import Control.Monad ( forM_ ) import Data.List ( length ) -import Data.Text - ( Text ) +import Data.Version + ( showVersion ) +import Paths_cardano_wallet_http_bridge + ( version ) import System.Command ( Exit (..), Stderr (..), Stdout (..) ) import System.Exit @@ -24,23 +26,20 @@ import Test.Hspec.Expectations.Lifted import Test.Integration.Framework.DSL ( cardanoWalletCLI, cardanoWalletLauncherCLI, generateMnemonicsViaCLI ) -import qualified Data.Text as T - -version :: Text -version = "2019.5.24" +import qualified Data.List as L spec :: SpecWith () spec = do it "CLI_VERSION - cardano-wallet shows version" $ do (Exit c, Stdout out) <- cardanoWalletCLI ["--version"] - let v = T.dropWhileEnd (== '\n') (T.pack out) - v `shouldBe` version + let v = L.dropWhileEnd (== '\n') out + v `shouldBe` (showVersion version) c `shouldBe` ExitSuccess it "CLI_VERSION - cardano-wallet-launcher shows version" $ do (Exit c, Stdout out) <- cardanoWalletLauncherCLI ["--version"] - let v = T.dropWhileEnd (== '\n') (T.pack out) - v `shouldBe` version + let v = L.dropWhileEnd (== '\n') out + v `shouldBe` (showVersion version) c `shouldBe` ExitSuccess it "CLI_HELP - cardano-wallet-launcher shows help on bad argument" $ do