Commit c854092b authored by Iustin Pop's avatar Iustin Pop
Browse files

Accept both full and short names in CLI

This patch introduces some new functionality in the base Element type
and in Container which supports searching for all 'known' names of an
element, such that both short and full names are accept for various
options like '-O' and '--excluded-instances'.
parent 3e4480e0
......@@ -108,7 +108,7 @@ findByName :: (T.Element a, Monad m) =>
Container a -> String -> m a
findByName c n =
let all_elems = elems c
result = filter ((== n) . T.nameOf) all_elems
result = filter ((n `elem`) . T.allNames) all_elems
in case result of
[item] -> return item
_ -> fail $ "Wrong number of elems found with name " ++ n
......@@ -69,6 +69,7 @@ instance T.Element Instance where
idxOf = idx
setAlias = setAlias
setIdx = setIdx
allNames n = [name n, alias n]
-- | Running instance states.
runningStates :: [String]
......
......@@ -188,9 +188,10 @@ mergeData um extags exinsts (nl, il, tags) =
common_suffix = longestDomain (node_names ++ inst_names)
snl = Container.map (computeAlias common_suffix) nl3
sil = Container.map (computeAlias common_suffix) il4
in if not $ all (`elem` inst_names) exinsts
all_inst_names = concatMap allNames $ Container.elems sil
in if not $ all (`elem` all_inst_names) exinsts
then Bad $ "Some of the excluded instances are unknown: " ++
show (exinsts \\ inst_names)
show (exinsts \\ all_inst_names)
else Ok (snl, sil, tags)
-- | Checks the cluster data for consistency.
......
......@@ -124,6 +124,7 @@ instance T.Element Node where
idxOf = idx
setAlias = setAlias
setIdx = setIdx
allNames n = [name n, alias n]
-- | A simple name for the int, node association list.
type AssocList = [(T.Ndx, Node)]
......
......@@ -192,6 +192,8 @@ instance Monad OpResult where
class Element a where
-- | Returns the name of the element
nameOf :: a -> String
-- | Returns all the known names of the element
allNames :: a -> [String]
-- | Returns the index of the element
idxOf :: a -> Int
-- | Updates the alias of the element
......
......@@ -196,7 +196,7 @@ main = do
let offline_names = optOffline opts
all_nodes = Container.elems fixed_nl
all_names = map Node.name all_nodes
all_names = concatMap allNames all_nodes
offline_wrong = filter (`notElem` all_names) offline_names
offline_indices = map Node.idx $
filter (\n -> Node.name n `elem` offline_names)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment