1
\$\begingroup\$

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
asked Apr 21, 2015 at 15:30
\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

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
\$\endgroup\$

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.