From b5e92eaa4239eb5fb394ac1f9941506eca2ae46a Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Wed, 4 Mar 2020 12:52:58 +0000 Subject: [PATCH] Add `version` command to `cardano-cli` --- cardano-config/src/Cardano/Config/Types.hs | 2 +- cardano-node/cardano-node.cabal | 7 +------ cardano-node/src/Cardano/CLI/Parsers.hs | 4 ++++ cardano-node/src/Cardano/CLI/Run.hs | 17 +++++++++++++++-- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/cardano-config/src/Cardano/Config/Types.hs b/cardano-config/src/Cardano/Config/Types.hs index 3a441c7eead..af7e864249c 100644 --- a/cardano-config/src/Cardano/Config/Types.hs +++ b/cardano-config/src/Cardano/Config/Types.hs @@ -272,7 +272,7 @@ instance FromJSON ViewMode where <> "Encountered: " <> (T.pack $ show invalid) -- | Detailed tracing options. Each option enables a tracer --- which verbosity to the log output. +-- which logs to the log output. data TraceOptions = TraceOptions { traceVerbosity :: !TracingVerbosity , traceBlockFetchClient :: !Bool diff --git a/cardano-node/cardano-node.cabal b/cardano-node/cardano-node.cabal index 0c769f9ee22..f974a190ef4 100644 --- a/cardano-node/cardano-node.cabal +++ b/cardano-node/cardano-node.cabal @@ -66,7 +66,6 @@ library , base >=4.12 && <5 , bytestring , deepseq - , strict-concurrency , canonical-json , cardano-binary , cardano-config @@ -81,7 +80,6 @@ library , contra-tracer , cborg >= 0.2.2 && < 0.3 , containers - , cryptonite , directory , filepath , formatting @@ -101,9 +99,9 @@ library , ouroboros-consensus-byron , ouroboros-consensus-cardano , ouroboros-network - , safe-exceptions , serialise , stm + , strict-concurrency , string-conv , template-haskell , text @@ -111,13 +109,10 @@ library , tracer-transformers , transformers , transformers-except - , tracer-transformers , typed-protocols , ouroboros-network-framework , unordered-containers , utf8-string - , vector - , yaml default-language: Haskell2010 default-extensions: NoImplicitPrelude diff --git a/cardano-node/src/Cardano/CLI/Parsers.hs b/cardano-node/src/Cardano/CLI/Parsers.hs index 1a5308aed3d..894a3fca979 100644 --- a/cardano-node/src/Cardano/CLI/Parsers.hs +++ b/cardano-node/src/Cardano/CLI/Parsers.hs @@ -394,6 +394,10 @@ parseMiscellaneous = subparser $ mconcat $ ValidateCBOR <$> parseCBORObject <*> parseFilePath "filepath" "Filepath of CBOR file." + , command' + "version" + "Show cardano-cli version" + $ pure DisplayVersion , command' "pretty-print-cbor" "Pretty print a CBOR file." diff --git a/cardano-node/src/Cardano/CLI/Run.hs b/cardano-node/src/Cardano/CLI/Run.hs index 297fd4e5c9a..fb337756140 100644 --- a/cardano-node/src/Cardano/CLI/Run.hs +++ b/cardano-node/src/Cardano/CLI/Run.hs @@ -33,7 +33,6 @@ module Cardano.CLI.Run ( ) where import Cardano.Prelude hiding (option, trace) - import Control.Monad.Trans.Except (ExceptT) import Control.Monad.Trans.Except.Extra (hoistEither, firstExceptT, left) import qualified Data.ByteString.Lazy as LB @@ -45,6 +44,7 @@ import Data.Version (showVersion) import qualified Formatting as F import Paths_cardano_node (version) import System.Directory (doesPathExist) +import System.Info (arch, compilerName, compilerVersion, os) import qualified Cardano.Chain.Common as Common import qualified Cardano.Chain.Delegation as Delegation @@ -174,7 +174,7 @@ data ClientCommand (NonEmpty UTxO.TxOut) -- ^ Genesis UTxO output Address. - --- Tx Generator Command ---------- + --- Tx Generator Command --- | GenerateTxs FilePath @@ -193,17 +193,30 @@ data ClientCommand (Maybe TxAdditionalSize) (Maybe ExplorerAPIEnpoint) [SigningKeyFile] + --- Misc Commands --- + + | DisplayVersion + | ValidateCBOR CBORObject -- ^ Type of the CBOR object FilePath + | PrettyPrintCBOR FilePath deriving Show runCommand :: ClientCommand -> ExceptT CliError IO () +runCommand DisplayVersion = do + liftIO . putTextLn + . toS + $ concat [ "cardano-cli " <> showVersion version + , " - " <> os <> "-" <> arch + , " - " <> compilerName <> "-" <> showVersion compilerVersion + ] + runCommand (Genesis outDir params ptcl) = do gen <- mkGenesis params dumpGenesis ptcl outDir `uncurry` gen