Skip to content

Commit 8403e28

Browse files
committed
Cleanup of cli template.
1 parent 1e41db6 commit 8403e28

File tree

16 files changed

+45
-239
lines changed

16 files changed

+45
-239
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ cabal-dev
99
.cabal-sandbox
1010
cabal.sandbox.config
1111
/tmp
12+
/gen

Setup.hs

+15-9
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,31 @@ main :: IO ()
2020
main =
2121
let hooks = simpleUserHooks
2222
in defaultMainWithHooks hooks {
23-
buildHook = \pd lbi uh flags -> do
24-
genBuildInfo (fromFlag $ buildVerbosity flags) pd lbi
23+
preConf = \args flags -> do
24+
createDirectoryIfMissingVerbose silent True "gen"
25+
(preConf hooks) args flags
26+
, sDistHook = \pd mlbi uh flags -> do
27+
genBuildInfo silent pd
28+
(sDistHook hooks) pd mlbi uh flags
29+
, buildHook = \pd lbi uh flags -> do
30+
genBuildInfo (fromFlag $ buildVerbosity flags) pd
2531
(buildHook hooks) pd lbi uh flags
2632
, replHook = \pd lbi uh flags args -> do
27-
genBuildInfo (fromFlag $ replVerbosity flags) pd lbi
33+
genBuildInfo (fromFlag $ replVerbosity flags) pd
2834
(replHook hooks) pd lbi uh flags args
2935
, testHook = \args pd lbi uh flags -> do
30-
genBuildInfo (fromFlag $ testVerbosity flags) pd lbi
36+
genBuildInfo (fromFlag $ testVerbosity flags) pd
3137
(testHook hooks) args pd lbi uh flags
3238
}
3339

34-
genBuildInfo :: Verbosity -> PackageDescription -> LocalBuildInfo -> IO ()
35-
genBuildInfo verbosity pkg info = do
36-
createDirectoryIfMissingVerbose verbosity True (autogenModulesDir info)
40+
genBuildInfo :: Verbosity -> PackageDescription -> IO ()
41+
genBuildInfo verbosity pkg = do
42+
createDirectoryIfMissingVerbose verbosity True "gen"
3743
let (PackageName pname) = pkgName . package $ pkg
3844
version = pkgVersion . package $ pkg
3945
name = "BuildInfo_" ++ (map (\c -> if c == '-' then '_' else c) pname)
40-
targetHs = autogenModulesDir info </> name <.> "hs"
41-
targetText = autogenModulesDir info </> "version.txt"
46+
targetHs = "gen" </> name <.> "hs"
47+
targetText = "gen" </> "version.txt"
4248
t <- timestamp
4349
gv <- gitVersion
4450
let v = showVersion version

main/project.hs

+10-50
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
22
{-# LANGUAGE OverloadedStrings #-}
33

4-
import BuildInfo_project
5-
6-
import Data.String
7-
import qualified Data.Text as T
4+
import BuildInfo_ambiata_project
85

96
import Options.Applicative
107

@@ -20,59 +17,22 @@ main = do
2017
hSetBuffering stderr LineBuffering
2118
dispatch parser >>= \sc ->
2219
case sc of
23-
Version ->
20+
VersionCommand ->
2421
putStrLn buildInfoVersion >> exitSuccess
2522
RunCommand DryRun c ->
26-
print (renderCommand c) >> exitSuccess
23+
print c >> exitSuccess
2724
RunCommand RealRun c ->
2825
run c
2926

27+
parser :: Parser (SafeCommand Command)
28+
parser =
29+
safeCommand $ pure Command
30+
3031
run :: Command -> IO ()
3132
run c = case c of
32-
CommandInputs name ->
33-
putStrLn (T.unpack name)
34-
35-
36-
-------------
37-
-- DATA TYPES
38-
-------------
39-
40-
-- | This application can be run for real
41-
-- | or just return a description of what it is about to do
42-
data RunType =
43-
DryRun | RealRun
44-
deriving (Eq, Show)
45-
46-
data SafeCommand =
47-
Version
48-
| RunCommand RunType Command
49-
deriving (Eq, Show)
33+
Command ->
34+
putStrLn "*implement me*" >> exitFailure
5035

5136
data Command =
52-
CommandInputs T.Text
37+
Command
5338
deriving (Eq, Show)
54-
55-
renderCommand :: Command -> String
56-
renderCommand (CommandInputs name) =
57-
T.unpack $
58-
T.concat
59-
[ "CommandInputs("
60-
, "name=", name, ")"
61-
]
62-
63-
64-
----------
65-
-- PARSERS
66-
----------
67-
68-
parser :: Parser SafeCommand
69-
parser =
70-
Version <$ flag' () (short 'v' <> long "version" <> help "Version information")
71-
<|> RunCommand <$> flag RealRun DryRun (long "dry-run" <> hidden) <*> commandP'
72-
73-
commandP' :: Parser Command
74-
commandP' = CommandInputs <$> name'
75-
76-
name' :: Parser T.Text
77-
name'= fmap T.pack $ argument str $
78-
metavar "VIEW-NAME"

project.cabal

+19-21
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: project
1+
name: ambiata-project
22
version: 0.0.1
33
license: AllRightsReserved
44
author: Ambiata <[email protected]>
@@ -13,22 +13,20 @@ description: project
1313
library
1414
build-depends:
1515
base >= 3 && < 5
16-
, attoparsec == 0.12.*
16+
, ambiata-p
1717
, either >= 4.4.1 && < 4.5
18-
, p
19-
, text
18+
, text == 1.2.*
2019

2120
ghc-options:
2221
-Wall
2322

2423
hs-source-dirs:
25-
src
24+
src gen
2625

2726
exposed-modules:
28-
Paths_project
27+
Paths_ambiata_project
28+
BuildInfo_ambiata_project
2929
Project
30-
Project.Data
31-
Project.Error
3230

3331
executable project
3432
ghc-options:
@@ -39,11 +37,11 @@ executable project
3937

4038
build-depends:
4139
base
42-
, project
40+
, ambiata-project
41+
, ambiata-p
42+
, ambiata-x-optparse
4343
, optparse-applicative == 0.11.*
44-
, p
4544
, text
46-
, x-optparse
4745

4846

4947
test-suite test
@@ -61,10 +59,10 @@ test-suite test
6159

6260
build-depends:
6361
base >= 3 && < 5
64-
, project
65-
, disorder-core
66-
, disorder-corpus
67-
, p
62+
, ambiata-project
63+
, ambiata-disorder-core
64+
, ambiata-disorder-corpus
65+
, ambiata-p
6866
, QuickCheck == 2.7.*
6967
, quickcheck-instances == 0.3.*
7068

@@ -83,10 +81,10 @@ test-suite test-io
8381

8482
build-depends:
8583
base >= 3 && < 5
86-
, project
87-
, disorder-core
88-
, disorder-corpus
89-
, p
84+
, ambiata-project
85+
, ambiata-disorder-core
86+
, ambiata-disorder-corpus
87+
, ambiata-p
9088
, text
9189
, QuickCheck == 2.7.*
9290
, quickcheck-instances == 0.3.*
@@ -106,5 +104,5 @@ test-suite test-cli
106104

107105
build-depends:
108106
base >= 3 && < 5
109-
, project
110-
, disorder-core
107+
, ambiata-project
108+
, ambiata-disorder-core

src/Project.hs

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE ScopedTypeVariables #-}
3-
{-# LANGUAGE OverloadedStrings #-}
42
module Project where

src/Project/Data.hs

-4
This file was deleted.

src/Project/Error.hs

-4
This file was deleted.

test/Test/IO/Project/IO.hs

-23
This file was deleted.

test/Test/Project.hs

-16
This file was deleted.

test/Test/Project/Arbitrary.hs

-4
This file was deleted.

test/cli/basic-usage/run

-35
This file was deleted.

test/cli/core/.keep

Whitespace-only changes.

test/cli/core/runner.sh

-25
This file was deleted.

test/cli/errors/run

-21
This file was deleted.

test/cli/project/run

-22
This file was deleted.

test/test-io.hs

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import Disorder.Core.Main
22

3-
import qualified Test.IO.Project.IO
4-
53
main :: IO ()
64
main =
75
disorderMain [
8-
Test.IO.Project.IO.tests
96
]

0 commit comments

Comments
 (0)