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/1.11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
smallhadroncollider committed Mar 30, 2021
2 parents ae915de + 08fa247 commit 3c73147
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 62 deletions.
38 changes: 18 additions & 20 deletions docs/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,75 @@ GEM
public_suffix (>= 2.0.2, < 5.0)
airbrussh (1.4.0)
sshkit (>= 1.6.1, != 1.7.0)
capistrano (3.14.1)
capistrano (3.16.0)
airbrussh (>= 1.0.0)
i18n
rake (>= 10.0.0)
sshkit (>= 1.9.0)
colorator (1.1.0)
concurrent-ruby (1.1.7)
em-websocket (0.5.1)
concurrent-ruby (1.1.8)
em-websocket (0.5.2)
eventmachine (>= 0.12.9)
http_parser.rb (~> 0.6.0)
eventmachine (1.2.7)
ffi (1.13.1)
ffi (1.15.0)
forwardable-extended (2.6.0)
http_parser.rb (0.6.0)
i18n (1.8.5)
i18n (1.8.9)
concurrent-ruby (~> 1.0)
jekyll (4.1.1)
jekyll (4.2.0)
addressable (~> 2.4)
colorator (~> 1.0)
em-websocket (~> 0.5)
i18n (~> 1.0)
jekyll-sass-converter (~> 2.0)
jekyll-watch (~> 2.0)
kramdown (~> 2.1)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.0)
liquid (~> 4.0)
mercenary (~> 0.4.0)
pathutil (~> 0.9)
rouge (~> 3.0)
safe_yaml (~> 1.0)
terminal-table (~> 1.8)
terminal-table (~> 2.0)
jekyll-sass-converter (2.1.0)
sassc (> 2.0.1, < 3.0)
jekyll-watch (2.2.1)
listen (~> 3.0)
kramdown (2.3.0)
kramdown (2.3.1)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
liquid (4.0.3)
listen (3.2.1)
listen (3.5.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
mercenary (0.4.0)
multi_json (1.15.0)
net-scp (3.0.0)
net-ssh (>= 2.6.5, < 7.0.0)
net-ssh (6.1.0)
pathutil (0.16.2)
forwardable-extended (~> 2.6)
public_suffix (4.0.5)
pygments.rb (1.2.1)
multi_json (>= 1.0.0)
rake (13.0.1)
public_suffix (4.0.6)
pygments.rb (2.2.0)
rake (13.0.3)
rb-fsevent (0.10.4)
rb-inotify (0.10.1)
ffi (~> 1.0)
rexml (3.2.4)
rouge (3.21.0)
rouge (3.26.0)
safe_yaml (1.0.5)
sassc (2.4.0)
ffi (~> 1.9)
sshkit (1.21.0)
sshkit (1.21.2)
net-scp (>= 1.1.2)
net-ssh (>= 2.8.0)
terminal-table (1.8.0)
terminal-table (2.0.0)
unicode-display_width (~> 1.1, >= 1.1.1)
unicode-display_width (1.7.0)

PLATFORMS
ruby
x86_64-darwin-20

DEPENDENCIES
capistrano
Expand All @@ -84,4 +82,4 @@ DEPENDENCIES
pygments.rb

BUNDLED WITH
2.1.4
2.2.15
2 changes: 1 addition & 1 deletion docs/_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: taskell
tagline: Command-line Kanban board/task management
baseurl: ""
locale: "en"
version: 1.10.1
version: 1.11.0
destination: _site/public
exclude: [deployment, Capfile, log, Gemfile, Gemfile.lock]

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: taskell
version: '1.10.1'
version: '1.11.0'
category: Command Line Tools
author: Mark Wales
maintainer: mark@smallhadroncollider.com
Expand Down
73 changes: 43 additions & 30 deletions src/Taskell/IO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import ClassyPrelude

import Control.Monad.Reader (runReader)
import Data.Text.Encoding (decodeUtf8With)
import System.Directory (doesFileExist, getCurrentDirectory)
import System.Directory (doesFileExist, doesDirectoryExist, canonicalizePath, makeRelativeToCurrentDirectory)
import Data.Either (fromRight)

import Data.Time.Zones (TZ)

Expand Down Expand Up @@ -38,14 +39,23 @@ data Next
Lists
| Exit


getPath :: Text -> ReaderConfig FilePath
getPath path = do
config <- asks ioConfig
canonicial <- lift $ canonicalizePath (unpack path)
let defaultFilename = filename (general config)
isDir <- lift $ doesDirectoryExist canonicial
pure $ if isDir then canonicial </> defaultFilename else canonicial

parseArgs :: [Text] -> ReaderConfig Next
parseArgs ["-v"] = pure $ Output version
parseArgs ["-h"] = pure $ Output usage
parseArgs ["-t", boardID, file] = loadTrello boardID file
parseArgs ["-g", identifier, file] = loadGitHub identifier file
parseArgs ["-i", file] = fileInfo file
parseArgs [file] = loadFile file
parseArgs [] = (pack . filename . general <$> asks ioConfig) >>= loadFile
parseArgs ["-t", boardID, file] = getPath file >>= loadTrello boardID
parseArgs ["-g", identifier, file] = getPath file >>= loadGitHub identifier
parseArgs ["-i", file] = getPath file >>= fileInfo
parseArgs [file] = getPath file >>= loadFile
parseArgs [] = getPath "" >>= loadFile
parseArgs _ = pure $ Error (unlines ["Invalid options", "", usage])

load :: ReaderConfig Next
Expand All @@ -54,34 +64,41 @@ load = getArgs >>= parseArgs
colonic :: FilePath -> Text -> Text
colonic path = ((pack path <> ": ") <>)

loadFile :: Text -> ReaderConfig Next
createLoad :: FilePath -> Lists -> ReaderConfig Next
createLoad path lists = do
relative <- lift $ makeRelativeToCurrentDirectory path
pure $ Load relative lists

loadFile :: FilePath -> ReaderConfig Next
loadFile filepath = do
mPath <- exists filepath
case mPath of
Nothing -> pure Exit
Just path -> either (Error . colonic path) (Load path) <$> readData path
Just path -> do
lists <- readData path
case lists of
Left err -> pure $ Error (colonic path err)
Right ls -> createLoad path ls

loadRemote :: (token -> FilePath -> ReaderConfig Next) -> token -> Text -> ReaderConfig Next
loadRemote createFn identifier filepath = do
let path = unpack filepath
loadRemote :: (token -> FilePath -> ReaderConfig Next) -> token -> FilePath -> ReaderConfig Next
loadRemote createFn identifier path = do
exists' <- fileExists path
if exists'
then pure $ Error (filepath <> " already exists")
then pure $ Error (pack path <> " already exists")
else createFn identifier path

loadTrello :: Trello.TrelloBoardID -> Text -> ReaderConfig Next
loadTrello :: Trello.TrelloBoardID -> FilePath -> ReaderConfig Next
loadTrello = loadRemote createTrello

loadGitHub :: GitHub.GitHubIdentifier -> Text -> ReaderConfig Next
loadGitHub :: GitHub.GitHubIdentifier -> FilePath -> ReaderConfig Next
loadGitHub = loadRemote createGitHub

fileInfo :: Text -> ReaderConfig Next
fileInfo filepath = do
let path = unpack filepath
fileInfo :: FilePath -> ReaderConfig Next
fileInfo path = do
exists' <- fileExists path
if exists'
then either (Error . colonic path) (Output . analyse filepath) <$> readData path
else pure $ Error (filepath <> " does not exist")
then either (Error . colonic path) (Output . analyse (pack path)) <$> readData path
else pure $ Error (pack path <> " does not exist")

createRemote ::
(Config -> Maybe token)
Expand All @@ -99,19 +116,17 @@ createRemote tokenFn missingToken getFn identifier path = do
lists <- lift $ runReaderT (getFn identifier) token
case lists of
Left txt -> pure $ Error txt
Right ls ->
promptCreate path >>=
bool (pure Exit) (Load path ls <$ lift (writeData tz config ls path))
Right ls -> do
promptCreate path >>= bool (pure Exit) (lift (writeData tz config ls path) >> createLoad path ls)

createTrello :: Trello.TrelloBoardID -> FilePath -> ReaderConfig Next
createTrello = createRemote (Trello.token . trello) trelloUsage Trello.getLists

createGitHub :: GitHub.GitHubIdentifier -> FilePath -> ReaderConfig Next
createGitHub = createRemote (GitHub.token . github) githubUsage GitHub.getLists

exists :: Text -> ReaderConfig (Maybe FilePath)
exists filepath = do
let path = unpack filepath
exists :: FilePath -> ReaderConfig (Maybe FilePath)
exists path = do
exists' <- fileExists path
if exists'
then pure $ Just path
Expand All @@ -121,17 +136,15 @@ fileExists :: FilePath -> ReaderConfig Bool
fileExists path = lift $ doesFileExist path

promptCreate :: FilePath -> ReaderConfig Bool
promptCreate path = do
cwd <- lift $ pack <$> getCurrentDirectory
lift $ promptYN PromptYes $ concat ["Create ", cwd, "/", pack path, "?"]
promptCreate path = lift $ promptYN PromptYes $ concat ["Create ", pack path, "?"]

-- creates taskell file
createPath :: FilePath -> ReaderConfig ()
createPath path = do
config <- asks ioConfig
tz <- asks ioTZ
template <- readData =<< templatePath <$> lift getDir
let ls = either (const initial) id template
template <- readData . templatePath =<< lift getDir
let ls = fromRight initial template
lift (writeData tz config ls path)

-- writes Tasks to json file
Expand Down
4 changes: 2 additions & 2 deletions stack.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
resolver: lts-16.14
resolver: lts-17.8
pvp-bounds: both
packages:
- .
extra-deps:
- tz-0.1.3.3
- tz-0.1.3.5
16 changes: 8 additions & 8 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

packages:
- completed:
hackage: tz-0.1.3.3@sha256:b9de0c1b10825460ff14a237209a8bf7747f47979601d35621276556bf63d2ca,5086
hackage: tz-0.1.3.5@sha256:fb17ca50a7d943e511c0ca70342dc83f66aa2532de2745632f1f5f9b1ad783c4,5086
pantry-tree:
size: 1180
sha256: ae6af45f3dba5a478ea9cc77c718f955fcc5c96f2dc0f4ede34c4a15a3e85ac1
size: 1179
sha256: 6482698ea1b1a93bd684fca35836b35e8cdf53fe51b0fa6b215afa7da1f983a6
original:
hackage: tz-0.1.3.3
hackage: tz-0.1.3.5
snapshots:
- completed:
size: 532382
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/16/14.yaml
sha256: 1ef27e36f38824abafc43224ca612211b3828fa9ffd31ba0fc2867ae2e19ba90
original: lts-16.14
size: 565720
url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/17/8.yaml
sha256: 76bf8992ff8dfe6eda9c02f81866138c2369344d5011ab39ae403457c4448b03
original: lts-17.8

0 comments on commit 3c73147

Please sign in to comment.