diff --git a/pact-core.cabal b/pact-core.cabal index 76e0a84ca..535f213db 100644 --- a/pact-core.cabal +++ b/pact-core.cabal @@ -239,12 +239,18 @@ executable gasmodel executable pact main-is: repl/Main.hs - build-depends: base, pact-core, pact-core:pact-core-lsp + build-depends: base + , pact-core + , pact-core:pact-core-lsp + , optparse-applicative + , text ghc-options: -Wall -threaded -rtsopts -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints ghc-prof-options: -fprof-auto -fprof-auto-calls default-language: Haskell2010 + other-modules: PackageInfo_pact_core + test-suite core-tests main-is: PactCoreTests.hs diff --git a/repl/Main.hs b/repl/Main.hs index deb3387d7..0e02dc604 100644 --- a/repl/Main.hs +++ b/repl/Main.hs @@ -1,12 +1,42 @@ {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} + module Main where import Pact.Core.Repl +import Pact.Core.Builtin import Pact.Core.LanguageServer -import System.Environment + +import qualified Options.Applicative as O +import Control.Applicative ((<|>)) + +import qualified PackageInfo_pact_core as PI +import Data.Version (showVersion) +import qualified Data.Text.IO as T +import Data.Foldable + +data ReplOpts + = OVersion + | OBuiltins + | OLanguageServer + +replOpts :: O.Parser (Maybe ReplOpts) +replOpts = O.optional $ + O.flag' OVersion (O.short 'v' <> O.long "version" <> O.help "Display version") + <|> O.flag' OBuiltins (O.short 'b' <> O.long "builtins" <> O.help "List builtins") + <|> O.flag' OLanguageServer (O.long "lsp" <> O.help "Start Language Server") + +argParser :: O.ParserInfo (Maybe ReplOpts) +argParser = O.info (O.helper <*> replOpts) + (O.fullDesc <> O.header "The Pact Smart Contract Language Interpreter") main :: IO () -main = getArgs >>= \case - ["--lsp"] -> startLSP - _ -> runRepl +main = O.execParser argParser >>= \case + Just OVersion -> printVersion + Just OBuiltins -> printBuiltins + Just OLanguageServer -> startLSP + Nothing -> runRepl + where + printVersion = putStrLn ("pact version " <> showVersion PI.version) + printBuiltins = traverse_ (\bi -> T.putStrLn $ "\"" <> bi <> "\"") replcoreBuiltinNames