Skip to content

A peer-to-peer stack for code collaboration

Improved machine config option

Thomas Scholtesdca5e8f5ed58
diff --git a/README.md b/README.md
index 5d53a14..2ff68fe 100644
--- a/README.md
+++ b/README.md
@@ -55,7 +55,8 @@ The end-to-end test suite is run with `stack test :e2e`. It requires you to
start up an IPFS test network and the Raicle daemon.
docker-compose -f test/docker-compose.yaml up -d ipfs-test-network
- RAD_IPFS_API_URL=http://localhost:19301 stack exec -- radicle-daemon --filePrefix test
+ RAD_IPFS_API_URL=http://localhost:19301 stack exec -- \
+ radicle-daemon --machine-config /tmp/radicle-machines.json
If you use `docker-compose up` for the first time you will also need to
initialize the IPFS test network with
@@ -63,8 +64,8 @@ initialize the IPFS test network with
echo '{"radicle": true}' | \
docker-compose -f test/docker-compose.yaml exec -T ipfs-test-network ipfs dag put
-You can reset the test daemon’s state by removing the file
-`./local/share/radicle/testdaemon-follows`.
+You can reset the test daemon’s machine configuration by removing the file
+`/tmp/radicle-machines.json`.
### Troubleshooting
diff --git a/exe/Daemon.hs b/exe/Daemon.hs
index 3baccdc..a9a365d 100644
--- a/exe/Daemon.hs
+++ b/exe/Daemon.hs
@@ -39,41 +39,53 @@ logDaemonError (displayError -> (m, xs)) = logErr m xs
-- * Main
data Opts = Opts
- { port :: Int
- -- TODO(james): temporary, just for testing.
- , filePrefix :: Text
- , debug :: Bool
+ { port :: Int
+ , machineConfigFile :: FilePath
+ , debug :: Bool
}
-opts :: Parser Opts
-opts = Opts
- <$> option auto
+cliInfo :: IO (ParserInfo Opts)
+cliInfo = do
+ defaultMachineConfigFile <- Local.getRadicleFile "machines.json"
+ pure $
+ info (opts defaultMachineConfigFile <**> helper)
+ ( fullDesc
+ <> progDesc "Run the radicle daemon"
+ <> header "radicle-daemon"
+ )
+
+opts :: FilePath -> Parser Opts
+opts defaultMachineConfigFile = do
+ port <-
+ option auto
( long "port"
<> help "daemon port"
<> metavar "PORT"
<> showDefault
<> value 8909
)
- <*> strOption
- ( long "filePrefix"
- <> help "file prefix"
- <> metavar "PREFIX"
+ machineConfigFile <-
+ strOption
+ ( long "machine-config"
+ <> help "Where to store configuration for known machines"
+ <> metavar "FILE"
<> showDefault
- <> value ""
+ <> value defaultMachineConfigFile
)
- <*> switch
+ debug <-
+ switch
( long "debug"
<> help "enable debug logging"
<> showDefault
)
+ pure $ Opts{..}
-- We use 'Void' to enforce the use of 'exitFailure'
main :: IO Void
main = do
hSetBuffering stdout LineBuffering
- Opts{..} <- execParser allOpts
+ Opts{..} <- execParser =<< cliInfo
machineConfigFileLock <- newMVar ()
- machineConfigFile <- Local.getRadicleFile (toS filePrefix <> "daemon-follows")
machines <- CachedMachines <$> CMap.empty
let env = Env{ logLevel = if debug then Debug else Normal, ..}
machineConfig <- readMachineConfigIO machineConfigFileLock machineConfigFile
@@ -99,12 +111,6 @@ main = do
Right (Right ()) -> do
logErr "Server stopped (this should not happen)" []
exitFailure
- where
- allOpts = info (opts <**> helper)
- ( fullDesc
- <> progDesc "Run the radicle daemon"
- <> header "radicle-daemon"
- )
server :: Env -> Server Api.DaemonApi
server env = hoistServer Api.daemonApi nt daemonServer
diff --git a/package.yaml b/package.yaml
index 8f75559..5d2b5df 100644
--- a/package.yaml
+++ b/package.yaml
@@ -206,6 +206,7 @@ executables:
default-extensions:
- AutoDeriveTypeable
+- ApplicativeDo
- ConstraintKinds
- DataKinds
- DefaultSignatures