on master help sign in
Get project root & current time for ob profile later on

Avoid showing it in the help documentation. Just do it when it is needed.

commit30183ed6aaa6cb8dc3f9b1b356bce32385e250da authorMatthew Bauer <mjbauer95@gmail.com> dateWed 12 Feb 2020, 13:33 (7 years ago) parent396cdad
1 file changed+19−15
lib/command/src/Obelisk/Command.hs+19−15
lib/command/src/Obelisk/Command.hs+19−15
@@ -53,8 +53,8 @@ newtype ArgsConfig = ArgsConfig
5353 { _argsConfig_enableVmBuilderByDefault :: Bool
5454 }
5555
56−args :: ArgsConfig -> UTCTime -> Maybe FilePath -> Parser Args
57−args cfg time root = Args <$> noHandoff <*> verbose <*> obCommand cfg time root
56+args :: ArgsConfig -> Parser Args
57+args cfg = Args <$> noHandoff <*> verbose <*> obCommand cfg
5858
5959noHandoff :: Parser Bool
6060noHandoff = flag False True $ mconcat
@@ -70,8 +70,8 @@ verbose = flag False True $ mconcat
7070 , help "Be more verbose"
7171 ]
7272
73−argsInfo :: ArgsConfig -> UTCTime -> Maybe FilePath -> ParserInfo Args
74−argsInfo cfg time root = info (args cfg time root <**> helper) $ mconcat
73+argsInfo :: ArgsConfig -> ParserInfo Args
74+argsInfo cfg = info (args cfg <**> helper) $ mconcat
7575 [ fullDesc
7676 , progDesc "Manage Obelisk projects"
7777 ]
@@ -90,7 +90,7 @@ data ObCommand
9090 = ObCommand_Init InitSource Bool
9191 | ObCommand_Deploy DeployCommand
9292 | ObCommand_Run
93− | ObCommand_Profile FilePath
93+ | ObCommand_Profile (Maybe FilePath)
9494 | ObCommand_Thunk ThunkCommand
9595 | ObCommand_Repl
9696 | ObCommand_Watch
@@ -106,13 +106,13 @@ data ObInternal
106106 = ObInternal_ApplyPackages String String String [String]
107107 deriving Show
108108
109−obCommand :: ArgsConfig -> UTCTime -> Maybe FilePath -> Parser ObCommand
110−obCommand cfg time root = hsubparser
109+obCommand :: ArgsConfig -> Parser ObCommand
110+obCommand cfg = hsubparser
111111 (mconcat
112112 [ command "init" $ info (ObCommand_Init <$> initSource <*> initForce) $ progDesc "Initialize an Obelisk project"
113113 , command "deploy" $ info (ObCommand_Deploy <$> deployCommand cfg) $ progDesc "Prepare a deployment for an Obelisk project"
114114 , command "run" $ info (pure ObCommand_Run) $ progDesc "Run current project in development mode"
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. Defaults to a timestamped path in the profile/ directory in the project's root." <> showDefault <> value ((fromMaybe "" root) </> "profile" </> formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S" time) <> metavar "PATH")) $ 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. Defaults to a timestamped path in the profile/ directory in the project's root." <> metavar "PATH")) $ progDesc "Run current project with profiling enabled"
116116 , command "thunk" $ info (ObCommand_Thunk <$> thunkCommand) $ progDesc "Manipulate thunk directories"
117117 , command "repl" $ info (pure ObCommand_Repl) $ progDesc "Open an interactive interpreter"
118118 , command "watch" $ info (pure ObCommand_Watch) $ progDesc "Watch current project for errors and warnings"
@@ -253,8 +253,8 @@ parserPrefs = defaultPrefs
253253 { prefShowHelpOnEmpty = True
254254 }
255255
256−parseCLIArgs :: ArgsConfig -> UTCTime -> Maybe FilePath -> [String] -> IO Args
257−parseCLIArgs cfg time root = handleParseResult . execParserPure parserPrefs (argsInfo cfg time root)
256+parseCLIArgs :: ArgsConfig -> [String] -> IO Args
257+parseCLIArgs cfg = handleParseResult . execParserPure parserPrefs (argsInfo cfg)
258258
259259-- | Create an Obelisk config for the current process.
260260mkObeliskConfig :: IO Obelisk
@@ -309,15 +309,12 @@ main' argsCfg = do
309309 , "logging-level=" <> show logLevel
310310 ]
311311
312− time <- liftIO $ getCurrentTime
313− root <- findProjectRoot "."
314−
315312 --TODO: We'd like to actually use the parser to determine whether to hand off,
316313 --but in the case where this implementation of 'ob' doesn't support all
317314 --arguments being passed along, this could fail. For now, we don't bother
318315 --with optparse-applicative until we've done the handoff.
319316 let go as = do
320− args' <- liftIO $ handleParseResult (execParserPure parserPrefs (argsInfo argsCfg time root) as)
317+ args' <- liftIO $ handleParseResult (execParserPure parserPrefs (argsInfo argsCfg) as)
321318 case _args_noHandOffPassed args' of
322319 False -> return ()
323320 True -> putLog Warning "--no-handoff should only be passed once and as the first argument; ignoring"
@@ -374,7 +371,14 @@ ob = \case
374371 DeployCommand_Update -> deployUpdate "."
375372 DeployCommand_Test (platform, extraArgs) -> deployMobile platform extraArgs
376373 ObCommand_Run -> run
377− ObCommand_Profile basePath -> profile basePath
374+ ObCommand_Profile mBasePath -> do
375+ basePath <- case mBasePath of
376+ Just path -> pure path
377+ Nothing -> do
378+ time <- liftIO $ getCurrentTime
379+ root <- findProjectRoot "."
380+ pure $ (fromMaybe "" root) </> "profile" </> formatTime defaultTimeLocale "%Y-%m-%dT%H:%M:%S" time
381+ profile basePath
378382 ObCommand_Thunk tc -> case tc of
379383 ThunkCommand_Update thunks config -> for_ thunks (updateThunkToLatest config)
380384 ThunkCommand_Unpack thunks -> for_ thunks unpackThunk