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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.