Skip to content

Commit a04a920

Browse files
committed
Special-case format command to delegate directly to elm-format
As suggested in PR review, the format command now bypasses Lamdera's normal CLI processing and delegates directly to elm-format's mainIO. This ensures perfect compatibility with all elm-format features and reduces code duplication. Changes: - Intercept "format" command early in Terminal.hs - Add minimal FormatDirect module that calls elm-format - Remove 244-line Format.hs implementation - Keep stub command for help display consistency
1 parent 76cdecd commit a04a920

File tree

5 files changed

+44
-259
lines changed

5 files changed

+44
-259
lines changed

elm.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Executable lamdera
237237
-- CLI Experimental
238238
Lamdera.CLI.Annotate
239239
Lamdera.CLI.Interpreter
240-
Lamdera.CLI.Format
240+
Lamdera.CLI.FormatDirect
241241

242242
Lamdera.AppConfig
243243
Lamdera.Checks

extra/Lamdera/CLI.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import qualified Lamdera.CLI.Reset
1616
import qualified Lamdera.CLI.Update
1717
import qualified Lamdera.CLI.Annotate
1818
import qualified Lamdera.CLI.Interpreter
19-
import qualified Lamdera.CLI.Format
2019

2120

2221
live :: Terminal.Command
@@ -195,10 +194,23 @@ eval =
195194

196195

197196
-- FORMAT
197+
-- @LAMDERA This is a stub - the actual format command is intercepted early in Terminal.hs
198+
-- and delegates directly to elm-format's CLI for perfect compatibility
198199

199200

200201
format :: Terminal.Command
201-
format = Lamdera.CLI.Format.command
202+
format =
203+
let
204+
summary =
205+
"Format Elm source files."
206+
207+
details =
208+
"The `format` command is handled directly by elm-format for perfect compatibility."
209+
210+
example =
211+
reflow "See elm-format documentation at <https://github.com/avh4/elm-format>"
212+
in
213+
Terminal.Command "format" (Common summary) details example noArgs noFlags (\_ _ -> return ())
202214

203215

204216
-- HELPERS

extra/Lamdera/CLI/Format.hs

Lines changed: 0 additions & 244 deletions
This file was deleted.

extra/Lamdera/CLI/FormatDirect.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
module Lamdera.CLI.FormatDirect
2+
( run
3+
) where
4+
5+
import qualified ElmFormat.Cli
6+
7+
-- | Run elm-format directly with the provided arguments
8+
-- This bypasses Lamdera's normal CLI processing to delegate
9+
-- directly to elm-format's own argument handling
10+
run :: [String] -> IO ()
11+
run args = ElmFormat.Cli.mainIO args

terminal/impl/Terminal.hs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import qualified Terminal.Error as Error
3131

3232

3333
import qualified Lamdera.Version
34+
import qualified Lamdera.CLI.FormatDirect -- @LAMDERA
3435
import qualified Sanity
3536

3637
-- COMMAND
@@ -86,21 +87,26 @@ app intro outro commands =
8687
Exit.exitSuccess
8788

8889
command : chunks ->
89-
do case List.find (\cmd -> toName cmd == command) commands of
90-
Nothing ->
91-
Error.exitWithUnknown command (map toName commands)
90+
-- @LAMDERA Special case for format command to delegate directly to elm-format
91+
if command == "format" then
92+
do -- Import will be added at the top of the file
93+
Lamdera.CLI.FormatDirect.run chunks
94+
else
95+
do case List.find (\cmd -> toName cmd == command) commands of
96+
Nothing ->
97+
Error.exitWithUnknown command (map toName commands)
9298

93-
Just (Command _ _ details example args_ flags_ callback) ->
94-
if elem "--help" chunks then
95-
Error.exitWithHelp (Just command) details example args_ flags_
99+
Just (Command _ _ details example args_ flags_ callback) ->
100+
if elem "--help" chunks then
101+
Error.exitWithHelp (Just command) details example args_ flags_
96102

97-
else
98-
case snd $ Chomp.chomp Nothing chunks args_ flags_ of
99-
Right (argsValue, flagsValue) ->
100-
callback argsValue flagsValue
103+
else
104+
case snd $ Chomp.chomp Nothing chunks args_ flags_ of
105+
Right (argsValue, flagsValue) ->
106+
callback argsValue flagsValue
101107

102-
Left err ->
103-
Error.exitWithError err
108+
Left err ->
109+
Error.exitWithError err
104110

105111

106112

0 commit comments

Comments
 (0)