Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/0.1.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
smallhadroncollider committed Mar 4, 2019
2 parents 7357a67 + 4e7a9c0 commit 7194239
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
3 changes: 2 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: cmt
version: 0.1.1.0
version: 0.1.2.0
github: "smallhadroncollider/cmt"
license: BSD3
author: "Small Hadron Collider / Mark Wales"
Expand Down Expand Up @@ -27,6 +27,7 @@ library:
- attoparsec
- text
- directory
- filepath
- process

executables:
Expand Down
5 changes: 4 additions & 1 deletion roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
> Store if commit fails. `cmt --prev` option?
- List option?
> Automatically adds a hyphen to each entry?
- Add comments to .cmt
- Show options in flat list if short?
- Make parts optional
> @? and !@? operators?
- Should search up directories to find .cmt
- Option to show files that have changed
> Useful for things like ${Scope} - autocomplete maybe?
- Should support ~/.cmt for global option

## Doing
Expand All @@ -27,3 +29,4 @@
- Shouldn't be able to add blank Line
- Better error message for * missing
> If ${*} detected, then say if no command line argument given
- Should search up directories to find .cmt
37 changes: 27 additions & 10 deletions src/Cmt/IO/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ module Cmt.IO.Config where
import ClassyPrelude

import Data.List (nub)
import System.Directory (doesFileExist)
import System.Directory (doesFileExist, getCurrentDirectory)
import System.FilePath (takeDirectory)

import Cmt.Parser.Config (config)
import Cmt.Types.Config

path :: FilePath
path = ".cmt"
configFile :: FilePath
configFile = ".cmt"

checkFormat :: [Output] -> Config -> Either Text (Config, [Output])
checkFormat output (Config parts format) = do
Expand All @@ -28,18 +29,34 @@ checkFormat output (Config parts format) = do
parse :: [Output] -> Text -> Either Text (Config, [Output])
parse output cfg = config cfg >>= checkFormat output

read :: IO Text
read = decodeUtf8 <$> readFile path
read :: FilePath -> IO Text
read path = decodeUtf8 <$> readFile path

parseArgs :: [Text] -> [Output]
parseArgs [] = []
parseArgs [msg] = [("*", msg)]
parseArgs parts = [("*", unwords parts)]

parentDir :: FilePath -> IO (Maybe FilePath)
parentDir path = do
let parent = takeDirectory path
if parent /= path
then findFile parent
else pure Nothing

findFile :: FilePath -> IO (Maybe FilePath)
findFile path = do
let fp = path <> "/" <> configFile
exists <- doesFileExist fp
if exists
then pure $ Just fp
else parentDir path

load :: IO (Either Text (Config, [Output]))
load = do
exists <- doesFileExist path
output <- parseArgs <$> getArgs
if exists
then parse output <$> read
else pure $ Left ".cmt file not found"
exists <- findFile =<< getCurrentDirectory
case exists of
Just path -> do
output <- parseArgs <$> getArgs
parse output <$> read path
Nothing -> pure $ Left ".cmt file not found"

0 comments on commit 7194239

Please sign in to comment.