Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move the withKey function out into Trajectory.Private.Config .

  • Loading branch information...
commit f701ee7dc4cc2d43ffbfbfcecbd94da9312a987f 1 parent 36095a8
@mike-burns authored
Showing with 62 additions and 11 deletions.
  1. +19 −11 LsStory.hs
  2. +43 −0 Trajectory/Private/Config.hs
View
30 LsStory.hs
@@ -9,16 +9,20 @@ import Data.Maybe (fromMaybe, isNothing)
import Control.Applicative( (<*>) )
import Data.Monoid (mconcat)
+import Trajectory.Private.Config (withKey)
+
main = do
args <- cmdArgs lsStoryArgDefinition
- key <- getKey $ profileName args
- stories <- getStories key (accountName args) (projectName args)
-
- putStrLn $ handle stories args
+ withKey (profileName args) $ \key -> do
+ stories <- getStories key (accountName args) (projectName args)
+ putStrLn $ either (\error -> "Error: " ++ show error)
+ (handle args)
+ stories
-- TODO:
-getKey profileName = return "bc510c80a9077bde54cee1034bc37d09"
-getStories key accountName projectName = return [story1, story2, story4, story3]
+getStories :: String -> String -> String -> IO (Either String [Story])
+getStories key accountName projectName =
+ return $ Right [story1, story2, story4, story3]
where
story1 = Story
False
@@ -141,8 +145,8 @@ data Story = Story {
,storyIdeaSubject :: Maybe String
} deriving (Show, Eq, Typeable, Data)
-handle :: [Story] -> LsStoryArg -> String
-handle stories args =
+handle :: LsStoryArg -> [Story] -> String
+handle args stories =
let filters = buildFilters args
renderer = buildRenderer args in
renderer $ filters `pipe` stories
@@ -152,14 +156,18 @@ handle stories args =
buildRenderer args [] = ""
buildRenderer args stories
+ | onlyNext args && null nonMilestones = ""
| detailedOutput args && onlyNext args =
- head $ map detailedFormatter stories
+ head $ map detailedFormatter nonMilestones
| detailedOutput args =
intercalate "\n\n" $ map detailedFormatter stories
| onlyNext args =
- head $ map simpleFormatter stories
+ head $ map simpleFormatter nonMilestones
| otherwise =
intercalate "\n" $ map simpleFormatter stories
+ where
+ nonMilestones = skipMilestones stories
+ skipMilestones = filter $ ("Milestone" /=) . storyTaskType
detailedFormatter story =
title ++ "\n" ++ origins ++ "\n" ++ overall
@@ -210,7 +218,7 @@ beforeMilestoneFilter args
where
(Just milestoneTitle) = beforeMilestone args
notTheMilestone story =
- (storyTaskType story /= "milestone") &&
+ (storyTaskType story /= "Milestone") &&
(storyTitle story /= milestoneTitle)
estimationFilter args
View
43 Trajectory/Private/Config.hs
@@ -0,0 +1,43 @@
+module Trajectory.Private.Config where
+
+import qualified Data.ByteString.Char8 as BS (readFile, ByteString)
+import System.Environment (getEnv)
+import qualified Data.Map as M (lookup)
+import qualified Data.Text as T (pack, unpack)
+import Data.Aeson (json, Value(..))
+import Data.Attoparsec (parse, Result(..))
+
+withKey profileName doThis = do
+ maybeKey <- getKey profileName
+ case maybeKey of
+ Nothing -> putStrLn $ "Unknown profile name: " ++ profileName
+ (Just key) -> doThis key
+
+getKey profileName = do
+ possibleJsonString <- readConfig
+ case possibleJsonString of
+ Nothing -> return Nothing
+ (Just jsonString) -> do
+ return $ maybe Nothing (Just . extractKey) maybeKey
+ where
+ extractKey (String k) = T.unpack k
+ (Done _ config) = parse json jsonString
+ (Object mapping) = config
+ maybeKey = M.lookup (T.pack profileName) mapping
+
+readConfig :: IO (Maybe BS.ByteString)
+readConfig = do
+ configFileName <- getConfigFileName
+ (BS.readFile configFileName >>= return . Just) `catch` (const $ return Nothing)
+
+getConfigFileName = do
+ getEnv "TRAJECTORY_CONFIG_FILE"
+ `catch`
+ (const (getEnv "HOME" >>= return . withHomeDir))
+ `catch`
+ (const (getEnv "USER" >>= return . withUserName))
+ `catch`
+ (const (return "/.trajectory"))
+ where
+ withHomeDir homeDir = homeDir ++ "/.trajectory"
+ withUserName userName = "/usr/"++userName++"/.trajectory"
Please sign in to comment.
Something went wrong with that request. Please try again.