A peer-to-peer stack for code collaboration
Rad command uses bindir to execute
Thomas Scholtes439323825bfb
diff --git a/bin/rad-ipfs-daemon b/bin/rad-daemon-ipfssimilarity index 100%rename from bin/rad-ipfs-daemonrename to bin/rad-daemon-ipfsdiff --git a/cloudbuild.yaml b/cloudbuild.yamlindex fe28fbe..10101c4 100644--- a/cloudbuild.yaml+++ b/cloudbuild.yaml@@ -171,6 +171,6 @@ steps:export RAD_IPFS_API_URL=http://ipfs-test-network:5001export RADPATH="$(pwd)/rad"- stack exec -- radicle-daemon &+ stack exec -- rad-daemon-radicle &stack test :e2ediff --git a/exe/Rad.hs b/exe/Rad.hsindex 012cb89..ee5584c 100644--- a/exe/Rad.hs+++ b/exe/Rad.hs@@ -6,11 +6,12 @@ module Radimport Protolude-import Data.List (isPrefixOf)+import Data.List (lookup, stripPrefix)import Data.String (String)import qualified Data.Text as Timport Data.Version (showVersion)import System.Directory+import System.FilePathimport qualified System.Posix.Process as Posiximport Paths_radicle (getBinDir, version)@@ -21,13 +22,13 @@ radPrefix = "rad-"runCommand :: [String] -> IO ()runCommand [] = do- bin <- getBinDir- cmds <- availableCommands [bin]+ cmds <- getSubCommands+ let availableCommands = sort $ map fst cmds <> builtinCommandsputStr @Text "usage: rad <command> [<args>]\n\n"- putStrLn @Text "Available rad commands:"- putStr $ T.unlines $ [" " <> T.pack c | c <- cmds]+ putStrLn @Text "Available commands:"+ putStr $ T.unlines $ [" " <> T.pack c | c <- availableCommands]runCommand ("version":_) =- putStrLn ("rad version " <> toS (showVersion version) :: Text)+ putStrLn ("radicle version " <> toS (showVersion version) :: Text)runCommand ("help":_) =runCommand []runCommand ("--help":_) =@@ -35,8 +36,8 @@ runCommand ("--help":_) =runCommand ("-h":_) =runCommand []runCommand (name:args) = do- result <- findExecutable (radPrefix <> name)- case result of+ cmds <- getSubCommands+ case lookup name cmds ofJust exe ->Posix.executeFile exe False args NothingNothing -> do@@ -50,18 +51,17 @@ builtinCommands :: [String]builtinCommands =["version", "help"]--- | Lists commands available for running.-availableCommands- :: [FilePath] -- ^ Directories to search- -> IO [String] -- ^ Available commands-availableCommands dirs =- concat <$> forM dirs (\dir -> do- result <- try $ do- xs <- listDirectory dir- pure $ [drop (length radPrefix) x | x <- xs, toS radPrefix `isPrefixOf` x]- pure $ case result of- Left (_ :: IOException) -> builtinCommands- Right xs -> xs ++ builtinCommands)+-- | Returns list of Radicle sub-command binaries. These are all the+-- executables in 'getBinDir' starting with @rad@.+--+-- The first item is the command name, the second the absolute location+-- of the executable.+getSubCommands :: IO [(String, FilePath)]+getSubCommands = do+ searchDir <- getBinDir+ files <- listDirectory searchDir+ let commands = mapMaybe (stripPrefix radPrefix) files+ pure [(command, searchDir </> radPrefix <> command) | command <- commands]main :: IO ()main = runCommand =<< getArgsdiff --git a/package.yaml b/package.yamlindex 5d2b5df..9bb3b9d 100644--- a/package.yaml+++ b/package.yaml@@ -119,8 +119,9 @@ executables:other-modules: [Paths_radicle]dependencies:- directory- - unix+ - filepath- text+ - unixghc-options: -main-is Rad -O3 -threadedradicle:@@ -134,7 +135,7 @@ executables:- optparse-applicativeghc-options: -main-is RadicleExe- radicle-daemon:+ rad-daemon-radicle:main: Daemon.hssource-dirs: exeother-modules: []