在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):gregwebs/Shelly.hs开源软件地址(OpenSource Url):https://github.com/gregwebs/Shelly.hs开源编程语言(OpenSource Language):Haskell 58.8%开源软件介绍(OpenSource Introduction):ShellyShelly provides a single module for convenient systems programming in Haskell.
The focus of this library on convenience combined with good error messages should make shelly approachable for newer users of Haskell. More shelly packagesThe shelly-extra package has some additional functionality that requires additional dependencies, currently including a convenient concurrency/futures implementation. Examples
Blog PostsTestimonialsHelpAlternativesHaskell shell scripting libraries
HSH, HsShellScript and shh (unlike Shelly currently) implement very efficient mechanisms for piping/redirecting in the system. turtle, like Shelly offers folding as a way to efficiently deal with a stream. None of the alternatives to Shelly offer command tracing. For some this is an absolutely critical feature, particularly given that Haskell does not yet offer up stack traces. Haskell file-finding supplements
Shelly's finders load all files into memory. This is simpler to use if you control the filesystem structure and know the system is bounded in size. However, if the filesystem structure is unbounded it consumes unbounded memory. Shell commands with richer input/outputShelly does not change the nature of shell scripting (text in, text out). If you want something more revolutionary you might try these:
UsageShelly's main goal is ease of use. There should be a primitive for every shell operation you need so you can easily build abstractions, so there are many of the usual file and environment operations. There are 2 main entry points for running arbitrary commands: Fun Example: shows an infectious script: it uploads itself to a server and runs itself over I recommend using the boilerplate at the top of this example in your projects. This includes setting line buffering if you are dealing with text and not binary data. {-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ExtendedDefaultRules #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
import Shelly
import System.IO
import Data.Text as T
default (T.Text)
main :: IO ()
main = do
hSetBuffering stdout LineBuffering
shelly $ verbosely $ do
host <- run "uname" ["-n"]
if T.stripEnd host == "local-machine"
then do d <- cmd "date"
c <- escaping False $ cmd "git" "log -1 | head -1 | awk '{print $2}'"
appendfile "log/deploy.log" $ T.intercalate " - " [T.stripEnd d, c]
uploads "my-server:/remote/path/" ["deploy"]
sshPairs_ "my-server" [("cd", ["/remote/path"]), ("./deploy", [])]
else do
cmd "./script/angel"
-- same path on remote host
-- will create directories
uploads :: Text -> [Text] -> Sh ()
uploads remote locals = rsync $ ["--relative"] ++ locals ++ [remote]
rsync :: [Text] -> Sh ()
rsync args = run_ "rsync" $ ["--delete", "-avz", "--no-g"] ++ args Variadic arguments to cmdYes, as seen above you can write variadic functions in Haskell quite easily, you just can't compose them as easily.
I find -- easy signature, but only allows one argument
let cabal = cmd "cabal" :: Text -> Sh Text
-- more complex signature that allows partial application of cmd
let cabal = cmd "cabal" :: Shelly.ShellCmd result => result EscapingBy default, all commands are shell escaped.
If you want the shell to interpret special characters such as Using Text and FilePath togetherShelly's usage of
Manual conversion is done through Thread-safe working directory and relative pathsCommand Good error messagesHaskell's #1 weakness for IO code is a lack of stack traces.
Shelly gives you something different: detailed logging.
In most cases this should be more useful than a stack trace.
Shelly keeps a log of API usage and saves it to a If you make your own primitive functions that do not use the existing Shelly API, you can create a wrapper in the Sh monad that use |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论