Skip to content

Commit

Permalink
Merge pull request #2 from dbalan/change_new
Browse files Browse the repository at this point in the history
Change new command structure
  • Loading branch information
dbalan authored Apr 11, 2018
2 parents 2bb277e + 4e75590 commit 4561283
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 27 deletions.
8 changes: 8 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ jobs:
- checkout
- run: DEBIAN_FRONTEND=noninteractive apt-get update
- run: DEBIAN_FRONTEND=noninteractive apt-get install -y xz-utils make
- restore_cache:
keys:
- stack-dir
- run: stack upgrade
- run: stack setup
- run: stack build
- run: stack test
- save_cache:
key: stack-dir
paths:
- ".stack-work"
- "/root/.stack"

6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ Available commands:
1. Example session

```
$ idid new
what did you do? some stuff
$ idid new some stuff
$ idid what lastweek
2018-04-08
========
Expand All @@ -57,7 +56,10 @@ $ idid what lastweek
========
1. some stuff
```

## Hacking!
Pull requests welcome!


## Versioning
Uses semantic versioning.
18 changes: 6 additions & 12 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module Main where

import Cli
import Data as D
import System.IO

import Data.List
import Data.Time
import System.Directory
import System.FilePath

main :: IO ()
main = do
Expand All @@ -22,24 +22,18 @@ run (Args (CommonOpts fp) cmd) = do
runWithFp expPt cmd

runWithFp :: String -> Command -> IO ()
runWithFp fp CommandNew = newCmd fp
runWithFp fp (CommandNew msg) = newCmd (intercalate " " msg) fp
runWithFp fp (CommandWhat prd) = whatCmd prd fp

getExpandedPath :: FilePath -> IO FilePath
getExpandedPath ('~':'/':xs) = (++ "/" ++ xs) <$> getHomeDirectory
getExpandedPath x = return x

newCmd fp = do
msg <- readMsg
entry <- D.entryNow msg
newCmd :: String -> FilePath -> IO ()
newCmd m fp = do
entry <- D.entryNow m
appendFile fp $ D.toFile entry

readMsg :: IO String
readMsg = do
hSetBuffering stdout NoBuffering
putStr "what did you do? "
getLine

periodToDiff :: UTCTime -> Period -> UTCTime
periodToDiff cur pd = addUTCTime (-1 * periodToNominalDiffTime pd) cur

Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: idid
version: 0.1.0.0
version: 2.0.0
github: "dbalan/idid"
license: BSD3
author: "Dhananjay Balan"
Expand Down
9 changes: 3 additions & 6 deletions src/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ import Data.Time
data Args = Args CommonOpts Command
deriving Show

data Command = CommandNew
| CommandWhat {
period :: Period
}
data Command = CommandNew { message :: [String] }
| CommandWhat { period :: Period }
deriving (Show)

data CommonOpts = CommonOpts { filePath :: String }
Expand Down Expand Up @@ -69,7 +67,7 @@ parseOpts = CommonOpts
<> help "file to store data")

parseNewCommand :: Parser Command
parseNewCommand = pure (CommandNew)
parseNewCommand = CommandNew <$> (many $ argument str (metavar "MSG.."))

parseWhatCommand :: Parser Command
parseWhatCommand = CommandWhat <$> periodParser
Expand Down Expand Up @@ -98,4 +96,3 @@ periodToNominalDiffTime p
| p == Day = 24*60*60
| p == Week = 7 * periodToNominalDiffTime Day
| p == Month = 4 * periodToNominalDiffTime Week

6 changes: 0 additions & 6 deletions src/Lib.hs

This file was deleted.

0 comments on commit 4561283

Please sign in to comment.