Skip to content

Instantly share code, notes, and snippets.

@revathskumar
Last active July 23, 2023 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save revathskumar/0aa72e462b0128c0401e781b36dbb657 to your computer and use it in GitHub Desktop.
Save revathskumar/0aa72e462b0128c0401e781b36dbb657 to your computer and use it in GitHub Desktop.
gen test function reading from cli argumant
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"
}
)
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