@@ -13,9 +13,12 @@ import qualified Data.ByteString.Base16 as Base16
1313import qualified Data.ByteString.Lazy as LBS
1414import Data.Foldable (for_)
1515import Data.List
16+import Data.Maybe
1617import qualified Data.Text as T
1718import Data.Text.Encoding
1819import Data.Text.Encoding.Error (lenientDecode)
20+import Data.Time.Clock
21+import Data.Time.Format (formatTime, defaultTimeLocale)
1922import GHC.StaticPtr
2023import Options.Applicative
2124import Options.Applicative.Help.Pretty (text, (<$$>))
@@ -50,8 +53,8 @@ newtype ArgsConfig = ArgsConfig
5053 { _argsConfig_enableVmBuilderByDefault :: Bool
5154 }
5255
53−args :: ArgsConfig -> Parser Args
54−args cfg = Args <$> noHandoff <*> verbose <*> obCommand cfg
56+args :: ArgsConfig -> UTCTime -> Maybe FilePath -> Parser Args
57+args cfg time root = Args <$> noHandoff <*> verbose <*> obCommand cfg time root
5558
5659noHandoff :: Parser Bool
5760noHandoff = flag False True $ mconcat
@@ -67,8 +70,8 @@ verbose = flag False True $ mconcat
6770 , help "Be more verbose"
6871 ]
6972
70−argsInfo :: ArgsConfig -> ParserInfo Args
71−argsInfo cfg = info (args cfg <**> helper) $ mconcat
73+argsInfo :: ArgsConfig -> UTCTime -> Maybe FilePath -> ParserInfo Args
74+argsInfo cfg time root = info (args cfg time root <**> helper) $ mconcat
7275 [ fullDesc
7376 , progDesc "Manage Obelisk projects"
7477 ]
@@ -87,7 +90,7 @@ data ObCommand
8790 = ObCommand_Init InitSource Bool
8891 | ObCommand_Deploy DeployCommand
8992 | ObCommand_Run
90− | ObCommand_Profile (Maybe FilePath)
93+ | ObCommand_Profile FilePath
9194 | ObCommand_Thunk ThunkCommand
9295 | ObCommand_Repl
9396 | ObCommand_Watch
@@ -103,13 +106,13 @@ data ObInternal
103106 = ObInternal_ApplyPackages String String String [String]
104107 deriving Show
105108
106−obCommand :: ArgsConfig -> Parser ObCommand
107−obCommand cfg = hsubparser
109+obCommand :: ArgsConfig -> UTCTime -> Maybe FilePath -> Parser ObCommand
110+obCommand cfg time root = hsubparser
108111 (mconcat
109112 [ command "init" $ info (ObCommand_Init <$> initSource <*> initForce) $ progDesc "Initialize an Obelisk project"
110113 , command "deploy" $ info (ObCommand_Deploy <$> deployCommand cfg) $ progDesc "Prepare a deployment for an Obelisk project"
111114 , command "run" $ info (pure ObCommand_Run) $ progDesc "Run current project in development mode"
112− , command "profile" $ info (ObCommand_Profile <$> optional (strOption ( long "output" <> short 'o' <> metavar "BASEPATH" ))) $ progDesc "Run current project with profiling enabled"
115+ , command "profile" $ info (ObCommand_Profile <$> option auto (long "output" <> short 'o' <> help "Base output to use for profiling output. Suffixes are added to this based on the profiling type." <> showDefault <> value ((fromMaybe "" root) </> "profile" </> formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S" time) <> metavar "PATH")) $ progDesc "Run current project with profiling enabled"
113116 , command "thunk" $ info (ObCommand_Thunk <$> thunkCommand) $ progDesc "Manipulate thunk directories"
114117 , command "repl" $ info (pure ObCommand_Repl) $ progDesc "Open an interactive interpreter"
115118 , command "watch" $ info (pure ObCommand_Watch) $ progDesc "Watch current project for errors and warnings"
@@ -250,8 +253,8 @@ parserPrefs = defaultPrefs
250253 { prefShowHelpOnEmpty = True
251254 }
252255
253−parseCLIArgs :: ArgsConfig -> [String] -> IO Args
254−parseCLIArgs cfg = handleParseResult . execParserPure parserPrefs (argsInfo cfg)
256+parseCLIArgs :: ArgsConfig -> UTCTime -> Maybe FilePath -> [String] -> IO Args
257+parseCLIArgs cfg time root = handleParseResult . execParserPure parserPrefs (argsInfo cfg time root)
255258
256259-- | Create an Obelisk config for the current process.
257260mkObeliskConfig :: IO Obelisk
@@ -306,12 +309,15 @@ main' argsCfg = do
306309 , "logging-level=" <> show logLevel
307310 ]
308311
312+ time <- liftIO $ getCurrentTime
313+ root <- findProjectRoot "."
314+
309315 --TODO: We'd like to actually use the parser to determine whether to hand off,
310316 --but in the case where this implementation of 'ob' doesn't support all
311317 --arguments being passed along, this could fail. For now, we don't bother
312318 --with optparse-applicative until we've done the handoff.
313319 let go as = do
314− args' <- liftIO $ handleParseResult (execParserPure parserPrefs (argsInfo argsCfg) as)
320+ args' <- liftIO $ handleParseResult (execParserPure parserPrefs (argsInfo argsCfg time root) as)
315321 case _args_noHandOffPassed args' of
316322 False -> return ()
317323 True -> putLog Warning "--no-handoff should only be passed once and as the first argument; ignoring"