Skip to content

Commit

Permalink
Fixing execArgs parsing in run command (#1188)
Browse files Browse the repository at this point in the history
Co-authored-by: Saravanan M <saravanan.m@juspay.in>
  • Loading branch information
imsaravana369 and SaravananM31 authored Mar 1, 2024
1 parent 94b7bab commit b4780ca
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 12 deletions.
16 changes: 7 additions & 9 deletions bin/src/Flags.purs
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,13 @@ pursArgs =
)

execArgs :: Parser (Maybe (Array String))
execArgs =
OT.optional
$ Array.fromFoldable
<$> O.many
( O.strArgument
( O.help "Arguments to pass to the running script"
<> O.metavar "ARGS"
)
)
execArgs = (\s -> if List.null s then Nothing else (Just $ Array.fromFoldable s))
<$> O.many
( O.strArgument
( O.help "Arguments to pass to the running script"
<> O.metavar "ARGS"
)
)

backendArgs :: Parser (List String)
backendArgs =
Expand Down
3 changes: 2 additions & 1 deletion test-fixtures/run-args-output.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
["hello world"]
hello
world
2 changes: 2 additions & 0 deletions test-fixtures/run-args-output2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bye
world
15 changes: 15 additions & 0 deletions test-fixtures/spago-args.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package:
name: aaa
dependencies:
- console
- effect
- prelude
run:
exec_args:
- "hello"
- "world"

workspace:
package_set:
registry: 29.3.0
extra_packages: {}
4 changes: 3 additions & 1 deletion test-fixtures/spago-run-args.purs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module Main where

import Prelude((<<<))
import Effect (Effect)
import Effect.Console (log)
import Node.Process (argv)
import Prelude (Unit, ($), bind)
import Data.Array (drop)
import Data.Show (show)
import Data.Traversable(traverse_)

main :: Effect Unit
main = do
args <- argv
-- dropping the first two args, node path and script name, to make test stable
log $ show $ drop 2 args
traverse_ log (drop 2 args)
18 changes: 17 additions & 1 deletion test/Spago/Run.purs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,20 @@ spec = Spec.around withTempDir do
cp (fixture "spago-run-args.purs") "src/Main.purs"
spago [ "install", "node-process", "arrays" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccess
spago [ "run", "--", "hello world" ] >>= shouldBeSuccessOutput (fixture "run-args-output.txt")
spago [ "run", "hello" , "world" ] >>= shouldBeSuccessOutput (fixture "run-args-output.txt")

Spec.it "args in spago.yaml should be used as the fallback args" \{ spago, fixture } -> do
spago [ "init" ] >>= shouldBeSuccess
cp (fixture "spago-run-args.purs") "src/Main.purs"
cp (fixture "spago-args.yaml") "spago.yaml"
spago [ "install", "node-process", "arrays" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccess
spago [ "run" ] >>= shouldBeSuccessOutput (fixture "run-args-output.txt")

Spec.it "explicit args has more priority than args in spago.yaml" \{ spago, fixture } -> do
spago [ "init" ] >>= shouldBeSuccess
cp (fixture "spago-args.yaml") "spago.yaml"
cp (fixture "spago-run-args.purs") "src/Main.purs"
spago [ "install", "node-process", "arrays" ] >>= shouldBeSuccess
spago [ "build" ] >>= shouldBeSuccess
spago [ "run", "bye" , "world" ] >>= shouldBeSuccessOutput (fixture "run-args-output2.txt")

0 comments on commit b4780ca

Please sign in to comment.