Skip to content

Commit

Permalink
Add version flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MichelBoucey committed Aug 15, 2024
1 parent 2ee8fc4 commit 08e8f63
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions app/ip6addr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,28 @@ data Output

data Options =
Options
{ output :: Output
, quantity :: Int
, prefix :: String
, address :: String
{ showver :: !Bool
, output :: !Output
, quantity :: !Int
, prefix :: !String
, address :: !String
}

showVer = "ip6addr v" <> showVersion version <> " (c) Michel Boucey 2011-2024"

main :: IO ()
main = do
Options{..} <- execParser opts
case output of
Canonical -> out maybeIPv6Addr address unIPv6Addr
NoIPv4 -> out maybePureIPv6Addr address unIPv6Addr
FullLength -> out maybeFullIPv6Addr address unIPv6Addr
PTR -> out maybeIP6ARPA address id
UNC -> out maybeUNC address id
Random -> replicateM_ quantity (putRandAddr prefix) >> exitSuccess
if showver
then putStrLn showVer >> exitFailure
else
case output of
Canonical -> out maybeIPv6Addr address unIPv6Addr
NoIPv4 -> out maybePureIPv6Addr address unIPv6Addr
FullLength -> out maybeFullIPv6Addr address unIPv6Addr
PTR -> out maybeIP6ARPA address id
UNC -> out maybeUNC address id
Random -> replicateM_ quantity (putRandAddr prefix) >> exitSuccess
where
putRandAddr p = do
r <- randIPv6AddrWithPrefix (if p == mempty then Nothing else Just (T.pack p))
Expand All @@ -60,13 +66,19 @@ opts :: ParserInfo Options
opts = info (parseOptions <**> helper)
( fullDesc
<> progDesc "ip6addr"
<> header ( "ip6addr v" <> showVersion version <> " (c) Michel Boucey 2011-2024")
<> header (showVer)
)

parseOptions :: Parser Options
parseOptions =
Options
<$>
switch
( short 'v'
<> long "version"
<> help "Show version"
)
<*>
(flag Canonical Canonical
( short 'c'
<> long "canonical"
Expand Down

0 comments on commit 08e8f63

Please sign in to comment.