Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions _/libs/base/System.idr
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@
then pure Nothing
else pure (Just (prim__getString env))

||| Retrieve an environment variable into Idriç-owned String storage.
||| Invalid environment names (those containing `=` or NUL) are rejected as
||| `Nothing`; this is distinct from a valid variable whose value is empty.
export
environment_value : String -> IO (Maybe String)

Check warning on line 158 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

ASCII arrows are an Idriç style canary. Re-check the design rather than applying a blind replacement; Idriç-facing notation uses real arrows such as → and ←.

Check warning on line 158 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

ASCII arrows are an Idriç style canary. Re-check the design rather than applying a blind replacement; Idriç-facing notation uses real arrows such as → and ←.
environment_value var =
if any invalidNameCharacter (unpack var)

Check warning on line 160 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.

Check warning on line 160 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.
then pure Nothing
else do
env <- primIO $ prim__getEnv var

Check warning on line 163 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

ASCII arrows are an Idriç style canary. Re-check the design rather than applying a blind replacement; Idriç-facing notation uses real arrows such as → and ←.

Check warning on line 163 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.

Check warning on line 163 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

ASCII arrows are an Idriç style canary. Re-check the design rather than applying a blind replacement; Idriç-facing notation uses real arrows such as → and ←.

Check warning on line 163 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.
if prim__nullPtr env /= 0

Check warning on line 164 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.

Check warning on line 164 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.
then pure Nothing
else pure $ Just $ fastPack $ unpack $ prim__getString env

Check warning on line 166 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.

Check warning on line 166 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.
where
invalidNameCharacter : Char -> Bool

Check warning on line 168 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

ASCII arrows are an Idriç style canary. Re-check the design rather than applying a blind replacement; Idriç-facing notation uses real arrows such as → and ←.

Check warning on line 168 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.

Check warning on line 168 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

ASCII arrows are an Idriç style canary. Re-check the design rather than applying a blind replacement; Idriç-facing notation uses real arrows such as → and ←.

Check warning on line 168 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.
invalidNameCharacter c = c == '=' || c == '\0'

Check warning on line 169 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.

Check warning on line 169 in _/libs/base/System.idr

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.

||| Retrieve all the key-value pairs of the environment variables, and return a
||| list containing them.
export
Expand Down
10 changes: 10 additions & 0 deletions _/tests/base/system_environment_value/InvalidNames.idric
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import System

showEnvironmentValue : Maybe String -> String

Check warning on line 3 in _/tests/base/system_environment_value/InvalidNames.idric

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.

Check warning on line 3 in _/tests/base/system_environment_value/InvalidNames.idric

View workflow job for this annotation

GitHub Actions / style

lowerCamelCase is an Idriç style canary. Do not merely rename the token: re-read the canonical Idriç STYLE.md and the surrounding design, then reconsider the declaration as a whole.
showEnvironmentValue Nothing = "missing"
showEnvironmentValue (Just value) = value

main : IO ()
main = do
putStrLn $ showEnvironmentValue !(environment_value "INVALID=NAME")
putStrLn $ showEnvironmentValue !(environment_value (pack ['N', '\0', 'X']))
9 changes: 9 additions & 0 deletions _/tests/base/system_environment_value/Test.idric
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import System

showEnvironmentValue : Maybe String -> String
showEnvironmentValue Nothing = "missing"
showEnvironmentValue (Just "") = "empty"
showEnvironmentValue (Just value) = value

main : IO ()
main = putStrLn $ showEnvironmentValue !(environment_value "IDRIC_ENV_TEST")
5 changes: 5 additions & 0 deletions _/tests/base/system_environment_value/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
hello
empty
missing
missing
missing
9 changes: 9 additions & 0 deletions _/tests/base/system_environment_value/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
. ../../testutils.sh

idris2 --cg chez -o test Test.idric
IDRIC_ENV_TEST=hello ./build/exec/test
IDRIC_ENV_TEST= ./build/exec/test
env -u IDRIC_ENV_TEST ./build/exec/test

idris2 --cg chez -o invalid-names InvalidNames.idric
./build/exec/invalid-names
Loading