diff options
author | Profpatsch <mail@profpatsch.de> | 2022-08-20T00·34+0200 |
---|---|---|
committer | Profpatsch <mail@profpatsch.de> | 2022-08-22T12·47+0000 |
commit | fdc5763f5be6c1749cfec1b39e13dfcb414acfb0 (patch) | |
tree | 2a9a8e47f2e558a48d6e7d3ddb35f5cf6ae4cdb3 /users | |
parent | 0fc16342554d293438a62a96adec4f48dac09d54 (diff) |
feat(users/Profpatsch): init haskell arglib-netencode r/4448
Mirrors the rust exec-helpers Change-Id: I96f211d6545e228b8ae0c1dce4e60e6f6867690c Reviewed-on: https://cl.tvl.fyi/c/depot/+/6117 Tested-by: BuildkiteCI Reviewed-by: Profpatsch <mail@profpatsch.de>
Diffstat (limited to 'users')
-rw-r--r-- | users/Profpatsch/arglib/ArglibNetencode.hs | 25 | ||||
-rw-r--r-- | users/Profpatsch/arglib/arglib-netencode.cabal | 17 | ||||
-rw-r--r-- | users/Profpatsch/arglib/netencode.nix | 22 |
3 files changed, 64 insertions, 0 deletions
diff --git a/users/Profpatsch/arglib/ArglibNetencode.hs b/users/Profpatsch/arglib/ArglibNetencode.hs new file mode 100644 index 000000000000..e4609d26abf5 --- /dev/null +++ b/users/Profpatsch/arglib/ArglibNetencode.hs @@ -0,0 +1,25 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} + +module ArglibNetencode where + +import qualified Data.Attoparsec.ByteString as Atto +import Data.Maybe (fromMaybe) +import ExecHelpers +import MyPrelude +import Netencode +import qualified System.Environment as Env +import qualified System.Posix.Env.ByteString as ByteEnv + +arglibNetencode :: CurrentProgramName -> Maybe Text -> IO T +arglibNetencode progName mEnvvar = do + let envvar = mEnvvar & fromMaybe "ARGLIB_NETENCODE" & textToBytesUtf8 + ByteEnv.getEnv envvar >>= \case + Nothing -> dieUserError progName [fmt|could not read args, envvar {envvar} not set|] + Just bytes -> + case Atto.parseOnly (Netencode.netencodeParser <* Atto.endOfInput) bytes of + Left err -> dieEnvironmentProblem progName [fmt|arglib parsing error: {err}|] + Right t -> do + ByteEnv.unsetEnv envvar + pure t diff --git a/users/Profpatsch/arglib/arglib-netencode.cabal b/users/Profpatsch/arglib/arglib-netencode.cabal new file mode 100644 index 000000000000..461b42a93956 --- /dev/null +++ b/users/Profpatsch/arglib/arglib-netencode.cabal @@ -0,0 +1,17 @@ +cabal-version: 2.4 +name: arglib-netencode +version: 0.1.0.0 +author: Profpatsch +maintainer: mail@profpatsch.de + +library + exposed-modules: ArglibNetencode + + build-depends: + base ^>=4.15.1.0, + my-prelude, + netencode, + exec-helpers, + attoparsec, + unix + default-language: Haskell2010 diff --git a/users/Profpatsch/arglib/netencode.nix b/users/Profpatsch/arglib/netencode.nix index 3f1d121e5132..c628d800dedf 100644 --- a/users/Profpatsch/arglib/netencode.nix +++ b/users/Profpatsch/arglib/netencode.nix @@ -36,6 +36,28 @@ let t } ''; + + haskell = pkgs.haskellPackages.mkDerivation { + pname = "arglib-netencode"; + version = "0.1.0"; + + src = depot.users.Profpatsch.exactSource ./. [ + ./arglib-netencode.cabal + ./ArglibNetencode.hs + ]; + + libraryHaskellDepends = [ + depot.users.Profpatsch.my-prelude + depot.users.Profpatsch.netencode.netencode-hs + depot.users.Profpatsch.execline.exec-helpers-hs + ]; + + isLibrary = true; + license = lib.licenses.mit; + + + }; + }; in |