ENH update evpn bin to reflect varying output from cli
This commit is contained in:
parent
e3ecbad62d
commit
fa8a7668d8
|
@ -6,6 +6,7 @@ module Main (main) where
|
||||||
|
|
||||||
import Control.Monad
|
import Control.Monad
|
||||||
|
|
||||||
|
import Data.List (isPrefixOf)
|
||||||
import Data.List.Split
|
import Data.List.Split
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
|
|
||||||
|
@ -59,10 +60,11 @@ getStatus = do
|
||||||
getConnectedServer :: IO (Maybe String)
|
getConnectedServer :: IO (Maybe String)
|
||||||
getConnectedServer = (procStatus =<<) <$> readCmdSuccess eVPN ["status"] ""
|
getConnectedServer = (procStatus =<<) <$> readCmdSuccess eVPN ["status"] ""
|
||||||
where
|
where
|
||||||
procStatus s = case words <$> lines s of
|
procStatus = listToMaybe . mapMaybe procLine . lines
|
||||||
|
procLine l = case words l of
|
||||||
-- the output is green...
|
-- the output is green...
|
||||||
(("\ESC[1;32;49mConnected":"to":server):_) -> Just $ unwords server
|
("\ESC[1;32;49mConnected":"to":server) -> Just $ unwords server
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
|
||||||
getAvailableServers :: IO [VPNServer]
|
getAvailableServers :: IO [VPNServer]
|
||||||
getAvailableServers = procOut =<< readCmdSuccess eVPN ["ls"] ""
|
getAvailableServers = procOut =<< readCmdSuccess eVPN ["ls"] ""
|
||||||
|
@ -70,13 +72,15 @@ getAvailableServers = procOut =<< readCmdSuccess eVPN ["ls"] ""
|
||||||
procOut Nothing = do
|
procOut Nothing = do
|
||||||
notify IconError "failed to get list of servers"
|
notify IconError "failed to get list of servers"
|
||||||
return []
|
return []
|
||||||
-- ASSUME the output has a header that has three lines, followed by the
|
-- ASSUME the output has a useless header that ends in a line that starts
|
||||||
-- stuff we care about, which is followed by a blank line (after which there
|
-- with "-----", after which is the stuff we care about, which is followed
|
||||||
-- is other stuff that doesn't matter based on the way I'm parsing below)
|
-- by a blank line, after which there is more stuff I don't care about
|
||||||
procOut (Just ls) = return
|
procOut (Just ls) = return
|
||||||
$ mapMaybe (matchLine . splitOn "\t")
|
$ mapMaybe (matchLine . splitOn "\t")
|
||||||
$ drop 3
|
|
||||||
$ takeWhile (/= "")
|
$ takeWhile (/= "")
|
||||||
|
$ drop 1
|
||||||
|
-- super lame way of matching lines that start with "-----"
|
||||||
|
$ dropWhile (not . isPrefixOf "-----")
|
||||||
$ lines ls
|
$ lines ls
|
||||||
-- The output of this command is very strange; it is delimited (kinda) by
|
-- The output of this command is very strange; it is delimited (kinda) by
|
||||||
-- tabs but some lines are long enough that they don't have a tab. In
|
-- tabs but some lines are long enough that they don't have a tab. In
|
||||||
|
|
Loading…
Reference in New Issue