summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJoey Hess <joeyh@joeyh.name>2016-08-12 11:44:34 -0400
committerJoey Hess <joeyh@joeyh.name>2016-08-12 11:44:34 -0400
commit3ee306d3d4bda52268f07df874070b65d171694e (patch)
tree4ed6a83a2e4358b0dd0ff4a0a5c62108a99286c2
parenta58aea595a780c91bbbe26d2d24a63abcd835994 (diff)
downloadkeysafe-3ee306d3d4bda52268f07df874070b65d171694e.tar.gz
add --gui option
-rw-r--r--CmdLine.hs6
-rw-r--r--UI.hs17
-rw-r--r--UI/Zenity.hs2
-rw-r--r--keysafe.cabal1
-rw-r--r--keysafe.hs2
5 files changed, 25 insertions, 3 deletions
diff --git a/CmdLine.hs b/CmdLine.hs
index 3d45d5a..2b494db 100644
--- a/CmdLine.hs
+++ b/CmdLine.hs
@@ -14,6 +14,7 @@ data CmdLine = CmdLine
, name :: Name
, keytype :: KeyType
, testMode :: Bool
+ , gui :: Bool
}
deriving (Show)
@@ -26,6 +27,7 @@ parse = CmdLine
<*> nameopt
<*> keytypeopt
<*> testmodeswitch
+ <*> guiswitch
where
backup = flag' Backup
( long "backup"
@@ -47,6 +49,10 @@ parse = CmdLine
( long "testmode"
<> help "Avoid using expensive cryptographic operation to secure key. Use for testing only, not with real secret keys."
)
+ guiswitch = switch
+ ( long "gui"
+ <> help "Use GUI interface for interaction. Default is to use readline interface when run in a terminal, and GUI otherwise."
+ )
get :: IO CmdLine
get = execParser opts
diff --git a/UI.hs b/UI.hs
index 0ce87db..a97f3c1 100644
--- a/UI.hs
+++ b/UI.hs
@@ -10,5 +10,18 @@ import Control.Monad
import UI.Zenity
import UI.Readline
-availableUI :: IO [UI]
-availableUI = filterM isAvailable [zenityUI, readlineUI]
+availableUIs :: IO [UI]
+availableUIs = filterM isAvailable [zenityUI, readlineUI]
+
+selectUI :: Bool -> IO UI
+selectUI needgui
+ | needgui = do
+ ok <- isAvailable zenityUI
+ if ok
+ then return zenityUI
+ else error "zenitty is not installed, GUI not available"
+ | otherwise = do
+ l <- availableUIs
+ case l of
+ (u:_) -> return u
+ [] -> error "Neither zenity nor the readline UI are available"
diff --git a/UI/Zenity.hs b/UI/Zenity.hs
index 5eb4bef..3b8b028 100644
--- a/UI/Zenity.hs
+++ b/UI/Zenity.hs
@@ -5,8 +5,8 @@
module UI.Zenity (zenityUI) where
-import UI
import Types
+import Types.UI
import Control.Monad
import System.Process
import Control.Exception
diff --git a/keysafe.cabal b/keysafe.cabal
index aa212b1..28fa921 100644
--- a/keysafe.cabal
+++ b/keysafe.cabal
@@ -32,6 +32,7 @@ Executable keysafe
, unix == 2.7.*
, filepath == 1.4.*
, directory == 1.2.*
+ , process == 1.2.*
, optparse-applicative == 0.12.*
, readline == 1.0.*
diff --git a/keysafe.hs b/keysafe.hs
index b31d377..94a7b09 100644
--- a/keysafe.hs
+++ b/keysafe.hs
@@ -10,6 +10,7 @@ module Main where
import Types
import Tunables
import qualified CmdLine
+import UI
import Encryption
import Cost
import Shard
@@ -19,6 +20,7 @@ import Storage.LocalFiles
main :: IO ()
main = do
cmdline <- CmdLine.get
+ ui <- selectUI (CmdLine.gui cmdline)
let name = CmdLine.name cmdline
let keytype = CmdLine.keytype cmdline
-- TODO determine gpg key id by examining secret key,