Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

disambiguate commands

  • Loading branch information...
commit e3d5056ec8653ab94cee7c1ae794565aa8134535 1 parent f5fb760
Tom Nielsen authored

Showing 1 changed file with 9 additions and 4 deletions. Show diff stats Hide diff stats

  1. +9 4 Vishnu/Lib/RunVis.hs
13 Vishnu/Lib/RunVis.hs
@@ -2,6 +2,7 @@ module Vishnu.Lib.RunVis where
2 2
3 3 import Control.Monad
4 4 import Vishnu.Lib.Common
  5 +import Data.List
5 6
6 7 import System.Environment
7 8
@@ -13,10 +14,14 @@ runVis cmds = do
13 14 arg0:rest -> dispatch arg0 rest cmds
14 15
15 16 help cmds = do
16   - putStrLn "available commands:\n"
  17 + putStrLn "vishnu: available commands:\n"
17 18 forM_ cmds $ \(cmd,_) -> putStrLn (" "++cmd)
  19 + putStrLn ""
18 20
  21 +
  22 +dispatch :: String -> [String] -> [(String, VisM ())] -> IO ()
19 23 dispatch arg rest cmds
20   - = case lookup arg cmds of
21   - Just action -> runVisM rest action
22   - Nothing -> putStrLn ("unknown command: "++arg) >> help cmds
  24 + = case filter ((arg `isPrefixOf`) . fst) cmds of
  25 + (_,action):[] -> runVisM rest action
  26 + [] -> putStrLn ("unknown command: "++arg) >> help cmds
  27 + actions -> putStrLn ("ambiguous command: "++arg) >> help actions

0 comments on commit e3d5056

Please sign in to comment.
Something went wrong with that request. Please try again.