A peer-to-peer stack for code collaboration
Cleanup usage of file argument in CLI
Thomas Scholtes3dfe69031cfd
diff --git a/exe/RadicleExe.hs b/exe/RadicleExe.hsindex 47aa7ba..9242a8b 100644--- a/exe/RadicleExe.hs+++ b/exe/RadicleExe.hs@@ -11,7 +11,7 @@ import Network.HTTP.Client (defaultManagerSettings, newManager)import qualified Network.HTTP.Client as HttpClientimport Options.Applicativeimport Prelude (String)-import Protolude hiding (TypeError, option)+import Protolude hiding (TypeError, option, sourceFile)import Radicleimport Servant.Clientimport System.Console.Haskeline (InputT)@@ -23,19 +23,16 @@ import qualified Radicle.Internal.PrimFns as PrimFnsmain :: IO ()main = doopts' <- execParser allOpts- cfgFile <- case configFile opts' of- Nothing -> getConfigFile- Just cfg -> pure cfg- cfgSrc <- do- exists <- doesFileExist cfgFile+ src <- do+ exists <- doesFileExist (sourceFile opts')if exists- then readFile cfgFile- else die $ "Could not find file: " <> toS cfgFile+ then readFile (sourceFile opts')+ else die $ "Could not find file: " <> toS (sourceFile opts')hist <- case histFile opts' ofNothing -> getHistoryFileJust h -> pure hmgr <- newManager defaultManagerSettings- repl (Just hist) (toS cfgFile) cfgSrc (bindings mgr)+ repl (Just hist) (toS $ sourceFile opts') src (bindings mgr)whereallOpts = info (opts <**> helper)( fullDesc@@ -54,20 +51,15 @@ radDesc-- * CLI Optsdata Opts = Opts- { configFile :: Maybe FilePath+ { sourceFile :: FilePath, histFile :: Maybe FilePath}opts :: Parser Optsopts = Opts- <$> argument (optional str)+ <$> strArgument( metavar "FILE"- <> help- ( "File to interpret."- <> "Defaults to $DIR/radicle/config.rad "- <> "where $DIR is $XDG_CONFIG_HOME (%APPDATA% on Windows "- <> "if that is set, or else ~/.config."- )+ <> help "File to interpret.")<*> optional (strOption( long "histfile"diff --git a/src/Radicle.hs b/src/Radicle.hsindex 303e5d7..4527e17 100644--- a/src/Radicle.hs+++ b/src/Radicle.hs@@ -82,7 +82,6 @@ module Radicle, ReplM-- * CLI- , getConfigFile, getHistoryFile-- * Helpersdiff --git a/src/Radicle/Internal/CLI.hs b/src/Radicle/Internal/CLI.hsindex d6da688..81387c0 100644--- a/src/Radicle/Internal/CLI.hs+++ b/src/Radicle/Internal/CLI.hs@@ -1,6 +1,5 @@module Radicle.Internal.CLI- ( getConfigFile- , getHistoryFile+ ( getHistoryFile)where@@ -9,14 +8,6 @@ import System.Directory(XdgDirectory(..), createDirectoryIfMissing, getXdgDirectory)import System.FilePath (takeDirectory)--- | Location of the radicle file to interpret.--- Usually @~/.local/config/radicle/config.rad@.------ See 'getXdgDirectory' XdgConfig' for how @~/.local/share@ is--- determined.-getConfigFile :: IO FilePath-getConfigFile = getXdgDirectory XdgConfig "radicle/config.rad"--- | Location of the radicle history, usually-- @~/.local/share/radicle/history@.--