2import TutorialD.Interpreter
4import ProjectM36.Client
5import ProjectM36.Server.ParseArgs
6import ProjectM36.Server
8import Options.Applicative
12import qualified Data.Text as T
14#if !defined(VERSION_project_m36)
15# warning Failed to discover proper version from cabal_macros.h
16# define VERSION_project_m36 "<unknown>"
19parseArgs :: Parser InterpreterConfig
20parseArgs = LocalInterpreterConfig <$> parsePersistenceStrategy <*> parseHeadName <*> parseTutDExec <*> many parseGhcPkgPath <*> parseCheckFS <|>
21 RemoteInterpreterConfig <$> parseNodeId <*> parseDatabaseName <*> parseHeadName <*> parseTutDExec <*> parseCheckFS
23parseHeadName :: Parser HeadName
24parseHeadName = option auto (long "head" <>
25 help "Start session at head name." <>
29parseNodeId :: Parser NodeId
30parseNodeId = createNodeId <$>
31 strOption (long "host" <>
33 help "Remote host name" <>
34 value "127.0.0.1") <*>
35 option auto (long "port" <>
38 value defaultServerPort)
40--just execute some tutd and exit
41parseTutDExec :: Parser (Maybe TutorialDExec)
42parseTutDExec = optional $ strOption (long "exec-tutd" <>
44 help "Execute TutorialD expression and exit"
47opts :: ParserInfo InterpreterConfig
48opts = info parseArgs idm
50connectionInfoForConfig :: InterpreterConfig -> ConnectionInfo
51connectionInfoForConfig (LocalInterpreterConfig pStrategy _ _ ghcPkgPaths _) = InProcessConnectionInfo pStrategy outputNotificationCallback ghcPkgPaths
52connectionInfoForConfig (RemoteInterpreterConfig remoteNodeId remoteDBName _ _ _) = RemoteProcessConnectionInfo remoteDBName remoteNodeId outputNotificationCallback
54headNameForConfig :: InterpreterConfig -> HeadName
55headNameForConfig (LocalInterpreterConfig _ headn _ _ _) = headn
56headNameForConfig (RemoteInterpreterConfig _ _ headn _ _) = headn
58execTutDForConfig :: InterpreterConfig -> Maybe String
59execTutDForConfig (LocalInterpreterConfig _ _ t _ _) = t
60execTutDForConfig (RemoteInterpreterConfig _ _ _ t _) = t
62checkFSForConfig :: InterpreterConfig -> Bool
63checkFSForConfig (LocalInterpreterConfig _ _ _ _ c) = c
64checkFSForConfig (RemoteInterpreterConfig _ _ _ _ c) = c
66persistenceStrategyForConfig :: InterpreterConfig -> Maybe PersistenceStrategy
67persistenceStrategyForConfig (LocalInterpreterConfig strat _ _ _ _) = Just strat
68persistenceStrategyForConfig RemoteInterpreterConfig{} = Nothing
70errDie :: String -> IO ()
71errDie err = hPutStrLn stderr err >> exitFailure
73#ifndef VERSION_project_m36
74#error VERSION_project_m36 is not defined
78 putStrLn $ "Project:M36 TutorialD Interpreter " ++ VERSION_project_m36
79 putStrLn "Type \":help\" for more information."
80 putStrLn "A full tutorial is available at:"
81 putStrLn "https://github.com/agentm/project-m36/blob/master/docs/tutd_tutorial.markdown"
85 interpreterConfig <- execParser opts
86 let connInfo = connectionInfoForConfig interpreterConfig
87 fscheck <- checkFSType (checkFSForConfig interpreterConfig) (fromMaybe NoPersistence (persistenceStrategyForConfig interpreterConfig))
89 errDie checkFSErrorMsg
91 dbconn <- connectProjectM36 connInfo
94 errDie ("Failed to create database connection: " ++ show err)
96 let connHeadName = headNameForConfig interpreterConfig
97 eSessionId <- createSessionAtHead conn connHeadName
99 Left err -> errDie ("Failed to create database session at \"" ++ show connHeadName ++ "\": " ++ show err)
101 case execTutDForConfig interpreterConfig of
104 _ <- reprLoop interpreterConfig sessionId conn
107 runTutorialD sessionId conn Nothing (T.pack tutdStr)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list