Skip to content

Commit 18940fb

Browse files
committed
support gren run --package
1 parent c190f74 commit 18940fb

File tree

3 files changed

+198
-93
lines changed

3 files changed

+198
-93
lines changed

src/Main.gren

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ type Msg
158158
| CompilerInstalled (Result FileSystem.Error Path)
159159
| CompilerInitialized { quiet : Bool, backendStreams : ChildProcess.StreamIO, encodedCommand : Bytes }
160160
| CompilerRan Int
161-
| CompiledForRun { path : String, exitCode : Int }
161+
| CompiledForRun { path : Path, exitCode : Int }
162162
| RunStarted Process.Id
163163
| RunExited Int
164164
| RedirectTerminalIO
@@ -270,13 +270,15 @@ update msg model =
270270
Terminal.Run.run
271271
{ cpPermission = model.cpPermission
272272
, fsPermission = model.fsPermission
273+
, pathToString = model.pathToString
273274
, path = path
274275
, onInit = RunStarted
275276
, onExit = RunExited
276277
}
277278
|> Task.onError
278279
(\error ->
279280
-- TODO: Terminal.Run.errorToString
281+
-- TODO: Why am I not seeing the write to stderr?
280282
Stream.Log.line model.stderr (Debug.toString error)
281283
|> Task.map (\_ -> Node.exitWithCode 1)
282284
)
@@ -485,14 +487,15 @@ parseUserArgs model compilerPath =
485487
)
486488
|> Task.executeCmd
487489

488-
CliParser.Run moduleName ->
490+
CliParser.Run opts ->
489491
Terminal.Run.make
490492
{ fsPermission = model.fsPermission
491493
, cpPermission = model.cpPermission
492494
, useColor = model.useColor
493495
, compilerPath = compilerPath
494496
, pathToString = model.pathToString
495-
, moduleName = moduleName
497+
, moduleName = opts.moduleName
498+
, package = opts.package
496499
, onBackendInitialized =
497500
(\{ backendStreams, encodedCommand } ->
498501
CompilerInitialized
@@ -504,7 +507,7 @@ parseUserArgs model compilerPath =
504507
, onCompiled =
505508
(\outputPath exitCode ->
506509
CompiledForRun
507-
{ path = model.pathToString outputPath
510+
{ path = outputPath
508511
, exitCode = exitCode
509512
}
510513
)

src/Terminal/Parser.gren

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Command
3030
| PackageBump
3131
| PackageDiff DiffArgs
3232
| Paths Paths.Options
33-
| Run ModuleName
33+
| Run RunOptions
3434

3535

3636
type alias InitFlags =
@@ -59,6 +59,12 @@ type alias DocsFlags =
5959
}
6060

6161

62+
type alias RunOptions =
63+
{ moduleName : ModuleName
64+
, package : Maybe PackageName
65+
}
66+
67+
6268
type DiffArgs
6369
= DiffLatest
6470
| DiffVersion SemanticVersion
@@ -243,7 +249,13 @@ parser =
243249
, arguments =
244250
CLI.Parser.oneArg moduleNameParser
245251
, flags =
246-
CLI.Parser.noFlags
252+
CLI.Parser.initFlags
253+
(\package ->
254+
{ package = package
255+
}
256+
)
257+
-- TODO: --package name (without equals) does not work. Is that expected?
258+
|> CLI.Parser.flag "package" PackageName.cliParser "Run a module in a particular package."
247259
, commonDescription =
248260
Nothing
249261
, summary =
@@ -259,11 +271,16 @@ parser =
259271
, PP.words
260272
"""
261273
This tries to compile a Gren file named src/Main.gren.
262-
The file must have a `main` function that returns a Node program.
274+
The file must have a `main` function that returns a Node or Browser program.
263275
"""
264276
]
265277
, builder =
266-
\arg _flags -> Run arg
278+
(\arg flags ->
279+
Run
280+
{ moduleName = arg
281+
, package = flags.package
282+
}
283+
)
267284
}
268285
|> CLI.Parser.withCommand
269286
{ word = "docs"

0 commit comments

Comments
 (0)