-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from kadena-io/rsoeldner/repl-args
Add pact executable arguments
- Loading branch information
Showing
2 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |