1{-# LANGUAGE DeriveDataTypeable #-}
2module Elm.Internal.Name where
4import Control.Applicative
5import Control.Monad.Error
8import qualified Data.Text as T
9import qualified Data.Maybe as Maybe
12data Name = Name { user :: String, project :: String }
13 deriving (Typeable,Eq)
15instance Binary Name where
16 get = Name <$> get <*> get
17 put (Name user project) =
18 put user >> put project
20instance Show Name where
21 show name = user name ++ "/" ++ project name
23toFilePath :: Name -> FilePath
24toFilePath name = user name ++ "-" ++ project name
26fromString :: String -> Maybe Name
28 case break (=='/') string of
29 ( user@(_:_), '/' : project@(_:_) )
30 | all (/='/') project -> Just (Name user project)
33fromString' :: String -> ErrorT String IO Name
35 Maybe.maybe (throwError $ errorMsg string) return (fromString string)
37instance FromJSON Name where
38 parseJSON (String text) =
39 let string = T.unpack text in
40 Maybe.maybe (fail $ errorMsg string) return (fromString string)
42 parseJSON _ = fail "Project name must be a string."
44instance ToJSON Name where
45 toJSON name = toJSON (show name)
49 [ "Dependency file has an invalid name: " ++ string
50 , "Must have format user/project and match a public github project."
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list