Last active
July 23, 2023 11:34
-
-
Save revathskumar/0aa72e462b0128c0401e781b36dbb657 to your computer and use it in GitHub Desktop.
gen test function reading from cli argumant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module TestMain exposing ( main ) | |
import Node | |
import Node.Program as Program exposing ( Program ) | |
import Stream exposing ( Stream ) | |
main : Program Model Msg | |
main = | |
Program.define | |
{ init = init | |
, update = | |
\msg model -> | |
{ model = model | |
, command = Cmd.none | |
} | |
, subscriptions = \_ -> Sub.none | |
} | |
type alias Model = | |
{ stdout : Stream | |
, stderr : Stream | |
} | |
type Msg | |
= Log | |
init : | |
Program.AppInitTask | |
{ model : Model | |
, command : Cmd Msg | |
} | |
init = | |
Program.await Node.initialize | |
<| (\nodeConfig -> | |
Program.startProgram | |
{ model = | |
{ stdout = nodeConfig.stdout | |
, stderr = nodeConfig.stderr | |
} | |
, command = | |
case nodeConfig.args of | |
[ _, _, input ] -> | |
case String.toInt input of | |
Nothing -> | |
Stream.sendLine nodeConfig.stderr <| | |
"Exactly one argument is required: input should be integer" | |
Just num -> | |
Stream.sendLine nodeConfig.stdout | |
-- <| Debug.toString (unsafeToDigit 15) | |
-- <| Debug.toString (Array.first []) | |
<| Debug.toString (String.fromInt num) | |
_ -> | |
Stream.sendLine nodeConfig.stderr <| | |
"Exactly one argument is required: the integer to convert" | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main exposing ( main ) | |
import Node | |
import Node.Program as Program exposing ( Program ) | |
import Stream exposing ( Stream ) | |
main : Program Model Msg | |
main = | |
Program.define | |
{ init = init | |
, update = | |
\msg model -> | |
{ model = model | |
, command = Cmd.none | |
} | |
, subscriptions = \_ -> Sub.none | |
} | |
type alias Model = | |
{ stdout : Stream | |
, stderr : Stream | |
} | |
type Msg | |
= Log | |
init : | |
Program.AppInitTask | |
{ model : Model | |
, command : Cmd Msg | |
} | |
init = | |
Program.await Node.initialize | |
<| (\nodeConfig -> | |
Program.startProgram | |
{ model = | |
{ stdout = nodeConfig.stdout | |
, stderr = nodeConfig.stderr | |
} | |
, command = | |
Stream.sendLine nodeConfig.stdout | |
-- <| Debug.toString (unsafeToDigit 15) | |
-- <| Debug.toString (Array.first []) | |
<| Debug.toString (strTail "ABC") | |
} | |
) | |
strTail : String -> Array Char | |
strTail str = | |
case Array.popFirst (String.toArray str) of | |
Nothing -> | |
[] | |
Just { first = head, rest } -> | |
if Array.isEmpty rest then | |
[] | |
else | |
rest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment