ip6addr 0.5.3 → 1.0.0
raw patch · 3 files changed
+89/−104 lines, 3 filesdep ~IPv6Addr
Dependency ranges changed: IPv6Addr
Files
- Main.hs +0/−94
- app/Main.hs +79/−0
- ip6addr.cabal +10/−10
− Main.hs
@@ -1,94 +0,0 @@-{-# LANGUAGE DeriveDataTypeable #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE RecordWildCards #-}--import Control.Monad (replicateM_)-import Data.Monoid ((<>))-import qualified Data.Text as T-import qualified Data.Text.IO as TIO (hPutStrLn, putStrLn)-import System.Console.CmdArgs-import System.Exit-import System.IO (stderr)--import Text.IPv6Addr--version :: String-version = "0.5.2"--data Input = Input- { output :: String- , address :: String- , quantity :: Int- , prefix :: String- } deriving (Show, Data, Typeable)--ip6addrInput :: Input-ip6addrInput = Input- { address = mempty- &= typ " <IPv6 address>"- , output = "canonical"- &= typ " [canonical|pure|full|arpa|unc|random]"- &= help "Default : canonical (RFC 5952)"- , quantity = 1- &= help "Amount of random addresses to generate"- &= typ " <Integer>"- , prefix = ""- &= typ " <Prefix>"- &= help "Set a prefix for random addresses generation"- } &= summary ("ip6addr version " <> version <> " (c) Michel Boucey 2015-2017")- &= program "ip6addr"- &= helpArg [name "h"]- &= details [ "Examples:"- , ""- , " ip6addr -a 0:0::FFFF:192.0.2.128"- , " ip6addr -o full -a ::1"- , " ip6addr -o random -q 10 -p 1234:abcd::"- , ""- ]--main :: IO ()-main = do- Input{..} <- cmdArgs ip6addrInput- if output == "random"- then replicateM_ quantity (putRandAddr prefix) >> exitSuccess- else- case output of- "canonical" -> out maybeIPv6Addr address fromIPv6Addr- "pure" -> out maybePureIPv6Addr address fromIPv6Addr- "full" -> out maybeFullIPv6Addr address fromIPv6Addr- "arpa" -> out maybeIP6ARPA address id- "unc" -> out maybeUNC address id- _ -> TIO.hPutStrLn stderr "See help" >> exitFailure- where- putRandAddr p = do- r <- randIPv6AddrWithPrefix (if p == mempty then Nothing else Just (T.pack p))- case r of- Nothing -> TIO.putStrLn "Bad prefix"- Just a -> TIO.putStrLn (fromIPv6Addr a)- out t i o =- if i /= mempty- then do- let p = T.pack i- case t p of- Nothing ->- TIO.hPutStrLn stderr ("'" <> p <> "' is not an IPv6 address")- >> exitFailure- Just a -> TIO.putStrLn (o a) >> exitSuccess- else Prelude.putStrLn "See help" >> exitFailure- maybeUNC t =- maybe- Nothing- (\a -> Just (T.concatMap trans (fromIPv6Addr a) <> ".ipv6-literal.net"))- (maybePureIPv6Addr t)- where- trans ':' = "-"- trans c = T.pack [c]- maybeIP6ARPA t =- maybe- Nothing- (\a -> Just (T.reverse (T.concatMap trans (fromIPv6Addr a)) <> "IP6.ARPA."))- (maybeFullIPv6Addr t)- where- trans ':' = T.empty- trans c = "." <> T.pack [c]-
+ app/Main.hs view
@@ -0,0 +1,79 @@+{-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE RecordWildCards #-}++import Control.Monad (replicateM_)+import Data.Monoid ((<>))+import qualified Data.Text as T+import qualified Data.Text.IO as TIO (hPutStrLn, putStrLn)+import System.Console.CmdArgs+import System.Exit+import System.IO (stderr)++import Text.IPv6Addr++version :: String+version = "1.0.0"++data Input = Input+ { output :: String+ , address :: String+ , quantity :: Int+ , prefix :: String+ } deriving (Show, Data, Typeable)++ip6addrInput :: Input+ip6addrInput = Input+ { address = mempty+ &= typ " <IPv6 address>"+ , output = "canonical"+ &= typ " [canonical|pure|full|arpa|unc|random]"+ &= help "Default : canonical (RFC 5952)"+ , quantity = 1+ &= help "Amount of random addresses to generate"+ &= typ " <Integer>"+ , prefix = ""+ &= typ " <Prefix>"+ &= help "Set a prefix for random addresses generation"+ } &= summary ("ip6addr version " <> version <> " (c) Michel Boucey 2011-2018")+ &= program "ip6addr"+ &= helpArg [name "h"]+ &= details [ "Examples:"+ , ""+ , " ip6addr -a 0:0::FFFF:192.0.2.128"+ , " ip6addr -o full -a ::1"+ , " ip6addr -o random -q 10 -p 1234:abcd::"+ , ""+ ]++main :: IO ()+main = do+ Input{..} <- cmdArgs ip6addrInput+ if output == "random"+ then replicateM_ quantity (putRandAddr prefix) >> exitSuccess+ else+ case output of+ "canonical" -> out maybeIPv6Addr address fromIPv6Addr+ "pure" -> out maybePureIPv6Addr address fromIPv6Addr+ "full" -> out maybeFullIPv6Addr address fromIPv6Addr+ "arpa" -> out maybeIP6ARPA address id+ "unc" -> out maybeUNC address id+ _ -> TIO.hPutStrLn stderr "See help" >> exitFailure+ where+ putRandAddr p = do+ r <- randIPv6AddrWithPrefix (if p == mempty then Nothing else Just (T.pack p))+ case r of+ Just a -> TIO.putStrLn (fromIPv6Addr a)+ Nothing -> TIO.putStrLn "Bad prefix"+ out t i o =+ if i /= mempty+ then do+ let p = T.pack i+ case t p of+ Nothing ->+ TIO.hPutStrLn stderr ("'" <> p <> "' is not an IPv6 address") >> exitFailure+ Just a -> TIO.putStrLn (o a) >> exitSuccess+ else Prelude.putStrLn "See help" >> exitFailure+ maybeUNC t = toUNC <$> maybePureIPv6Addr t+ maybeIP6ARPA t = toIP6ARPA <$> maybeFullIPv6Addr t+
ip6addr.cabal view
@@ -1,17 +1,17 @@-name: ip6addr-version: 0.5.3 cabal-version: >=1.10-build-type: Simple+name: ip6addr+version: 1.0.0 license: BSD3 license-file: LICENSE-copyright: Copyright (c) 2011-2017 - Michel Boucey+copyright: Copyright (c) 2011-2018 - Michel Boucey maintainer: michel.boucey@cybervisible.fr+author: Michel Boucey homepage: https://github.com/MichelBoucey/ip6addr synopsis: Commandline tool to generate IPv6 address text representations description: Commandline tool to generate IPv6 address text representations category: Network,Console-author: Michel Boucey+build-type: Simple extra-source-files: README.md @@ -21,12 +21,12 @@ executable ip6addr main-is: Main.hs+ hs-source-dirs: app+ default-language: Haskell2010+ other-extensions: DeriveDataTypeable OverloadedStrings+ ghc-options: -Wall build-depends: base >=4.8 && <5, cmdargs >=0.10.13 && <0.11,- IPv6Addr >=0.6.0.2 && <1.1.0,+ IPv6Addr >=1.1.0 && <1.2.0, text >=1.2.2 && <1.3- default-language: Haskell2010- other-extensions: DeriveDataTypeable OverloadedStrings- ghc-options: -Wall-