ADD cli arg for bitwarden name to look up

This commit is contained in:
Nathan Dwarshuis 2021-06-26 00:07:37 -04:00
parent 75f06b5b25
commit 5a063fe237
1 changed files with 31 additions and 27 deletions

View File

@ -9,55 +9,59 @@ module Main where
import Data.List import Data.List
import Bitwarden.Internal import Bitwarden.Internal
import System.Environment
import System.Exit import System.Exit
main :: IO () main :: IO ()
main = do main = do
n <- parseArgs =<< getArgs
putStrLn "Hello loser" putStrLn "Hello loser"
pinentryLoop pinentryLoop n
pinentryLoop :: IO () parseArgs :: [String] -> IO String
pinentryLoop = do parseArgs [n] = return n
parseArgs _ = do
putStrLn "Usage: pinentry-rofi [BWNAME]"
exitWith $ ExitFailure 1
pinentryLoop :: String -> IO ()
pinentryLoop n = do
c <- getLine c <- getLine
processLine $ words c processLine n $ words c
pinentryLoop pinentryLoop n
processLine :: [String] -> IO () processLine :: String -> [String] -> IO ()
processLine [] = noop processLine _ [] = noop
processLine ["BYE"] = exitSuccess processLine _ ["BYE"] = exitSuccess
processLine ["GETPIN"] = getPin processLine n ["GETPIN"] = getPin n
-- TODO this might be important -- TODO this might be important
processLine ["OPTION", o] = processOption o processLine _ ["OPTION", o] = processOption o
-- TODO this might be important -- TODO this might be important
processLine ["GETINFO", _] = noop processLine _ ["GETINFO", _] = noop
-- these all take one arg and should do nothing here -- these all take one arg and should do nothing here
processLine ["SETDESC", _] = noop processLine _ ["SETDESC", _] = noop
processLine ["SETOK", _] = noop processLine _ ["SETOK", _] = noop
processLine ["SETNOTOK", _] = noop processLine _ ["SETNOTOK", _] = noop
processLine ["SETCANCEL", _] = noop processLine _ ["SETCANCEL", _] = noop
processLine ["SETPROMPT", _] = noop processLine _ ["SETPROMPT", _] = noop
processLine ["SETERROR", _] = noop processLine _ ["SETERROR", _] = noop
-- CONFIRM can take a flag -- CONFIRM can take a flag
processLine ["CONFIRM"] = noop processLine _ ["CONFIRM"] = noop
processLine ["CONFIRM", "--one-button", _] = noop processLine _ ["CONFIRM", "--one-button", _] = noop
processLine ss = unknownCommand $ unwords ss processLine _ ss = unknownCommand $ unwords ss
unknownCommand :: String -> IO () unknownCommand :: String -> IO ()
unknownCommand c = putStrLn $ "ERR 275 Unknown command " ++ c unknownCommand c = putStrLn $ "ERR 275 Unknown command " ++ c
-- TODO make this a CLI arg getPin :: String -> IO ()
gpgname :: String getPin n = do
gpgname = "password name"
getPin :: IO ()
getPin = do
its <- getItems its <- getItems
let p = (password . login) =<< find (\i -> gpgname == name i) its let p = (password . login) =<< find (\i -> n == name i) its
maybe err printPin p maybe err printPin p
where where
err = putStrLn "ERR 83886179 Operation canceled <rofi>" err = putStrLn "ERR 83886179 Operation canceled <rofi>"