Skip to content

Commit 8b7e756

Browse files
committed
Make separate binaries for Elm 0.16 and Elm 0.17
1 parent 583d63c commit 8b7e756

File tree

8 files changed

+109
-29
lines changed

8 files changed

+109
-29
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ cd elm-format
9696
cabal sandbox init
9797
cabal install --only-dependencies --enable-tests
9898
cabal build
99-
./dist/build/elm-format/elm-format --help
99+
./dist/build/elm-format-0.17/elm-format-0.17 --help
100100
```
101101

102102
### Running tests

elm-format.cabal

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Name: elm-format-0.17
1+
Name: elm-format
22
Version: 0.3.0-alpha
33

44
Synopsis:
@@ -28,7 +28,7 @@ source-repository head
2828
type: git
2929
location: git://github.com/avh4/elm-format.git
3030

31-
Executable elm-format
31+
Executable elm-format-0.17
3232

3333
ghc-options:
3434
-threaded -O2 -W
@@ -38,7 +38,41 @@ Executable elm-format
3838
parser/src
3939

4040
Main-is:
41-
Main.hs
41+
Main0_17.hs
42+
43+
Build-depends:
44+
aeson >= 0.7 && < 0.9,
45+
ansi-terminal >= 0.6.2.1 && < 0.7,
46+
ansi-wl-pprint,
47+
base >= 4.2 && < 5,
48+
binary >= 0.7.0.0 && < 0.8,
49+
bytestring >= 0.9 && < 0.11,
50+
containers >= 0.3 && < 0.6,
51+
directory >= 1.0 && < 2.0,
52+
edit-distance >= 0.2 && < 0.3,
53+
filepath >= 1 && < 2.0,
54+
filemanip >= 0.1 && < 1.0,
55+
indents >= 0.3 && < 0.4,
56+
mtl >= 2.2 && < 3,
57+
optparse-applicative >=0.11 && <0.12,
58+
parsec >= 3.1.1 && < 3.5,
59+
pretty >= 1.0 && < 2.0,
60+
process,
61+
regex-applicative >= 0.3.3 && < 0.4,
62+
split >= 0.2.2 && < 0.3,
63+
text
64+
65+
Executable elm-format-0.16
66+
67+
ghc-options:
68+
-threaded -O2 -W
69+
70+
hs-source-dirs:
71+
src
72+
parser/src
73+
74+
Main-is:
75+
Main0_16.hs
4276

4377
Build-depends:
4478
aeson >= 0.7 && < 0.9,

src/Main.hs renamed to src/ElmFormat.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{-# OPTIONS_GHC -Wall #-}
2-
module Main where
2+
module ElmFormat where
33

44
import Elm.Utils ((|>))
55
import System.Exit (exitFailure, exitSuccess)
@@ -140,10 +140,10 @@ handleFilesInput inputFiles outputFile autoYes validateOnly elmVersion =
140140
else
141141
return Nothing
142142

143-
main :: IO ()
144-
main =
143+
main :: ElmVersion -> IO ()
144+
main defaultVersion =
145145
do
146-
config <- Flags.parse
146+
config <- Flags.parse defaultVersion
147147
let inputFiles = (Flags._input config)
148148
let isStdin = (Flags._stdin config)
149149
let outputFile = (Flags._output config)
@@ -156,7 +156,7 @@ main =
156156

157157
-- when we don't have any input, stdin or otherwise
158158
when (noInputSource) $
159-
Flags.showHelpText
159+
Flags.showHelpText defaultVersion
160160
>> exitFailure
161161

162162
when (twoInputSources) $

src/ElmVersion.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ data ElmVersion
77
| Elm_0_17
88

99

10+
instance Show ElmVersion where
11+
show Elm_0_16 = "0.16"
12+
show Elm_0_17 = "0.17"
13+
14+
1015
parse :: String -> Either String ElmVersion
1116
parse versionString =
1217
case versionString of

src/Flags.hs

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,55 @@ data Config = Config
2222
}
2323

2424

25+
2526
-- PARSE ARGUMENTS
2627

27-
parse :: IO Config
28-
parse =
29-
Opt.customExecParser preferences parser
28+
29+
parse :: ElmVersion -> IO Config
30+
parse defaultVersion =
31+
Opt.customExecParser preferences (parser defaultVersion)
32+
3033

3134
preferences :: Opt.ParserPrefs
3235
preferences =
3336
Opt.prefs (mempty <> Opt.showHelpOnError)
3437

35-
parser :: Opt.ParserInfo Config
36-
parser =
37-
Opt.info (Opt.helper <*> flags) helpInfo
3838

39-
showHelpText :: IO ()
40-
showHelpText = Opt.handleParseResult . Opt.Failure $
41-
Opt.parserFailure preferences parser Opt.ShowHelpText mempty
39+
parser :: ElmVersion -> Opt.ParserInfo Config
40+
parser defaultVersion =
41+
Opt.info
42+
(Opt.helper <*> flags defaultVersion)
43+
(helpInfo defaultVersion)
44+
45+
46+
showHelpText :: ElmVersion -> IO ()
47+
showHelpText defaultVersion = Opt.handleParseResult . Opt.Failure $
48+
Opt.parserFailure
49+
preferences
50+
(parser defaultVersion)
51+
Opt.ShowHelpText
52+
mempty
4253

4354

4455

4556
-- COMMANDS
4657

47-
flags :: Opt.Parser Config
48-
flags =
58+
flags :: ElmVersion -> Opt.Parser Config
59+
flags defaultVersion =
4960
Config
5061
<$> Opt.many input
5162
<*> output
5263
<*> yes
5364
<*> validate
5465
<*> stdin
55-
<*> elmVersion
66+
<*> elmVersion defaultVersion
5667

5768

5869

5970
-- HELP
6071

61-
helpInfo :: Opt.InfoMod Config
62-
helpInfo =
72+
helpInfo :: ElmVersion -> Opt.InfoMod Config
73+
helpInfo defaultVersion =
6374
mconcat
6475
[ Opt.fullDesc
6576
, Opt.header top
@@ -68,7 +79,10 @@ helpInfo =
6879
]
6980
where
7081
top =
71-
"elm-format " ++ showVersion This.version ++ " \n"
82+
concat
83+
[ "elm-format-" ++ show defaultVersion ++ " "
84+
, showVersion This.version ++ "\n"
85+
]
7286

7387
examples =
7488
linesToDoc
@@ -131,13 +145,20 @@ stdin =
131145
]
132146

133147

134-
elmVersion :: Opt.Parser ElmVersion
135-
elmVersion =
136-
fmap (Maybe.fromMaybe Elm_0_17)$
148+
elmVersion :: ElmVersion -> Opt.Parser ElmVersion
149+
elmVersion defaultVersion =
150+
fmap (Maybe.fromMaybe defaultVersion)$
137151
Opt.optional $
138152
Opt.option (Opt.eitherReader ElmVersion.parse) $
139153
mconcat
140154
[ Opt.long "elm-version"
141155
, Opt.metavar "VERSION"
142-
, Opt.help "The Elm version of the source files being formatted. Valid values: 0.16, 0.17. Default: 0.17"
156+
, Opt.help $
157+
concat
158+
[ "The Elm version of the source files being formatted. "
159+
, "Valid values: "
160+
, show ElmVersion.Elm_0_16 ++ ", "
161+
, show ElmVersion.Elm_0_17 ++ ". "
162+
, "Default: " ++ show defaultVersion
163+
]
143164
]

src/Main0_16.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{-# OPTIONS_GHC -Wall #-}
2+
module Main where
3+
4+
import ElmVersion
5+
import qualified ElmFormat
6+
7+
8+
main :: IO ()
9+
main =
10+
ElmFormat.main Elm_0_16

src/Main0_17.hs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{-# OPTIONS_GHC -Wall #-}
2+
module Main where
3+
4+
import ElmVersion
5+
import qualified ElmFormat
6+
7+
8+
main :: IO ()
9+
main =
10+
ElmFormat.main Elm_0_17

tests/run-tests.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
cabal build || exit 1
88

9-
ELM_FORMAT="./dist/build/elm-format/elm-format"
9+
ELM_FORMAT="./dist/build/elm-format-0.17/elm-format-0.17"
1010
if which md5 > /dev/null; then
1111
MD5="md5"
1212
else

0 commit comments

Comments
 (0)