3
3
module Main (main ) where
4
4
5
5
import Codec.CBOR.Cuddle.CBOR.Gen (generateCBORTerm )
6
- import Codec.CBOR.Cuddle.CDDL (Name (.. ))
7
- import Codec.CBOR.Cuddle.CDDL.Resolve
8
- ( fullResolveCDDL ,
9
- )
6
+ import Codec.CBOR.Cuddle.CDDL (Name (.. ), sortCDDL )
7
+ import Codec.CBOR.Cuddle.CDDL.Resolve (
8
+ fullResolveCDDL ,
9
+ )
10
10
import Codec.CBOR.Cuddle.Parser (pCDDL )
11
11
import Codec.CBOR.Cuddle.Pretty ()
12
12
import Codec.CBOR.FlatTerm (toFlatTerm )
@@ -22,7 +22,6 @@ import System.Exit (exitFailure, exitSuccess)
22
22
import System.IO (hPutStrLn , stderr )
23
23
import System.Random (getStdGen )
24
24
import Text.Megaparsec (ParseErrorBundle , Parsec , errorBundlePretty , runParser )
25
- import Codec.CBOR.Cuddle.CDDL (sortCDDL )
26
25
27
26
data Opts = Opts Command String
28
27
@@ -47,8 +46,8 @@ pCBOROutputFormat = eitherReader $ \case
47
46
s -> Left s
48
47
49
48
data GenOpts = GenOpts
50
- { itemName :: T. Text,
51
- outputFormat :: CBOROutputFormat
49
+ { itemName :: T. Text
50
+ , outputFormat :: CBOROutputFormat
52
51
}
53
52
54
53
pGenOpts :: Parser GenOpts
@@ -86,23 +85,20 @@ opts =
86
85
( command
87
86
" format"
88
87
( info
89
- ( Format <$> pFormatOpts)
90
- ( progDesc " Format the provided CDDL file"
91
- )
88
+ (Format <$> pFormatOpts)
89
+ (progDesc " Format the provided CDDL file" )
92
90
)
93
91
<> command
94
92
" validate"
95
93
( info
96
94
(pure Validate )
97
- ( progDesc " Validate the provided CDDL file"
98
- )
95
+ (progDesc " Validate the provided CDDL file" )
99
96
)
100
97
<> command
101
98
" gen"
102
99
( info
103
100
(GenerateCBOR <$> pGenOpts)
104
- ( progDesc " Generate a CBOR term matching the schema"
105
- )
101
+ (progDesc " Generate a CBOR term matching the schema" )
106
102
)
107
103
)
108
104
<*> argument str (metavar " CDDL_FILE" )
@@ -126,8 +122,9 @@ run (Opts cmd cddlFile) = do
126
122
putStrLnErr $ errorBundlePretty err
127
123
exitFailure
128
124
Right res -> case cmd of
129
- Format fOpts -> let defs = if sort fOpts then sortCDDL res else res in
130
- putDocW 80 $ pretty defs
125
+ Format fOpts ->
126
+ let defs = if sort fOpts then sortCDDL res else res
127
+ in putDocW 80 $ pretty defs
131
128
Validate -> case fullResolveCDDL res of
132
129
Left err -> putStrLnErr (show err) >> exitFailure
133
130
Right _ -> exitSuccess
0 commit comments