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." <>
26 metavar "GRAPH HEAD NAME" <>
30parseNodeId :: Parser NodeId
31parseNodeId = createNodeId <$>
32 strOption (long "host" <>
34 help "Remote host name" <>
36 value "127.0.0.1") <*>
37 option auto (long "port" <>
38 metavar "PORT NUMBER" <>
41 value defaultServerPort)
43--just execute some tutd and exit
44parseTutDExec :: Parser (Maybe TutorialDExec)
45parseTutDExec = optional $ strOption (long "exec-tutd" <>
47 metavar "TUTORIALD" <>
48 help "Execute TutorialD expression and exit"
51opts :: ParserInfo InterpreterConfig
52opts = info (parseArgs <**> helpOption) idm
54connectionInfoForConfig :: InterpreterConfig -> ConnectionInfo
55connectionInfoForConfig (LocalInterpreterConfig pStrategy _ _ ghcPkgPaths _) = InProcessConnectionInfo pStrategy outputNotificationCallback ghcPkgPaths
56connectionInfoForConfig (RemoteInterpreterConfig remoteNodeId remoteDBName _ _ _) = RemoteProcessConnectionInfo remoteDBName remoteNodeId outputNotificationCallback
58headNameForConfig :: InterpreterConfig -> HeadName
59headNameForConfig (LocalInterpreterConfig _ headn _ _ _) = headn
60headNameForConfig (RemoteInterpreterConfig _ _ headn _ _) = headn
62execTutDForConfig :: InterpreterConfig -> Maybe String
63execTutDForConfig (LocalInterpreterConfig _ _ t _ _) = t
64execTutDForConfig (RemoteInterpreterConfig _ _ _ t _) = t
66checkFSForConfig :: InterpreterConfig -> Bool
67checkFSForConfig (LocalInterpreterConfig _ _ _ _ c) = c
68checkFSForConfig (RemoteInterpreterConfig _ _ _ _ c) = c
70persistenceStrategyForConfig :: InterpreterConfig -> Maybe PersistenceStrategy
71persistenceStrategyForConfig (LocalInterpreterConfig strat _ _ _ _) = Just strat
72persistenceStrategyForConfig RemoteInterpreterConfig{} = Nothing
74errDie :: String -> IO ()
75errDie err = hPutStrLn stderr err >> exitFailure
77#ifndef VERSION_project_m36
78#error VERSION_project_m36 is not defined
82 putStrLn $ "Project:M36 TutorialD Interpreter " ++ VERSION_project_m36
83 putStrLn "Type \":help\" for more information."
84 putStrLn "A full tutorial is available at:"
85 putStrLn "https://github.com/agentm/project-m36/blob/master/docs/tutd_tutorial.markdown"
89 interpreterConfig <- execParser opts
90 let connInfo = connectionInfoForConfig interpreterConfig
91 fscheck <- checkFSType (checkFSForConfig interpreterConfig) (fromMaybe NoPersistence (persistenceStrategyForConfig interpreterConfig))
93 errDie checkFSErrorMsg
95 dbconn <- connectProjectM36 connInfo
98 errDie ("Failed to create database connection: " ++ show err)
100 let connHeadName = headNameForConfig interpreterConfig
101 eSessionId <- createSessionAtHead conn connHeadName
103 Left err -> errDie ("Failed to create database session at \"" ++ show connHeadName ++ "\": " ++ show err)
105 case execTutDForConfig interpreterConfig of
108 _ <- reprLoop interpreterConfig sessionId conn
111 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