turtle-options 0.1.0.2 → 0.1.0.3
raw patch · 8 files changed
+104/−11 lines, 8 filesdep +HUnitPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependencies added: HUnit
API changes (from Hackage documentation)
- Turtle.Options.Parsers: infixr 5 <:>
- Turtle.Options.Timecode: infixr 5 <+>
+ Turtle.Options.Percentage: percentage :: Parser Float
+ Turtle.Options.Quality: quality :: Parser Float
+ Turtle.Options.Scale: scale :: Parser Scale
+ Turtle.Options.Timecode: timecode :: Parser Timecode
Files
- README.md +65/−0
- src/Turtle/Options/Parsers.hs +2/−2
- src/Turtle/Options/Percentage.hs +4/−1
- src/Turtle/Options/Quality.hs +1/−0
- src/Turtle/Options/Scale.hs +3/−1
- src/Turtle/Options/Timecode.hs +9/−1
- test/Spec.hs +14/−2
- turtle-options.cabal +6/−4
+ README.md view
@@ -0,0 +1,65 @@+Turtle options+==============++[](https://travis-ci.org/elaye/turtle-options)++This package provides additional command line options for [Turtle](https://hackage.haskell.org/package/turtle-1.2.5/docs/Turtle-Tutorial.html).++Percentage+----------++Parse a percentage (`20%`). The result is a floating point number (`Float`), corresponding to the given percentage divided by 100.++Scale+-----++Parse a scaling option in different ways. +You can specify a size (`480x320`), a width (`480x`) or a height (`x320`) or a percentage (`50%` or `0.5`, needs to be positive).++Quality+-------++Parse a quality option. This can be a percentage or a keyword (`verylow`, `low`, `mediumlow`, `medium`, `mediumhigh`, `high`, `best`). The keywords are mapped to a percentage according to the following table:++|Keyword |Percentage|+| --------- | -------- |+|verylow | 10%|+|low | 20%|+|mediumlow | 35%|+|medium | 50%|+|mediumhigh | 65%|+|high | 80%|+|veryhigh | 90%|+|best | 100%|++Timecode+--------++Parse a timecode. +A timecode is made of a number of hours, minutes, seconds and milliseconds. +The time code can be given in different formats.+You don't have to give a number of seconds or minutes inferior to 60. For example if you give 75 minutes, it will be interpreted as 1 hour and 15 minutes. +You can also provide a number of milliseconds superior to 1000.+The only required number is the number of seconds. +The following table gives examples of valid timecodes and how they are interpreted:++| Timecode | Result |+| ---------- | ------------------------------------ |+| 3 | 3 secs |+| 75 | 1 min 15 secs |+| 17:12 | 17 mins 12 secs |+| 80:23 | 1 hour 20 mins 23 secs |+| 54:32:10 | 54 hours 32 mins 10 secs |+| 43.7 | 43 secs 700 millisecs |+| 4:13.85 | 4 mins 13 secs 850 millisecs |+| 7:4:13.437 | 7 hours 4 mins 13 secs 437 millisecs |+| 5.2150 | 7 secs 150 milliseconds |++You can also use the 00h00m00s000 format if you prefer. The same rules apply:++ 1h34m12s345 gives 1 hour 34 mins 12 secs and 345 millisecs++A timecode can be negative: ++ -3:45 (or -3m45) gives minus 3 mins and 45 secs+
src/Turtle/Options/Parsers.hs view
@@ -8,7 +8,7 @@ , (<:>) ) where -import Control.Applicative ((<$>), (<*>), (<*), (*>))+import Control.Applicative (Applicative, (<$>), (<*>), (<*), (*>)) import Text.Parsec (Parsec, many1, digit, char, option, oneOf, (<|>)) @@ -42,4 +42,4 @@ exponent = option "" $ oneOf "eE" <:> integer percent :: Parser Float-percent = float <* char '%'+percent = (/100) <$> float <* char '%'
src/Turtle/Options/Percentage.hs view
@@ -3,6 +3,7 @@ module Turtle.Options.Percentage ( optPercentage , defPercentageHelp+, percentage ) where import Turtle (ArgName, ShortName, HelpMessage, opt)@@ -10,6 +11,8 @@ import qualified Turtle import qualified Data.Text as Text +import Control.Applicative ((<$>))+ import Text.Parsec import Turtle.Options.Parsers (Parser, percent, float)@@ -18,7 +21,7 @@ defPercentageHelp = "Percentage: can be a positive or negative percentage (-43%), represented with a float." percentage :: Parser Float-percentage = try ((/100) <$> percent)+percentage = try percent readPercentage :: String -> Maybe Float readPercentage str = case (parse percentage "Percentage (Float)" str) of
src/Turtle/Options/Quality.hs view
@@ -3,6 +3,7 @@ module Turtle.Options.Quality ( optQuality , defQualityHelp+, quality ) where import Turtle (ArgName, ShortName, HelpMessage, opt)
src/Turtle/Options/Scale.hs view
@@ -4,12 +4,14 @@ ( Scale(..) , optScale , defScaleHelp+, scale ) where import Turtle (ArgName, ShortName, HelpMessage, opt) import Data.Optional (Optional) import qualified Turtle import qualified Data.Text as Text+import Control.Applicative ((<$>), (<*>), (*>), (<*)) import Text.Parsec @@ -49,7 +51,7 @@ v <- percent case v < 0 of True -> error "Error parsing scale percentage: can't have a negative value"- False -> return $ Percentage (v / 100)+ False -> return $ Percentage v scale :: Parser Scale scale = choice [size, percentage, width, height]
src/Turtle/Options/Timecode.hs view
@@ -5,6 +5,7 @@ , RelTimecode(..) , optTimecode , defTimecodeHelp+, timecode , msToTimecode , sToTimecode , mToTimecode@@ -19,6 +20,7 @@ --import Data.Monoid (Sum, (<>)) import Data.Monoid (Monoid, mappend)+import Control.Applicative ((<$>), (<*>), (*>)) import Text.Parsec import Text.ParserCombinators.Parsec.Error (Message(..), newErrorMessage)@@ -76,7 +78,13 @@ normalTimecode = do --plus <|> minus ts <- number `sepBy1` char ':'- ms <- read <$> (option "0" $ char '.' *> number)+ --ms <- read <$> (option "0" $ char '.' *> number)+ msStr <- option "0" $ char '.' *> number+ let ms = read $ case (length msStr) of+ 1 -> (msStr ++ "00")+ 2 -> msStr ++ "0"+ _ -> msStr+ return $ case (fmap read ts) of (h:m:s:[]) -> toTimecode h m s ms (m:s:[]) -> toTimecode 0 m s ms
test/Spec.hs view
@@ -1,2 +1,14 @@-main :: IO ()-main = putStrLn "Test suite not yet implemented"+import Test.HUnit++import qualified Scale.Tests+import qualified Quality.Tests+import qualified Percentage.Tests+import qualified Timecode.Tests++main :: IO Counts+main = runTestTT $ TestList+ [ Scale.Tests.tests+ , Quality.Tests.tests+ , Percentage.Tests.tests+ , Timecode.Tests.tests+ ]
turtle-options.cabal view
@@ -1,8 +1,8 @@ name: turtle-options-version: 0.1.0.2+version: 0.1.0.3 synopsis: Collection of command line options and parsers for these options description: Please see README.md-homepage: http://github.com/githubuser/turtle-options#readme+homepage: https://github.com/elaye/turtle-options#readme license: BSD3 license-file: LICENSE author: Elie Genard@@ -10,7 +10,7 @@ copyright: 2016 Elie Genard category: Utils build-type: Simple--- extra-source-files:+extra-source-files: README.md cabal-version: >=1.10 library@@ -42,9 +42,11 @@ main-is: Spec.hs build-depends: base , turtle-options+ , HUnit+ , parsec ghc-options: -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010 source-repository head type: git- location: https://github.com/githubuser/turtle-options+ location: https://github.com/elaye/turtle-options