Skip to content

Commit

Permalink
Merge pull request #65 from kadena-io/rsoeldner/repl-args
Browse files Browse the repository at this point in the history
Add pact executable arguments
  • Loading branch information
rsoeldner authored Jan 12, 2024
2 parents 2c8c2da + ddcfe14 commit e46d60c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
8 changes: 7 additions & 1 deletion pact-core.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 34 additions & 4 deletions repl/Main.hs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e46d60c

Please sign in to comment.