tn 4.0.0.1 → 4.1.0.0
raw patch · 3 files changed
+40/−109 lines, 3 filesdep +optparse-helperPVP ok
version bump matches the API change (PVP)
Dependencies added: optparse-helper
API changes (from Hackage documentation)
Files
- README.md +10/−4
- bin/Main.hs +26/−104
- tn.cabal +4/−1
README.md view
@@ -4,7 +4,7 @@ [Haskell][hs] and licensed under the [ISC license][iscl]. You can find a copy of the ISC license in the [LICENSE file][license-file] -## Installing+## Installation and Usage First, install [Stack][hs-stack]. @@ -13,7 +13,7 @@ Versions of tn less than `4` are just awful, so run - $ tn version+ $ tn --version to make sure you have a decent version. else, try this: @@ -24,11 +24,17 @@ $ stack setup $ stack install +To add an entry, simply run++ $ tn "entry text"++The journal is stored in `~/.local/share/tn/`.++## Contributing+ I welcome any contributions anyone wants to make. If you find a bug or a feature request, use the [GitHub bug tracker][issues]. If you want to contribute, use the normal method of contributing to projects on GitHub.--## Contacting me You can contact me at `peter@harpending.org`, or `pharpend` on FreeNode.
bin/Main.hs view
@@ -1,112 +1,34 @@ module Main where -import Options.Applicative-import System.IO-import Tn--data Command = NewEntry Input Output- | ShowLicense Bool- | ShowVersion- deriving (Eq, Show)--data Input = Argument String- | FromFile FilePath- | Stdin- deriving (Eq, Show)--data Output = ToFile FilePath- | Stdout- | DefaultOutput- deriving (Eq, Show)+import qualified Data.ByteString as B+import Data.FileEmbed+import Options.Applicative+import Options.Applicative.Helper+import System.IO+import Tn main :: IO () main =- do result <- customExecParser tnPrefs (infoHelper tnParser tnInfo)+ do result <- helperExecParser tnParser+ (fpDesc "Simple journal-keeping program") hSetBuffering stdin NoBuffering case result of- ShowLicense noPager -> printLicense noPager- ShowVersion -> putStrLn version- NewEntry i o ->- do input <- case i of- Argument s -> return s- FromFile fp -> readFile fp- Stdin -> getContents- currentJournal <- readJournal- newJournal <- addEntry currentJournal <$> mkEntry input- case o of- Stdout -> printJournal newJournal False- ToFile f -> writeJournalFile newJournal f- DefaultOutput -> writeJournal newJournal--tnPrefs :: ParserPrefs-tnPrefs =- prefs $ mconcat [ disambiguate- , showHelpOnError- ]--infoHelper :: Parser a -> InfoMod a -> ParserInfo a-infoHelper a = info (helper <*> a)--tnInfo :: InfoMod Command-tnInfo = mconcat [ briefDesc- , progDesc "Simple journal-keeping program"- ]--tnParser :: Parser Command-tnParser =- altConcat $ fmap subparser [ licenseCmd- , versionCmd- , newEntryCmd- ]---licenseCmd :: Mod CommandFields Command-licenseCmd = - command "license" $- infoHelper licenseParser- (mappend briefDesc- (progDesc "Show the license (ISC)"))- where- licenseParser = - ShowLicense <$> switch (mconcat [ long "no-pager"- , help "Do not pipe to the system pager"- , showDefault- ])--versionCmd :: Mod CommandFields Command-versionCmd = - command "version" $- infoHelper (pure ShowVersion)- (mappend briefDesc- (progDesc "Show the version"))-- -newEntryCmd :: Mod CommandFields Command-newEntryCmd =- command "new"- (infoHelper (NewEntry <$> inputOpts <*> outputOpts)- (mappend briefDesc- (progDesc "New entry")))- where- inputOpts = - altConcat [ FromFile <$> strOption (mconcat [ help "Input file"- , metavar "PATH"- , long "input"- , short 'i'- ])- , flag' Stdin (mconcat [ help "Read entry text from stdin"- , long "stdin"- ])- , Argument <$> strArgument (mconcat [help "Entry text", metavar "TEXT"])- ]- outputOpts = altConcat [ flag' Stdout (mconcat [ help "Print to stdout instead of a file"- , long "stdout"- ])- , ToFile <$> strOption (mconcat [ help "Output file"- , metavar "PATH"- , long "output"- , short 'o'- ])- , pure DefaultOutput- ]+ ShowLicense -> B.hPut stdout $(embedFile "LICENSE")+ ShowVersion -> putStrLn version+ NewEntry i ->+ do currentJournal <- readJournal+ newJournal <- addEntry currentJournal <$> mkEntry i+ writeJournal newJournal+ where tnParser = altconcat [version', license, newEntry]+ version' = flag' ShowVersion+ (mappend (help "Print the version")+ (long "version"))+ license = flag' ShowLicense+ (mappend (help "Print the license")+ (long "license"))+ newEntry = NewEntry <$> strArgument (help "Entry text") +data Command = NewEntry String+ | ShowLicense+ | ShowVersion+ deriving (Eq, Show)
tn.cabal view
@@ -1,5 +1,5 @@ name: tn-version: 4.0.0.1+version: 4.1.0.0 synopsis: A simple daily journal program description: tn is a simple program to keep journals.@@ -57,7 +57,10 @@ TemplateHaskell build-depends: base ==4.8.*+ , bytestring+ , file-embed , optparse-applicative+ , optparse-helper , tn source-repository head