\$\begingroup\$
\$\endgroup\$
This script cleans up destination directory and copies file into it with new name. Can this intent be expressed more cleanly with shelly
?
main = shellyFailDir $ verbosely $ do
escaping False $ rm_rf $ webapps </> "*"
cp (m2repo
</> groupPath
</> artifact
</> version
</> (intercalate "-" [artifact, version] `append` ".war")
) $ webapps </> (finalName `append` ".war")
echo "done"
Alternate take:
main = shellyFailDir $ verbosely $ do
ls webapps >>= mapM_ rm_rf
cp (m2repo <> groupPath <> (mconcat . map fromText $ [artifact, version, artifactFileName]))
$ webapps <> fromText (finalName <> extension)
echo "done"
artifactFileName = intercalate "-" [artifact, version] <> extension
Having (types match only second version because they help pick correct Monoid
):
m2repo = ".m2/repository" :: FilePath
version = "1.0-SNAPSHOT" :: Text
webapps = "tomcat/webapps" :: FilePath
groupPath = "com/example" :: FilePath
artifact = "app" :: Text
finalName = artifact
extension = ".war" :: Text
200_success
146k22 gold badges190 silver badges478 bronze badges
1 Answer 1
\$\begingroup\$
\$\endgroup\$
I think your first version looks pretty slick. You could use a let-binding to do a little reordering and naming.
import Data.Monoid
main = shellyFailDir $ verbosely $ do
escaping False $ rm_rf $ webapps </> "*"
let sourceName = artifact <> "-" <> version <> ".war"
source = m2repo </> groupPath </> artifact </> version </> sourceName
destination = webapps </> finalName <> ".war"
cp source destination
echo "done"
answered Apr 21, 2015 at 19:45
Explore related questions
See similar questions with these tags.
lang-hs