Permalink
Browse files

disambiguate commands

  • Loading branch information...
1 parent f5fb760 commit e3d5056ec8653ab94cee7c1ae794565aa8134535 @glutamate committed Mar 19, 2012
Showing with 9 additions and 4 deletions.
  1. +9 −4 Vishnu/Lib/RunVis.hs
View
@@ -2,6 +2,7 @@ module Vishnu.Lib.RunVis where
import Control.Monad
import Vishnu.Lib.Common
+import Data.List
import System.Environment
@@ -13,10 +14,14 @@ runVis cmds = do
arg0:rest -> dispatch arg0 rest cmds
help cmds = do
- putStrLn "available commands:\n"
+ putStrLn "vishnu: available commands:\n"
forM_ cmds $ \(cmd,_) -> putStrLn (" "++cmd)
+ putStrLn ""
+
+dispatch :: String -> [String] -> [(String, VisM ())] -> IO ()
dispatch arg rest cmds
- = case lookup arg cmds of
- Just action -> runVisM rest action
- Nothing -> putStrLn ("unknown command: "++arg) >> help cmds
+ = case filter ((arg `isPrefixOf`) . fst) cmds of
+ (_,action):[] -> runVisM rest action
+ [] -> putStrLn ("unknown command: "++arg) >> help cmds
+ actions -> putStrLn ("ambiguous command: "++arg) >> help actions

0 comments on commit e3d5056

Please sign in to comment.