feat(users/Profpatsch): init haskell arglib-netencode
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>
This commit is contained in:
parent
0fc1634255
commit
fdc5763f5b
3 changed files with 64 additions and 0 deletions
25
users/Profpatsch/arglib/ArglibNetencode.hs
Normal file
25
users/Profpatsch/arglib/ArglibNetencode.hs
Normal file
|
@ -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
|
17
users/Profpatsch/arglib/arglib-netencode.cabal
Normal file
17
users/Profpatsch/arglib/arglib-netencode.cabal
Normal file
|
@ -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
|
|
@ -36,6 +36,28 @@ let
|
||||||
t
|
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
|
in
|
||||||
|
|
Loading…
Reference in a new issue