packages feed

ip6addr 0.4.0.0 → 0.5.0.0

raw patch · 2 files changed

+49/−26 lines, 2 filesdep ~IPv6Addr

Dependency ranges changed: IPv6Addr

Files

Main.hs view
@@ -4,56 +4,79 @@ -- License    : BSD-Style -- Maintainer : michel.boucey@gmail.com ----- commandline tool to generate IPv6 address text representations+-- Commandline tool to generate IPv6 address text representations -- -- -----------------------------------------------------------------------------  {-# LANGUAGE DeriveDataTypeable,OverloadedStrings #-} -import Control.Applicative ((<$>)) import Control.Monad (replicateM_) import Data.Text as T (append,pack) import Data.Text.IO as TIO (putStrLn,hPutStrLn) import System.Console.CmdArgs import System.Exit import System.IO (stderr)+ import Text.IPv6Addr  data Input =Input     { output   :: String     , address  :: String     , quantity :: Int+    , prefix   :: String     } deriving (Show,Data,Typeable)  ip6addrInput :: Input ip6addrInput = Input-    { address = "" &= typ " <IPv6 address>"-    , output = "canonical" &= typ " [pure|canonical|full|arpa|random]" &= help "(default=canonical)"-    , quantity = 1 &= help "Amount of random addresses to generate" &= typ " <Integer>"-    } &= summary "ip6addr version 0.4 (C) Michel Boucey 2015"+    { address = ""+      &= typ " <IPv6 address>"+    , output = "canonical"+      &= typ " [pure|canonical|full|arpa|random]"+      &= help "(default=canonical)"+    , 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 0.5 (C) Michel Boucey 2015"       &= 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",""]+      &= 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     a <- cmdArgs ip6addrInput     if output a == "random"-        then replicateM_ (quantity a) putRandAddr >> exitSuccess-        else do let m = address a-                case output a of-                    "canonical" -> out maybeIPv6Addr m fromIPv6Addr-                    "full"      -> out maybeFullIPv6Addr m fromIPv6Addr-                    "arpa"      -> out maybePureIPv6Addr m toIP6ARPA-                    "pure"      -> out maybePureIPv6Addr m fromIPv6Addr-                    _           -> hPutStrLn stderr "See help"-                                >> exitFailure+        then replicateM_ (quantity a) (putRandAddr (prefix a)) >> exitSuccess+        else do+            let m = address a+            case output a of+                "canonical" -> out maybeIPv6Addr m fromIPv6Addr+                "full"      -> out maybeFullIPv6Addr m fromIPv6Addr+                "arpa"      -> out maybePureIPv6Addr m toIP6ARPA+                "pure"      -> out maybePureIPv6Addr m fromIPv6Addr+                _           -> hPutStrLn stderr "See help" >> exitFailure   where-    putRandAddr = fromIPv6Addr <$> randIPv6Addr >>= TIO.putStrLn+    putRandAddr p = do+        r <- randIPv6AddrWithPrefix $+                 if p == "" 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 /= ""-            then do let p = T.pack i-                    case t p of-                        Nothing -> hPutStrLn stderr ("'" `T.append` p `T.append` "' is not an IPv6 address") >> exitFailure-                        Just a  -> TIO.putStrLn (o a) >> exitSuccess+            then do+                let p = T.pack i+                case t p of+                    Nothing -> hPutStrLn stderr +                        ("'" `T.append` p `T.append` "' is not an IPv6 address")+                        >> exitFailure+                    Just a  -> TIO.putStrLn (o a) >> exitSuccess             else Prelude.putStrLn "See help" >> exitFailure
ip6addr.cabal view
@@ -1,7 +1,7 @@ name:                ip6addr-version:             0.4.0.0-synopsis:            commandline tool to generate IPv6 address text representations-description:         commandline tool to generate IPv6 address text representations+version:             0.5.0.0+synopsis:            Commandline tool to generate IPv6 address text representations+description:         Commandline tool to generate IPv6 address text representations license:             BSD3 license-file:        LICENSE author:              Michel Boucey@@ -17,8 +17,8 @@   Location: https://github.com/MichelBoucey/ip6addr.git  executable ip6addr-  GHC-Options: -O2 -Wall+  GHC-Options: -Wall   main-is:             Main.hs   other-extensions:    DeriveDataTypeable, OverloadedStrings-  build-depends:       base >=4.7 && <4.8, cmdargs,IPv6Addr >= 0.5, text >= 1.2+  build-depends:       base >=4.7 && <4.8, cmdargs,IPv6Addr >= 0.6, text >= 1.2   default-language:    Haskell2010