Skip to content

Commit 1e6e6d6

Browse files
authored
Add exec-args flag (#710)
1 parent f5c0fb6 commit 1e6e6d6

File tree

8 files changed

+60
-7
lines changed

8 files changed

+60
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
- Add `exec-args` as alias to `node-args`, to clarify that the args are
11+
forwarded to whichever backend is being targeted (go, js, etc), not
12+
exclusively node.
13+
1014
## [0.18.0] - 2020-12-07
1115

1216
Breaking changes (😱!!!):

CONTRIBUTING.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ and respect and do not harass or belittle others.
1212

1313
## What is the correct way to ask a question?
1414

15-
It's ok to ask questions by [opening an issue][spago-issues]!
15+
It's ok to ask questions by [opening an issue][spago-issues]!
1616
I ([@f-f][f-f]) am also on the [Functional Programming Slack][fp-slack], so you can also ask
1717
questions in the `#purescript` and `#purescript-beginners` channels.
1818

@@ -81,6 +81,9 @@ $ npm install -g bower
8181

8282
# This runs the tests which make use of the `spago` executable
8383
$ stack test
84+
85+
# A single test can be running by providing a pattern to the 'match' flag
86+
$ stack test --test-arguments='--match "/Spago/spago run/Spago should use exec-args"'
8487
```
8588

8689

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,12 @@ $ spago run --main ModulePath.To.Main
367367
# And pass arguments through to `purs compile`
368368
$ spago run --main ModulePath.To.Main --purs-args "--verbose-errors"
369369

370-
# Or pass arguments to node
370+
# Or pass arguments to the backend, in this case node
371+
$ spago run --exec-args "arg1 arg2"
372+
373+
# For versions 18 and below, use `node-args` instead:
371374
$ spago run --node-args "arg1 arg2"
375+
372376
```
373377

374378

src/Spago/CLI.hs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ parser = do
155155
docsFormat = CLI.optional $ CLI.opt Purs.parseDocsFormat "format" 'f' "Docs output format (markdown | html | etags | ctags)"
156156
jobsLimit = CLI.optional (CLI.optInt "jobs" 'j' "Limit the amount of jobs that can run concurrently")
157157
nodeArgs = many $ CLI.opt (Just . BackendArg) "node-args" 'a' "Argument to pass to node (run/test only)"
158+
backendArgs = many $ CLI.opt (Just . BackendArg) "exec-args" 'b' "Argument to pass to the backend (run/test only)"
158159
replPackageNames = many $ CLI.opt (Just . PackageName) "dependency" 'D' "Package name to add to the REPL as dependency"
159160
sourcePaths = many $ CLI.opt (Just . SourcePath) "path" 'p' "Source path to include"
160161

@@ -174,7 +175,6 @@ parser = do
174175
globalOptions = GlobalOptions <$> quiet <*> verbose <*> veryVerbose <*> (not <$> noColor) <*> usePsa
175176
<*> jobsLimit <*> configPath <*> cacheFlag
176177

177-
178178
initProject =
179179
( "init"
180180
, "Initialize a new sample project, or migrate a psc-package one"
@@ -193,16 +193,18 @@ parser = do
193193
, Repl <$> replPackageNames <*> sourcePaths <*> pursArgs <*> depsOnly
194194
)
195195

196+
execArgs = (++) <$> backendArgs <*> nodeArgs
197+
196198
test =
197199
( "test"
198200
, "Test the project with some module, default Test.Main"
199-
, Test <$> mainModule <*> buildOptions <*> nodeArgs
201+
, Test <$> mainModule <*> buildOptions <*> execArgs
200202
)
201203

202204
run =
203205
( "run"
204206
, "Runs the project with some module, default Main"
205-
, Run <$> mainModule <*> buildOptions <*> nodeArgs
207+
, Run <$> mainModule <*> buildOptions <*> execArgs
206208
)
207209

208210
bundleApp =

test/SpagoSpec.hs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ spec = around_ setup $ do
652652

653653
shell "psa --version" empty >>= \case
654654
ExitSuccess -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt"
655-
ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt"
655+
ExitFailure _ -> spago ["-v", "run"] >>= shouldBeSuccessOutput "run-output.txt"
656656

657657
it "Spago should be able to not use `psa`" $ do
658658

@@ -668,6 +668,30 @@ spec = around_ setup $ do
668668
spago ["build"] >>= shouldBeSuccess
669669
shellStrictWithErr "echo wut| spago run" empty >>= shouldBeSuccessOutput "spago-run-passthrough.txt"
670670

671+
it "Spago should use exec-args" $ do
672+
673+
spago ["init"] >>= shouldBeSuccess
674+
cp "../fixtures/spago-run-args.purs" "src/Main.purs"
675+
spago ["install", "node-process"] >>= shouldBeSuccess
676+
spago ["build"] >>= shouldBeSuccess
677+
spago ["run", "--exec-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt"
678+
679+
it "Spago should use node-args" $ do
680+
681+
spago ["init"] >>= shouldBeSuccess
682+
cp "../fixtures/spago-run-args.purs" "src/Main.purs"
683+
spago ["install", "node-process"] >>= shouldBeSuccess
684+
spago ["build"] >>= shouldBeSuccess
685+
spago ["run", "--node-args", "hello world"] >>= shouldBeSuccessOutput "run-args-output.txt"
686+
687+
it "Spago should prefer exec-args" $ do
688+
689+
spago ["init"] >>= shouldBeSuccess
690+
cp "../fixtures/spago-run-args.purs" "src/Main.purs"
691+
spago ["install", "node-process"] >>= shouldBeSuccess
692+
spago ["build"] >>= shouldBeSuccess
693+
spago ["run", "--exec-args", "hello world", "--node-args", "hallo welt"] >>= shouldBeSuccessOutput "run-args-combined-output.txt"
694+
671695
describe "spago bundle" $ do
672696

673697
it "Spago should fail but should point to the replacement command" $ do
@@ -689,7 +713,7 @@ spec = around_ setup $ do
689713
spago ["bundle-app", "--to", "bundle-app-src-map.js", "--source-maps"] >>= shouldBeSuccess
690714
checkFixture "bundle-app-src-map.js"
691715
checkFileExist "bundle-app-src-map.js.map"
692-
716+
693717
describe "spago make-module" $ do
694718

695719
it "Spago should fail but should point to the replacement command" $ do
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["hello","world","hallo","welt"]

test/fixtures/run-args-output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
["hello","world"]

test/fixtures/spago-run-args.purs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Main where
2+
3+
import Effect (Effect)
4+
import Effect.Console (log)
5+
import Node.Process (argv)
6+
import Prelude (Unit, ($), bind)
7+
import Data.Array (drop)
8+
import Data.Show (show)
9+
10+
main :: Effect Unit
11+
main = do
12+
args <- argv
13+
-- dropping the first two args, node path and script name, to make test stable
14+
log $ show $ drop 2 args

0 commit comments

Comments
 (0)