X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/a6cdfdccfd07556527352ea5c46e82b7467e307f..b9612abb7e31ea1bddfd390c52a5eb6db2f74c97:/htools/Ganeti/Common.hs?ds=sidebyside diff --git a/htools/Ganeti/Common.hs b/htools/Ganeti/Common.hs index e7e7a1e..4e5a275 100644 --- a/htools/Ganeti/Common.hs +++ b/htools/Ganeti/Common.hs @@ -71,7 +71,8 @@ data OptCompletion = OptComplNone -- ^ No parameter to this option | OptComplOneIallocator -- ^ One iallocator | OptComplInstAddNodes -- ^ Either one or two nodes | OptComplOneGroup -- ^ One group - | OptComplNumeric -- ^ Float values + | OptComplInteger -- ^ Integer values + | OptComplFloat -- ^ Float values | OptComplJobId -- ^ Job Id | OptComplCommand -- ^ Command (executable) | OptComplString -- ^ Arbitrary string @@ -91,8 +92,8 @@ optComplYesNo = OptComplChoices ["yes", "no"] -- | Text serialisation for 'OptCompletion', used on the Python side. complToText :: OptCompletion -> String -complToText (OptComplChoices choices) = "choices " ++ intercalate "," choices -complToText (OptComplSuggest choices) = "suggest " ++ intercalate "," choices +complToText (OptComplChoices choices) = "choices=" ++ intercalate "," choices +complToText (OptComplSuggest choices) = "suggest=" ++ intercalate "," choices complToText compl = let show_compl = show compl stripped = stripPrefix "OptCompl" show_compl @@ -183,10 +184,11 @@ parseOpts :: (StandardOptions a) => -> [String] -- ^ The command line arguments -> String -- ^ The program name -> [GenericOptType a] -- ^ The supported command line options + -> [ArgCompletion] -- ^ The supported command line arguments -> IO (a, [String]) -- ^ The resulting options and -- leftover arguments -parseOpts defaults argv progname options = - case parseOptsInner defaults argv progname options of +parseOpts defaults argv progname options arguments = + case parseOptsInner defaults argv progname options arguments of Left (code, msg) -> do hPutStr (if code == ExitSuccess then stdout else stderr) msg exitWith code @@ -201,8 +203,9 @@ parseOptsInner :: (StandardOptions a) => -> [String] -> String -> [GenericOptType a] + -> [ArgCompletion] -> Either (ExitCode, String) (a, [String]) -parseOptsInner defaults argv progname options = +parseOptsInner defaults argv progname options arguments = case getOpt Permute (map fst options) argv of (opts, args, []) -> case foldM (flip id) defaults opts of @@ -216,7 +219,8 @@ parseOptsInner defaults argv progname options = , (verRequested parsed, Left (ExitSuccess, versionInfo progname)) , (compRequested parsed, - Left (ExitSuccess, completionInfo progname options [])) + Left (ExitSuccess, completionInfo progname options + arguments)) ] (_, _, errs) -> Left (ExitFailure 2, "Command line error: " ++ concat errs ++ "\n" ++