| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Hledger.Cli.Script
Description
A convenient module to import in hledger scripts, aiming to provide the most useful imports and reduce boilerplate. |
Synopsis
- module Control.Applicative
- module Control.Concurrent
- module Control.Monad
- module Data.Char
- module Data.Either
- module Data.List
- module Data.Maybe
- module Data.Ord
- module Data.Time
- module Hledger
- module Hledger.Cli.CliOptions
- module Hledger.Cli.Commands
- module Hledger.Cli.CompoundBalanceCommand
- module Hledger.Cli.DocFiles
- module Hledger.Cli.Utils
- module Hledger.Cli.Version
- module System.Directory
- module System.Environment
- module System.Exit
- module System.IO
- module System.IO.Error
- module System.Process
- process :: Mode a -> [String] -> Either String a
- data Text
- ($>) :: Functor f => f a -> b -> f b
- type Name = String
- formatRealFloat :: RealFloat a => a -> FieldFormatter
- (<&>) :: Functor f => f a -> (a -> b) -> f b
- data Arg a = Arg {}
- type ModifierParser = String -> FormatParse
- type FieldFormatter = FieldFormat -> ShowS
- data FormatParse = FormatParse {}
- data FieldFormat = FieldFormat {}
- data FormatSign
- data FormatAdjustment
- class IsChar c where
- class PrintfArg a where
- formatArg :: a -> FieldFormatter
- parseFormat :: a -> ModifierParser
- class HPrintfType t
- class PrintfType t
- printf :: PrintfType r => String -> r
- hPrintf :: HPrintfType r => Handle -> String -> r
- vFmt :: Char -> FieldFormat -> FieldFormat
- formatChar :: Char -> FieldFormatter
- formatInt :: (Integral a, Bounded a) => a -> FieldFormatter
- formatInteger :: Integer -> FieldFormatter
- perror :: String -> a
- errorBadFormat :: Char -> a
- errorShortFormat :: a
- errorMissingArgument :: a
- errorBadArgument :: a
- pack :: String -> Text
- unpack :: Text -> String
- expandArgsAt :: [String] -> IO [String]
- joinArgs :: [String] -> String
- splitArgs :: String -> [String]
- class Remap (m :: Type -> Type) where
- remap :: (a -> b) -> (b -> (a, a -> b)) -> m a -> m b
- data Flag a = Flag {}
- type Update a = String -> a -> Either String a
- data FlagInfo
- data Mode a = Mode {
- modeGroupModes :: Group (Mode a)
- modeNames :: [Name]
- modeValue :: a
- modeCheck :: a -> Either String a
- modeReform :: a -> Maybe [String]
- modeExpandAt :: Bool
- modeHelp :: Help
- modeHelpSuffix :: [String]
- modeArgs :: ([Arg a], Maybe (Arg a))
- modeGroupFlags :: Group (Flag a)
- data Group a = Group {
- groupUnnamed :: [a]
- groupHidden :: [a]
- groupNamed :: [(Help, [a])]
- type FlagHelp = String
- type Help = String
- parseBool :: String -> Maybe Bool
- fromGroup :: Group a -> [a]
- toGroup :: [a] -> Group a
- modeModes :: Mode a -> [Mode a]
- modeFlags :: Mode a -> [Flag a]
- fromFlagOpt :: FlagInfo -> String
- checkMode :: Mode a -> Maybe String
- remap2 :: Remap m => (a -> b) -> (b -> a) -> m a -> m b
- remapUpdate :: (a -> b) -> (b -> (a, a -> b)) -> Update a -> Update b
- modeEmpty :: a -> Mode a
- mode :: Name -> a -> Help -> Arg a -> [Flag a] -> Mode a
- modes :: String -> a -> Help -> [Mode a] -> Mode a
- flagNone :: [Name] -> (a -> a) -> Help -> Flag a
- flagOpt :: String -> [Name] -> Update a -> FlagHelp -> Help -> Flag a
- flagReq :: [Name] -> Update a -> FlagHelp -> Help -> Flag a
- flagArg :: Update a -> FlagHelp -> Arg a
- flagBool :: [Name] -> (Bool -> a -> a) -> Help -> Flag a
- data Complete
- complete :: Mode a -> [String] -> (Int, Int) -> [Complete]
- data HelpFormat
- helpText :: [String] -> HelpFormat -> Mode a -> [Text]
- processArgs :: Mode a -> IO a
- processValue :: Mode a -> [String] -> a
- processValueIO :: Mode a -> [String] -> IO a
- flagHelpSimple :: (a -> a) -> Flag a
- flagHelpFormat :: (HelpFormat -> TextFormat -> a -> a) -> Flag a
- flagVersion :: (a -> a) -> Flag a
- flagNumericVersion :: (a -> a) -> Flag a
- flagsVerbosity :: (Verbosity -> a -> a) -> [Flag a]
- searchPathSeparator :: Char
- normalise :: FilePath -> FilePath
- dropTrailingPathSeparator :: FilePath -> FilePath
- makeRelative :: FilePath -> FilePath -> FilePath
- (</>) :: FilePath -> FilePath -> FilePath
- headDef :: a -> [a] -> a
- lastDef :: a -> [a] -> a
- pathSeparator :: Char
- pathSeparators :: [Char]
- isPathSeparator :: Char -> Bool
- isSearchPathSeparator :: Char -> Bool
- extSeparator :: Char
- isExtSeparator :: Char -> Bool
- splitSearchPath :: String -> [FilePath]
- getSearchPath :: IO [FilePath]
- splitExtension :: FilePath -> (String, String)
- takeExtension :: FilePath -> String
- (-<.>) :: FilePath -> String -> FilePath
- replaceExtension :: FilePath -> String -> FilePath
- (<.>) :: FilePath -> String -> FilePath
- dropExtension :: FilePath -> FilePath
- addExtension :: FilePath -> String -> FilePath
- hasExtension :: FilePath -> Bool
- isExtensionOf :: String -> FilePath -> Bool
- stripExtension :: String -> FilePath -> Maybe FilePath
- splitExtensions :: FilePath -> (FilePath, String)
- dropExtensions :: FilePath -> FilePath
- takeExtensions :: FilePath -> String
- replaceExtensions :: FilePath -> String -> FilePath
- splitDrive :: FilePath -> (FilePath, FilePath)
- joinDrive :: FilePath -> FilePath -> FilePath
- takeDrive :: FilePath -> FilePath
- dropDrive :: FilePath -> FilePath
- hasDrive :: FilePath -> Bool
- isDrive :: FilePath -> Bool
- splitFileName :: FilePath -> (String, String)
- replaceFileName :: FilePath -> String -> FilePath
- dropFileName :: FilePath -> FilePath
- takeFileName :: FilePath -> FilePath
- takeBaseName :: FilePath -> String
- replaceBaseName :: FilePath -> String -> FilePath
- hasTrailingPathSeparator :: FilePath -> Bool
- addTrailingPathSeparator :: FilePath -> FilePath
- takeDirectory :: FilePath -> FilePath
- replaceDirectory :: FilePath -> String -> FilePath
- combine :: FilePath -> FilePath -> FilePath
- splitPath :: FilePath -> [FilePath]
- splitDirectories :: FilePath -> [FilePath]
- joinPath :: [FilePath] -> FilePath
- equalFilePath :: FilePath -> FilePath -> Bool
- isValid :: FilePath -> Bool
- makeValid :: FilePath -> FilePath
- isRelative :: FilePath -> Bool
- isAbsolute :: FilePath -> Bool
- foldl1May :: (a -> a -> a) -> [a] -> Maybe a
- foldr1May :: (a -> a -> a) -> [a] -> Maybe a
- foldl1Note :: Partial => String -> (a -> a -> a) -> [a] -> a
- foldr1Note :: Partial => String -> (a -> a -> a) -> [a] -> a
- minimumMay :: Ord a => [a] -> Maybe a
- maximumMay :: Ord a => [a] -> Maybe a
- minimumNote :: (Partial, Ord a) => String -> [a] -> a
- maximumNote :: (Partial, Ord a) => String -> [a] -> a
- minimumByMay :: (a -> a -> Ordering) -> [a] -> Maybe a
- maximumByMay :: (a -> a -> Ordering) -> [a] -> Maybe a
- minimumByNote :: Partial => String -> (a -> a -> Ordering) -> [a] -> a
- maximumByNote :: Partial => String -> (a -> a -> Ordering) -> [a] -> a
- maximumBoundBy :: a -> (a -> a -> Ordering) -> [a] -> a
- minimumBoundBy :: a -> (a -> a -> Ordering) -> [a] -> a
- maximumBound :: Ord a => a -> [a] -> a
- minimumBound :: Ord a => a -> [a] -> a
- maximumBounded :: (Ord a, Bounded a) => [a] -> a
- minimumBounded :: (Ord a, Bounded a) => [a] -> a
- findJust :: (a -> Bool) -> [a] -> a
- findJustDef :: a -> (a -> Bool) -> [a] -> a
- findJustNote :: Partial => String -> (a -> Bool) -> [a] -> a
- minimumDef :: Ord a => a -> [a] -> a
- maximumDef :: Ord a => a -> [a] -> a
- minimumByDef :: a -> (a -> a -> Ordering) -> [a] -> a
- maximumByDef :: a -> (a -> a -> Ordering) -> [a] -> a
- foldl1Def :: a -> (a -> a -> a) -> [a] -> a
- foldr1Def :: a -> (a -> a -> a) -> [a] -> a
- abort :: Partial => String -> a
- tailErr :: Partial => [a] -> [a]
- headErr :: Partial => [a] -> a
- tailMay :: [a] -> Maybe [a]
- tailDef :: [a] -> [a] -> [a]
- tailNote :: Partial => String -> [a] -> [a]
- tailSafe :: [a] -> [a]
- initMay :: [a] -> Maybe [a]
- initDef :: [a] -> [a] -> [a]
- initNote :: Partial => String -> [a] -> [a]
- initSafe :: [a] -> [a]
- headMay :: [a] -> Maybe a
- lastMay :: [a] -> Maybe a
- headNote :: Partial => String -> [a] -> a
- lastNote :: Partial => String -> [a] -> a
- foldl1May' :: (a -> a -> a) -> [a] -> Maybe a
- foldl1Note' :: Partial => String -> (a -> a -> a) -> [a] -> a
- scanr1May :: (a -> a -> a) -> [a] -> Maybe [a]
- scanl1May :: (a -> a -> a) -> [a] -> Maybe [a]
- scanr1Def :: [a] -> (a -> a -> a) -> [a] -> [a]
- scanl1Def :: [a] -> (a -> a -> a) -> [a] -> [a]
- scanr1Note :: Partial => String -> (a -> a -> a) -> [a] -> [a]
- scanl1Note :: Partial => String -> (a -> a -> a) -> [a] -> [a]
- cycleMay :: [a] -> Maybe [a]
- cycleDef :: [a] -> [a] -> [a]
- cycleNote :: Partial => String -> [a] -> [a]
- fromJustDef :: a -> Maybe a -> a
- fromJustNote :: Partial => String -> Maybe a -> a
- assertNote :: Partial => String -> Bool -> a -> a
- atMay :: [a] -> Int -> Maybe a
- atDef :: a -> [a] -> Int -> a
- atNote :: Partial => String -> [a] -> Int -> a
- readEitherSafe :: Read a => String -> Either String a
- readMay :: Read a => String -> Maybe a
- readDef :: Read a => a -> String -> a
- readNote :: (Partial, Read a) => String -> String -> a
- lookupJust :: (Eq a, Partial) => a -> [(a, b)] -> b
- lookupJustDef :: Eq a => b -> a -> [(a, b)] -> b
- lookupJustNote :: (Partial, Eq a) => String -> a -> [(a, b)] -> b
- elemIndexJust :: (Partial, Eq a) => a -> [a] -> Int
- elemIndexJustDef :: Eq a => Int -> a -> [a] -> Int
- elemIndexJustNote :: (Partial, Eq a) => String -> a -> [a] -> Int
- findIndexJust :: (a -> Bool) -> [a] -> Int
- findIndexJustDef :: Int -> (a -> Bool) -> [a] -> Int
- findIndexJustNote :: Partial => String -> (a -> Bool) -> [a] -> Int
- toEnumMay :: (Enum a, Bounded a) => Int -> Maybe a
- toEnumDef :: (Enum a, Bounded a) => a -> Int -> a
- toEnumNote :: (Partial, Enum a, Bounded a) => String -> Int -> a
- toEnumSafe :: (Enum a, Bounded a) => Int -> a
- succMay :: (Enum a, Eq a, Bounded a) => a -> Maybe a
- succDef :: (Enum a, Eq a, Bounded a) => a -> a -> a
- succNote :: (Partial, Enum a, Eq a, Bounded a) => String -> a -> a
- succSafe :: (Enum a, Eq a, Bounded a) => a -> a
- predMay :: (Enum a, Eq a, Bounded a) => a -> Maybe a
- predDef :: (Enum a, Eq a, Bounded a) => a -> a -> a
- predNote :: (Partial, Enum a, Eq a, Bounded a) => String -> a -> a
- predSafe :: (Enum a, Eq a, Bounded a) => a -> a
- indexMay :: Ix a => (a, a) -> a -> Maybe Int
- indexDef :: Ix a => Int -> (a, a) -> a -> Int
- indexNote :: (Partial, Ix a) => String -> (a, a) -> a -> Int
- foldl1Def' :: a -> (a -> a -> a) -> [a] -> a
- argsToCliOpts :: [String] -> [String] -> IO CliOpts
Documentation
module Control.Applicative
module Control.Concurrent
module Control.Monad
module Data.Char
module Data.Either
module Data.List
module Data.Maybe
module Data.Ord
module Data.Time
module Hledger
module Hledger.Cli.CliOptions
module Hledger.Cli.Commands
module Hledger.Cli.DocFiles
module Hledger.Cli.Utils
module Hledger.Cli.Version
module System.Directory
module System.Environment
module System.Exit
module System.IO
module System.IO.Error
module System.Process
A space efficient, packed, unboxed Unicode text type.
Instances
| ToJSON Text | |||||||||
| ToJSONKey Text | |||||||||
Defined in Data.Aeson.Types.ToJSON Methods | |||||||||
| Chunk Text | |||||||||
Defined in Data.Attoparsec.Internal.Types Associated Types
Methods pappendChunk :: State Text -> Text -> State Text atBufferEnd :: Text -> State Text -> Pos bufferElemAt :: Text -> Pos -> State Text -> Maybe (ChunkElem Text, Int) chunkElemToChar :: Text -> ChunkElem Text -> Char | |||||||||
| PrintfArg Text | Since: text-1.2.2.0 | ||||||||
Defined in Data.Text | |||||||||
| Binary Text | Since: text-1.2.1.0 | ||||||||
| FoldCase Text | |||||||||
Defined in Data.CaseInsensitive.Internal | |||||||||
| NFData Text | |||||||||
| Monoid Text | |||||||||
| Semigroup Text | Beware: Since: text-1.2.2.0 | ||||||||
| Data Text | This instance preserves data abstraction at the cost of inefficiency. We omit reflection services for the sake of data abstraction. This instance was created by copying the updated behavior of
The original discussion is archived here: could we get a Data instance for Data.Text.Text? The followup discussion that changed the behavior of | ||||||||
Defined in Data.Text Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Text -> c Text Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Text Source # toConstr :: Text -> Constr Source # dataTypeOf :: Text -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Text) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Text) Source # gmapT :: (forall b. Data b => b -> b) -> Text -> Text Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Text -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Text -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Text -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Text -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Text -> m Text Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Text -> m Text Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Text -> m Text Source # | |||||||||
| IsString Text | Performs replacement on invalid scalar values:
| ||||||||
| IsList Text | Performs replacement on invalid scalar values:
Since: text-1.2.0.0 | ||||||||
| Read Text | |||||||||
| Show CsvRules | |||||||||
| Show Text | |||||||||
| Eq CsvRules | |||||||||
| Eq Text | |||||||||
| Ord Text | |||||||||
| Hashable Text | |||||||||
| Anon Text Source # | |||||||||
| HasAmounts AccountTransactionsReportItem | |||||||||
| HasAmounts BalanceReportItem | |||||||||
Defined in Hledger.Reports.BalanceReport Methods styleAmounts :: Map CommoditySymbol AmountStyle -> BalanceReportItem -> BalanceReportItem Source # | |||||||||
| HasAmounts PostingsReportItem | |||||||||
Defined in Hledger.Reports.PostingsReport Methods styleAmounts :: Map CommoditySymbol AmountStyle -> PostingsReportItem -> PostingsReportItem Source # | |||||||||
| FromFormKey Text | |||||||||
Defined in Web.Internal.FormUrlEncoded Methods parseFormKey :: Text -> Either Text Text | |||||||||
| ToFormKey Text | |||||||||
Defined in Web.Internal.FormUrlEncoded | |||||||||
| QueryKeyLike Text | |||||||||
Defined in Network.HTTP.Types.QueryLike Methods toQueryKey :: Text -> ByteString Source # | |||||||||
| QueryValueLike Text | |||||||||
Defined in Network.HTTP.Types.QueryLike Methods toQueryValue :: Text -> Maybe ByteString Source # | |||||||||
| ToHtml Text | |||||||||
| Stream Text | |||||||||
Defined in Text.Megaparsec.Stream Associated Types
Methods tokenToChunk :: Proxy Text -> Token Text -> Tokens Text tokensToChunk :: Proxy Text -> [Token Text] -> Tokens Text chunkToTokens :: Proxy Text -> Tokens Text -> [Token Text] chunkLength :: Proxy Text -> Tokens Text -> Int chunkEmpty :: Proxy Text -> Tokens Text -> Bool take1_ :: Text -> Maybe (Token Text, Text) takeN_ :: Int -> Text -> Maybe (Tokens Text, Text) takeWhile_ :: (Token Text -> Bool) -> Text -> (Tokens Text, Text) | |||||||||
| TraversableStream Text | |||||||||
Defined in Text.Megaparsec.Stream Methods reachOffset :: Int -> PosState Text -> (Maybe String, PosState Text) reachOffsetNoLine :: Int -> PosState Text -> PosState Text | |||||||||
| VisualStream Text | |||||||||
Defined in Text.Megaparsec.Stream | |||||||||
| Pretty Text | |||||||||
Defined in Prettyprinter.Internal | |||||||||
| Extract Text | |||||||||
| Uncons Text | |||||||||
| ToHamletData Text | |||||||||
Defined in Text.Hamlet.Runtime Methods toHamletData :: Text -> HamletData | |||||||||
| ToCss Text | |||||||||
Defined in Text.Internal.Css | |||||||||
| RawJS Text | |||||||||
Defined in Text.Julius | |||||||||
| ToJavascript Text | |||||||||
Defined in Text.Julius Methods toJavascript :: Text -> Javascript | |||||||||
| ToMessage Text | |||||||||
Defined in Text.Shakespeare.I18N | |||||||||
| ToText Text | |||||||||
Defined in Text.Shakespeare.Text | |||||||||
| Term Text Attribute | |||||||||
| TermRaw Text Attribute | |||||||||
Defined in Lucid.Base | |||||||||
| RegexLike Regex Text | |||||||||
Defined in Text.Regex.TDFA.Text | |||||||||
| RenderMessage master Text | |||||||||
Defined in Text.Shakespeare.I18N Methods renderMessage :: master -> [Lang] -> Text -> Text | |||||||||
| Lift Text | Since: text-1.2.4.0 | ||||||||
| RegexContext Regex Text Text | |||||||||
| RegexMaker Regex CompOption ExecOption Text | |||||||||
Defined in Text.Regex.TDFA.Text Methods makeRegexOpts :: CompOption -> ExecOption -> Text -> Regex makeRegexM :: MonadFail m => Text -> m Regex makeRegexOptsM :: MonadFail m => CompOption -> ExecOption -> Text -> m Regex | |||||||||
| (Monad m, a ~ ()) => TermRaw Text (HtmlT m a) | |||||||||
Defined in Lucid.Base | |||||||||
| Stream (NoShareInput Text) | |||||||||
Defined in Text.Megaparsec.Stream Methods tokenToChunk :: Proxy (NoShareInput Text) -> Token (NoShareInput Text) -> Tokens (NoShareInput Text) tokensToChunk :: Proxy (NoShareInput Text) -> [Token (NoShareInput Text)] -> Tokens (NoShareInput Text) chunkToTokens :: Proxy (NoShareInput Text) -> Tokens (NoShareInput Text) -> [Token (NoShareInput Text)] chunkLength :: Proxy (NoShareInput Text) -> Tokens (NoShareInput Text) -> Int chunkEmpty :: Proxy (NoShareInput Text) -> Tokens (NoShareInput Text) -> Bool take1_ :: NoShareInput Text -> Maybe (Token (NoShareInput Text), NoShareInput Text) takeN_ :: Int -> NoShareInput Text -> Maybe (Tokens (NoShareInput Text), NoShareInput Text) takeWhile_ :: (Token (NoShareInput Text) -> Bool) -> NoShareInput Text -> (Tokens (NoShareInput Text), NoShareInput Text) | |||||||||
| Stream (ShareInput Text) | |||||||||
Defined in Text.Megaparsec.Stream Methods tokenToChunk :: Proxy (ShareInput Text) -> Token (ShareInput Text) -> Tokens (ShareInput Text) tokensToChunk :: Proxy (ShareInput Text) -> [Token (ShareInput Text)] -> Tokens (ShareInput Text) chunkToTokens :: Proxy (ShareInput Text) -> Tokens (ShareInput Text) -> [Token (ShareInput Text)] chunkLength :: Proxy (ShareInput Text) -> Tokens (ShareInput Text) -> Int chunkEmpty :: Proxy (ShareInput Text) -> Tokens (ShareInput Text) -> Bool take1_ :: ShareInput Text -> Maybe (Token (ShareInput Text), ShareInput Text) takeN_ :: Int -> ShareInput Text -> Maybe (Tokens (ShareInput Text), ShareInput Text) takeWhile_ :: (Token (ShareInput Text) -> Bool) -> ShareInput Text -> (Tokens (ShareInput Text), ShareInput Text) | |||||||||
| ToAttributes [(Text, Text)] | |||||||||
Defined in Text.Hamlet Methods toAttributes :: [(Text, Text)] -> [(Text, Text)] | |||||||||
| Ord (ParseError Text HledgerParseErrorData) | |||||||||
Defined in Hledger.Utils.Parse Methods compare :: ParseError Text HledgerParseErrorData -> ParseError Text HledgerParseErrorData -> Ordering Source # (<) :: ParseError Text HledgerParseErrorData -> ParseError Text HledgerParseErrorData -> Bool Source # (<=) :: ParseError Text HledgerParseErrorData -> ParseError Text HledgerParseErrorData -> Bool Source # (>) :: ParseError Text HledgerParseErrorData -> ParseError Text HledgerParseErrorData -> Bool Source # (>=) :: ParseError Text HledgerParseErrorData -> ParseError Text HledgerParseErrorData -> Bool Source # max :: ParseError Text HledgerParseErrorData -> ParseError Text HledgerParseErrorData -> ParseError Text HledgerParseErrorData Source # min :: ParseError Text HledgerParseErrorData -> ParseError Text HledgerParseErrorData -> ParseError Text HledgerParseErrorData Source # | |||||||||
| ToAttributes (Text, Text) | |||||||||
Defined in Text.Hamlet Methods toAttributes :: (Text, Text) -> [(Text, Text)] | |||||||||
| HasAmounts b => HasAmounts (Text, PeriodicReport a b, Bool) | |||||||||
Defined in Hledger.Reports.ReportTypes Methods styleAmounts :: Map CommoditySymbol AmountStyle -> (Text, PeriodicReport a b, Bool) -> (Text, PeriodicReport a b, Bool) Source # | |||||||||
| type ChunkElem Text | |||||||||
Defined in Data.Attoparsec.Internal.Types | |||||||||
| type State Text | |||||||||
Defined in Data.Attoparsec.Internal.Types type State Text = Buffer | |||||||||
| type Item Text | |||||||||
| type Token Text | |||||||||
Defined in Text.Megaparsec.Stream | |||||||||
| type Tokens Text | |||||||||
Defined in Text.Megaparsec.Stream | |||||||||
| type Token (NoShareInput Text) | |||||||||
Defined in Text.Megaparsec.Stream | |||||||||
| type Token (ShareInput Text) | |||||||||
Defined in Text.Megaparsec.Stream | |||||||||
| type Tokens (NoShareInput Text) | |||||||||
Defined in Text.Megaparsec.Stream | |||||||||
| type Tokens (ShareInput Text) | |||||||||
Defined in Text.Megaparsec.Stream | |||||||||
($>) :: Functor f => f a -> b -> f b infixl 4 Source #
Flipped version of <$.
Examples
Replace the contents of a with a constant
Maybe IntString:
>>>Nothing $> "foo"Nothing
>>>Just 90210 $> "foo"Just "foo"
Replace the contents of an
with a constant Either Int IntString, resulting in an :Either
Int String
>>>Left 8675309 $> "foo"Left 8675309
>>>Right 8675309 $> "foo"Right "foo"
Replace each element of a list with a constant String:
>>>[1,2,3] $> "foo"["foo","foo","foo"]
Replace the second element of a pair with a constant String:
>>>(1,2) $> "foo"(1,"foo")
Since: base-4.7.0.0
formatRealFloat :: RealFloat a => a -> FieldFormatter Source #
Formatter for RealFloat values.
Since: base-4.7.0.0
Instances
| Remap Arg | |
Defined in System.Console.CmdArgs.Explicit.Type | |
| Packer a => Packer (Arg a) | |
Defined in System.Console.CmdArgs.Helper | |
| Show (Arg a) | |
type ModifierParser = String -> FormatParse Source #
Type of a function that will parse modifier characters from the format string.
Since: base-4.7.0.0
type FieldFormatter = FieldFormat -> ShowS Source #
This is the type of a field formatter reified over its argument.
Since: base-4.7.0.0
data FormatParse Source #
The "format parser" walks over argument-type-specific modifier characters to find the primary format character. This is the type of its result.
Since: base-4.7.0.0
Constructors
| FormatParse | |
data FieldFormat Source #
Description of field formatting for formatArg. See UNIX printf(3)
for a description of how field formatting works.
Since: base-4.7.0.0
Constructors
| FieldFormat | |
Fields
| |
data FormatSign Source #
How to handle the sign of a numeric field. These are
mutually exclusive, with SignPlus taking precedence.
Since: base-4.7.0.0
data FormatAdjustment Source #
Whether to left-adjust or zero-pad a field. These are
mutually exclusive, with LeftAdjust taking precedence.
Since: base-4.7.0.0
Constructors
| LeftAdjust | |
| ZeroPad |
This class, with only the one instance, is used as
a workaround for the fact that String, as a concrete
type, is not allowable as a typeclass instance. IsChar
is exported for backward-compatibility.
class PrintfArg a where Source #
Typeclass of printf-formattable values. The formatArg method
takes a value and a field format descriptor and either fails due
to a bad descriptor or produces a ShowS as the result. The
default parseFormat expects no modifiers: this is the normal
case. Minimal instance: formatArg.
Minimal complete definition
Methods
formatArg :: a -> FieldFormatter Source #
Since: base-4.7.0.0
parseFormat :: a -> ModifierParser Source #
Since: base-4.7.0.0
Instances
class HPrintfType t Source #
The HPrintfType class provides the variable argument magic for
hPrintf. Its implementation is intentionally not visible from
this module.
Minimal complete definition
hspr
Instances
| a ~ () => HPrintfType (IO a) | Since: base-4.7.0.0 |
Defined in Text.Printf | |
| (PrintfArg a, HPrintfType r) => HPrintfType (a -> r) | Since: base-2.1 |
Defined in Text.Printf | |
class PrintfType t Source #
The PrintfType class provides the variable argument magic for
printf. Its implementation is intentionally not visible from
this module. If you attempt to pass an argument of a type which
is not an instance of this class to printf or hPrintf, then
the compiler will report it as a missing instance of PrintfArg.
Minimal complete definition
spr
Instances
| a ~ () => PrintfType (IO a) | Since: base-4.7.0.0 |
Defined in Text.Printf | |
| IsChar c => PrintfType [c] | Since: base-2.1 |
Defined in Text.Printf | |
| (PrintfArg a, PrintfType r) => PrintfType (a -> r) | Since: base-2.1 |
Defined in Text.Printf | |
printf :: PrintfType r => String -> r Source #
Format a variable number of arguments with the C-style formatting string.
>>>printf "%s, %d, %.4f" "hello" 123 pihello, 123, 3.1416
The return value is either String or ( (which
should be IO a)(, but Haskell's type system
makes this hard).IO ())
The format string consists of ordinary characters and
conversion specifications, which specify how to format
one of the arguments to printf in the output string. A
format specification is introduced by the % character;
this character can be self-escaped into the format string
using %%. A format specification ends with a
format character that provides the primary information about
how to format the value. The rest of the conversion
specification is optional. In order, one may have flag
characters, a width specifier, a precision specifier, and
type-specific modifier characters.
Unlike C printf(3), the formatting of this printf
is driven by the argument type; formatting is type specific. The
types formatted by printf "out of the box" are:
printf is also extensible to support other types: see below.
A conversion specification begins with the
character %, followed by zero or more of the following flags:
- left adjust (default is right adjust) + always use a sign (+ or -) for signed conversions space leading space for positive numbers in signed conversions 0 pad with zeros rather than spaces # use an \"alternate form\": see below
When both flags are given, - overrides 0 and + overrides space.
A negative width specifier in a * conversion is treated as
positive but implies the left adjust flag.
The "alternate form" for unsigned radix conversions is
as in C printf(3):
%o prefix with a leading 0 if needed %x prefix with a leading 0x if nonzero %X prefix with a leading 0X if nonzero %b prefix with a leading 0b if nonzero %[eEfFgG] ensure that the number contains a decimal point
Any flags are followed optionally by a field width:
num field width * as num, but taken from argument list
The field width is a minimum, not a maximum: it will be expanded as needed to avoid mutilating a value.
Any field width is followed optionally by a precision:
.num precision . same as .0 .* as num, but taken from argument list
Negative precision is taken as 0. The meaning of the precision depends on the conversion type.
Integral minimum number of digits to show RealFloat number of digits after the decimal point String maximum number of characters
The precision for Integral types is accomplished by zero-padding. If both precision and zero-pad are given for an Integral field, the zero-pad is ignored.
Any precision is followed optionally for Integral types by a width modifier; the only use of this modifier being to set the implicit size of the operand for conversion of a negative operand to unsigned:
hh Int8 h Int16 l Int32 ll Int64 L Int64
The specification ends with a format character:
c character Integral d decimal Integral o octal Integral x hexadecimal Integral X hexadecimal Integral b binary Integral u unsigned decimal Integral f floating point RealFloat F floating point RealFloat g general format float RealFloat G general format float RealFloat e exponent format float RealFloat E exponent format float RealFloat s string String v default format any type
The "%v" specifier is provided for all built-in types, and should be provided for user-defined type formatters as well. It picks a "best" representation for the given type. For the built-in types the "%v" specifier is converted as follows:
c Char u other unsigned Integral d other signed Integral g RealFloat s String
Mismatch between the argument types and the format string, as well as any other syntactic or semantic errors in the format string, will cause an exception to be thrown at runtime.
Note that the formatting for RealFloat types is
currently a bit different from that of C printf(3),
conforming instead to showEFloat,
showFFloat and showGFloat (and their
alternate versions showFFloatAlt and
showGFloatAlt). This is hard to fix: the fixed
versions would format in a backward-incompatible way.
In any case the Haskell behavior is generally more
sensible than the C behavior. A brief summary of some
key differences:
- Haskell
printfnever uses the default "6-digit" precision used by C printf. - Haskell
printftreats the "precision" specifier as indicating the number of digits after the decimal point. - Haskell
printfprints the exponent of e-format numbers without a gratuitous plus sign, and with the minimum possible number of digits. - Haskell
printfwill place a zero after a decimal point when possible.
vFmt :: Char -> FieldFormat -> FieldFormat Source #
Substitute a 'v' format character with the given
default format character in the FieldFormat. A
convenience for user-implemented types, which should
support "%v".
Since: base-4.7.0.0
formatChar :: Char -> FieldFormatter Source #
Formatter for Char values.
Since: base-4.7.0.0
formatInt :: (Integral a, Bounded a) => a -> FieldFormatter Source #
Formatter for Int values.
Since: base-4.7.0.0
formatInteger :: Integer -> FieldFormatter Source #
Formatter for Integer values.
Since: base-4.7.0.0
perror :: String -> a Source #
Raises an error with a printf-specific prefix on the
message string.
Since: base-4.7.0.0
errorBadFormat :: Char -> a Source #
Calls perror to indicate an unknown format letter for
a given type.
Since: base-4.7.0.0
errorShortFormat :: a Source #
Calls perror to indicate that the format string ended
early.
Since: base-4.7.0.0
errorMissingArgument :: a Source #
Calls perror to indicate that there is a missing
argument in the argument list.
Since: base-4.7.0.0
errorBadArgument :: a Source #
Calls perror to indicate that there is a type
error or similar in the given argument.
Since: base-4.7.0.0
expandArgsAt :: [String] -> IO [String] #
class Remap (m :: Type -> Type) where #
Instances
| Remap Arg | |
Defined in System.Console.CmdArgs.Explicit.Type | |
| Remap Flag | |
Defined in System.Console.CmdArgs.Explicit.Type | |
| Remap Mode | |
Defined in System.Console.CmdArgs.Explicit.Type | |
Constructors
| Flag | |
Instances
| Remap Flag | |
Defined in System.Console.CmdArgs.Explicit.Type | |
| Packer a => Packer (Flag a) | |
Defined in System.Console.CmdArgs.Helper | |
| Show (Flag a) | |
Instances
| Packer FlagInfo | |
Defined in System.Console.CmdArgs.Helper | |
| Show FlagInfo | |
| Eq FlagInfo | |
| Ord FlagInfo | |
Defined in System.Console.CmdArgs.Explicit.Type | |
Constructors
| Mode | |
Fields
| |
Instances
| Remap Mode | |
Defined in System.Console.CmdArgs.Explicit.Type | |
| Packer a => Packer (Mode a) | |
Defined in System.Console.CmdArgs.Helper | |
| Show (Mode a) | |
Constructors
| Group | |
Fields
| |
fromFlagOpt :: FlagInfo -> String #
remapUpdate :: (a -> b) -> (b -> (a, a -> b)) -> Update a -> Update b #
Constructors
| CompleteValue String | |
| CompleteFile String FilePath | |
| CompleteDir String FilePath |
Instances
| Show Complete | |
| Eq Complete | |
| Ord Complete | |
Defined in System.Console.CmdArgs.Explicit.Complete | |
data HelpFormat #
Instances
helpText :: [String] -> HelpFormat -> Mode a -> [Text] #
processArgs :: Mode a -> IO a #
processValue :: Mode a -> [String] -> a #
processValueIO :: Mode a -> [String] -> IO a #
flagHelpSimple :: (a -> a) -> Flag a #
flagHelpFormat :: (HelpFormat -> TextFormat -> a -> a) -> Flag a #
flagVersion :: (a -> a) -> Flag a #
flagNumericVersion :: (a -> a) -> Flag a #
flagsVerbosity :: (Verbosity -> a -> a) -> [Flag a] #
searchPathSeparator :: Char Source #
The character that is used to separate the entries in the $PATH environment variable.
Windows: searchPathSeparator == ';' Posix: searchPathSeparator == ':'
normalise :: FilePath -> FilePath Source #
Normalise a file
- // outside of the drive can be made blank
- / ->
pathSeparator - ./ -> ""
Does not remove "..", because of symlinks.
Posix: normalise "/file/\\test////" == "/file/\\test/"
Posix: normalise "/file/./test" == "/file/test"
Posix: normalise "/test/file/../bob/fred/" == "/test/file/../bob/fred/"
Posix: normalise "../bob/fred/" == "../bob/fred/"
Posix: normalise "/a/../c" == "/a/../c"
Posix: normalise "./bob/fred/" == "bob/fred/"
Windows: normalise "c:\\file/bob\\" == "C:\\file\\bob\\"
Windows: normalise "c:\\" == "C:\\"
Windows: normalise "c:\\\\\\\\" == "C:\\"
Windows: normalise "C:.\\" == "C:"
Windows: normalise "\\\\server\\test" == "\\\\server\\test"
Windows: normalise "//server/test" == "\\\\server\\test"
Windows: normalise "c:/file" == "C:\\file"
Windows: normalise "/file" == "\\file"
Windows: normalise "\\" == "\\"
Windows: normalise "/./" == "\\"
normalise "." == "."
Posix: normalise "./" == "./"
Posix: normalise "./." == "./"
Posix: normalise "/./" == "/"
Posix: normalise "/" == "/"
Posix: normalise "bob/fred/." == "bob/fred/"
Posix: normalise "//home" == "/home"dropTrailingPathSeparator :: FilePath -> FilePath Source #
Remove any trailing path separators
dropTrailingPathSeparator "file/test/" == "file/test"
dropTrailingPathSeparator "/" == "/"
Windows: dropTrailingPathSeparator "\\" == "\\"
Posix: not (hasTrailingPathSeparator (dropTrailingPathSeparator x)) || isDrive xmakeRelative :: FilePath -> FilePath -> FilePath Source #
Contract a filename, based on a relative path. Note that the resulting path
will never introduce .. paths, as the presence of symlinks means ../b
may not reach a/b if it starts from a/c. For a worked example see
this blog post.
The corresponding makeAbsolute function can be found in
System.Directory.
makeRelative "/directory" "/directory/file.ext" == "file.ext"
Valid x => makeRelative (takeDirectory x) x `equalFilePath` takeFileName x
makeRelative x x == "."
Valid x y => equalFilePath x y || (isRelative x && makeRelative y x == x) || equalFilePath (y </> makeRelative y x) x
Windows: makeRelative "C:\\Home" "c:\\home\\bob" == "bob"
Windows: makeRelative "C:\\Home" "c:/home/bob" == "bob"
Windows: makeRelative "C:\\Home" "D:\\Home\\Bob" == "D:\\Home\\Bob"
Windows: makeRelative "C:\\Home" "C:Home\\Bob" == "C:Home\\Bob"
Windows: makeRelative "/Home" "/home/bob" == "bob"
Windows: makeRelative "/" "//" == "//"
Posix: makeRelative "/Home" "/home/bob" == "/home/bob"
Posix: makeRelative "/home/" "/home/bob/foo/bar" == "bob/foo/bar"
Posix: makeRelative "/fred" "bob" == "bob"
Posix: makeRelative "/file/test" "/file/test/fred" == "fred"
Posix: makeRelative "/file/test" "/file/test/fred/" == "fred/"
Posix: makeRelative "some/path" "some/path/a/b/c" == "a/b/c"(</>) :: FilePath -> FilePath -> FilePath infixr 5 Source #
Combine two paths with a path separator.
If the second path starts with a path separator or a drive letter, then it returns the second.
The intention is that readFile (dir will access the same file as
</> file)setCurrentDirectory dir; readFile file.
Posix: "/directory" </> "file.ext" == "/directory/file.ext"
Windows: "/directory" </> "file.ext" == "/directory\\file.ext"
"directory" </> "/file.ext" == "/file.ext"
Valid x => (takeDirectory x </> takeFileName x) `equalFilePath` xCombined:
Posix: "/" </> "test" == "/test" Posix: "home" </> "bob" == "home/bob" Posix: "x:" </> "foo" == "x:/foo" Windows: "C:\\foo" </> "bar" == "C:\\foo\\bar" Windows: "home" </> "bob" == "home\\bob"
Not combined:
Posix: "home" </> "/bob" == "/bob" Windows: "home" </> "C:\\bob" == "C:\\bob"
Not combined (tricky):
On Windows, if a filepath starts with a single slash, it is relative to the
root of the current drive. In [1], this is (confusingly) referred to as an
absolute path.
The current behavior of </> is to never combine these forms.
Windows: "home" </> "/bob" == "/bob" Windows: "home" </> "\\bob" == "\\bob" Windows: "C:\\home" </> "\\bob" == "\\bob"
On Windows, from [1]: "If a file name begins with only a disk designator
but not the backslash after the colon, it is interpreted as a relative path
to the current directory on the drive with the specified letter."
The current behavior of </> is to never combine these forms.
Windows: "D:\\foo" </> "C:bar" == "C:bar" Windows: "C:\\foo" </> "C:bar" == "C:bar"
pathSeparator :: Char Source #
The character that separates directories. In the case where more than
one character is possible, pathSeparator is the 'ideal' one.
Windows: pathSeparator == '\\' Posix: pathSeparator == '/' isPathSeparator pathSeparator
pathSeparators :: [Char] Source #
The list of all possible separators.
Windows: pathSeparators == ['\\', '/'] Posix: pathSeparators == ['/'] pathSeparator `elem` pathSeparators
isPathSeparator :: Char -> Bool Source #
Rather than using (== , use this. Test if something
is a path separator.pathSeparator)
isPathSeparator a == (a `elem` pathSeparators)
isSearchPathSeparator :: Char -> Bool Source #
Is the character a file separator?
isSearchPathSeparator a == (a == searchPathSeparator)
extSeparator :: Char Source #
File extension character
extSeparator == '.'
isExtSeparator :: Char -> Bool Source #
Is the character an extension character?
isExtSeparator a == (a == extSeparator)
splitSearchPath :: String -> [FilePath] Source #
Take a string, split it on the searchPathSeparator character.
Blank items are ignored on Windows, and converted to . on Posix.
On Windows path elements are stripped of quotes.
Follows the recommendations in http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
Posix: splitSearchPath "File1:File2:File3" == ["File1","File2","File3"] Posix: splitSearchPath "File1::File2:File3" == ["File1",".","File2","File3"] Windows: splitSearchPath "File1;File2;File3" == ["File1","File2","File3"] Windows: splitSearchPath "File1;;File2;File3" == ["File1","File2","File3"] Windows: splitSearchPath "File1;\"File2\";File3" == ["File1","File2","File3"]
getSearchPath :: IO [FilePath] Source #
Get a list of FILEPATHs in the $PATH variable.
splitExtension :: FilePath -> (String, String) Source #
Split on the extension. addExtension is the inverse.
splitExtension "/directory/path.ext" == ("/directory/path",".ext")
uncurry (<>) (splitExtension x) == x
Valid x => uncurry addExtension (splitExtension x) == x
splitExtension "file.txt" == ("file",".txt")
splitExtension "file" == ("file","")
splitExtension "file/file.txt" == ("file/file",".txt")
splitExtension "file.txt/boris" == ("file.txt/boris","")
splitExtension "file.txt/boris.ext" == ("file.txt/boris",".ext")
splitExtension "file/path.txt.bob.fred" == ("file/path.txt.bob",".fred")
splitExtension "file/path.txt/" == ("file/path.txt/","")takeExtension :: FilePath -> String Source #
Get the extension of a file, returns "" for no extension, .ext otherwise.
takeExtension "/directory/path.ext" == ".ext" takeExtension x == snd (splitExtension x) Valid x => takeExtension (addExtension x "ext") == ".ext" Valid x => takeExtension (replaceExtension x "ext") == ".ext"
(-<.>) :: FilePath -> String -> FilePath infixr 7 Source #
Remove the current extension and add another, equivalent to replaceExtension.
"/directory/path.txt" -<.> "ext" == "/directory/path.ext" "/directory/path.txt" -<.> ".ext" == "/directory/path.ext" "foo.o" -<.> "c" == "foo.c"
replaceExtension :: FilePath -> String -> FilePath Source #
Set the extension of a file, overwriting one if already present, equivalent to -<.>.
replaceExtension "/directory/path.txt" "ext" == "/directory/path.ext" replaceExtension "/directory/path.txt" ".ext" == "/directory/path.ext" replaceExtension "file.txt" ".bob" == "file.bob" replaceExtension "file.txt" "bob" == "file.bob" replaceExtension "file" ".bob" == "file.bob" replaceExtension "file.txt" "" == "file" replaceExtension "file.fred.bob" "txt" == "file.fred.txt" replaceExtension x y == addExtension (dropExtension x) y
(<.>) :: FilePath -> String -> FilePath infixr 7 Source #
Add an extension, even if there is already one there, equivalent to addExtension.
"/directory/path" <.> "ext" == "/directory/path.ext" "/directory/path" <.> ".ext" == "/directory/path.ext"
dropExtension :: FilePath -> FilePath Source #
Remove last extension, and the "." preceding it.
dropExtension "/directory/path.ext" == "/directory/path" dropExtension x == fst (splitExtension x)
addExtension :: FilePath -> String -> FilePath Source #
Add an extension, even if there is already one there, equivalent to <.>.
addExtension "/directory/path" "ext" == "/directory/path.ext" addExtension "file.txt" "bib" == "file.txt.bib" addExtension "file." ".bib" == "file..bib" addExtension "file" ".bib" == "file.bib" addExtension "/" "x" == "/.x" addExtension x "" == x Valid x => takeFileName (addExtension (addTrailingPathSeparator x) "ext") == ".ext" Windows: addExtension "\\\\share" ".txt" == "\\\\share\\.txt"
hasExtension :: FilePath -> Bool Source #
Does the given filename have an extension?
hasExtension "/directory/path.ext" == True hasExtension "/directory/path" == False null (takeExtension x) == not (hasExtension x)
isExtensionOf :: String -> FilePath -> Bool Source #
Does the given filename have the specified extension?
"png" `isExtensionOf` "/directory/file.png" == True ".png" `isExtensionOf` "/directory/file.png" == True ".tar.gz" `isExtensionOf` "bar/foo.tar.gz" == True "ar.gz" `isExtensionOf` "bar/foo.tar.gz" == False "png" `isExtensionOf` "/directory/file.png.jpg" == False "csv/table.csv" `isExtensionOf` "/data/csv/table.csv" == False
stripExtension :: String -> FilePath -> Maybe FilePath Source #
Drop the given extension from a FilePath, and the "." preceding it.
Returns Nothing if the FilePath does not have the given extension, or
Just and the part before the extension if it does.
This function can be more predictable than dropExtensions, especially if the filename
might itself contain . characters.
stripExtension "hs.o" "foo.x.hs.o" == Just "foo.x" stripExtension "hi.o" "foo.x.hs.o" == Nothing dropExtension x == fromJust (stripExtension (takeExtension x) x) dropExtensions x == fromJust (stripExtension (takeExtensions x) x) stripExtension ".c.d" "a.b.c.d" == Just "a.b" stripExtension ".c.d" "a.b..c.d" == Just "a.b." stripExtension "baz" "foo.bar" == Nothing stripExtension "bar" "foobar" == Nothing stripExtension "" x == Just x
splitExtensions :: FilePath -> (FilePath, String) Source #
Split on all extensions.
splitExtensions "/directory/path.ext" == ("/directory/path",".ext")
splitExtensions "file.tar.gz" == ("file",".tar.gz")
uncurry (<>) (splitExtensions x) == x
Valid x => uncurry addExtension (splitExtensions x) == xdropExtensions :: FilePath -> FilePath Source #
Drop all extensions.
dropExtensions "/directory/path.ext" == "/directory/path" dropExtensions "file.tar.gz" == "file" not $ hasExtension $ dropExtensions x not $ any isExtSeparator $ takeFileName $ dropExtensions x
takeExtensions :: FilePath -> String Source #
Get all extensions.
takeExtensions "/directory/path.ext" == ".ext" takeExtensions "file.tar.gz" == ".tar.gz"
replaceExtensions :: FilePath -> String -> FilePath Source #
Replace all extensions of a file with a new extension. Note
that replaceExtension and addExtension both work for adding
multiple extensions, so only required when you need to drop
all extensions first.
replaceExtensions "file.fred.bob" "txt" == "file.txt" replaceExtensions "file.fred.bob" "tar.gz" == "file.tar.gz"
splitDrive :: FilePath -> (FilePath, FilePath) Source #
Split a path into a drive and a path. On Posix, / is a Drive.
uncurry (<>) (splitDrive x) == x
Windows: splitDrive "file" == ("","file")
Windows: splitDrive "c:/file" == ("c:/","file")
Windows: splitDrive "c:\\file" == ("c:\\","file")
Windows: splitDrive "\\\\shared\\test" == ("\\\\shared\\","test")
Windows: splitDrive "\\\\shared" == ("\\\\shared","")
Windows: splitDrive "\\\\?\\UNC\\shared\\file" == ("\\\\?\\UNC\\shared\\","file")
Windows: splitDrive "\\\\?\\UNCshared\\file" == ("\\\\?\\","UNCshared\\file")
Windows: splitDrive "\\\\?\\d:\\file" == ("\\\\?\\d:\\","file")
Windows: splitDrive "/d" == ("","/d")
Posix: splitDrive "/test" == ("/","test")
Posix: splitDrive "//test" == ("//","test")
Posix: splitDrive "test/file" == ("","test/file")
Posix: splitDrive "file" == ("","file")joinDrive :: FilePath -> FilePath -> FilePath Source #
Join a drive and the rest of the path.
Valid x => uncurry joinDrive (splitDrive x) == x Windows: joinDrive "C:" "foo" == "C:foo" Windows: joinDrive "C:\\" "bar" == "C:\\bar" Windows: joinDrive "\\\\share" "foo" == "\\\\share\\foo" Windows: joinDrive "/:" "foo" == "/:\\foo"
takeDrive :: FilePath -> FilePath Source #
Get the drive from a filepath.
takeDrive x == fst (splitDrive x)
dropDrive :: FilePath -> FilePath Source #
Delete the drive, if it exists.
dropDrive x == snd (splitDrive x)
hasDrive :: FilePath -> Bool Source #
Does a path have a drive.
not (hasDrive x) == null (takeDrive x)
Posix: hasDrive "/foo" == True
Windows: hasDrive "C:\\foo" == True
Windows: hasDrive "C:foo" == True
hasDrive "foo" == False
hasDrive "" == FalseisDrive :: FilePath -> Bool Source #
Is an element a drive
Posix: isDrive "/" == True
Posix: isDrive "/foo" == False
Windows: isDrive "C:\\" == True
Windows: isDrive "C:\\foo" == False
isDrive "" == FalsesplitFileName :: FilePath -> (String, String) Source #
Split a filename into directory and file. </> is the inverse.
The first component will often end with a trailing slash.
splitFileName "/directory/file.ext" == ("/directory/","file.ext")
Valid x => uncurry (</>) (splitFileName x) == x || fst (splitFileName x) == "./"
Valid x => isValid (fst (splitFileName x))
splitFileName "file/bob.txt" == ("file/", "bob.txt")
splitFileName "file/" == ("file/", "")
splitFileName "bob" == ("./", "bob")
Posix: splitFileName "/" == ("/","")
Windows: splitFileName "c:" == ("c:","")
Windows: splitFileName "\\\\?\\A:\\fred" == ("\\\\?\\A:\\","fred")
Windows: splitFileName "\\\\?\\A:" == ("\\\\?\\A:","")replaceFileName :: FilePath -> String -> FilePath Source #
Set the filename.
replaceFileName "/directory/other.txt" "file.ext" == "/directory/file.ext" Valid x => replaceFileName x (takeFileName x) == x
dropFileName :: FilePath -> FilePath Source #
Drop the filename. Unlike takeDirectory, this function will leave
a trailing path separator on the directory.
dropFileName "/directory/file.ext" == "/directory/" dropFileName x == fst (splitFileName x) isPrefixOf (takeDrive x) (dropFileName x)
takeFileName :: FilePath -> FilePath Source #
Get the file name.
takeFileName "/directory/file.ext" == "file.ext" takeFileName "test/" == "" isSuffixOf (takeFileName x) x takeFileName x == snd (splitFileName x) Valid x => takeFileName (replaceFileName x "fred") == "fred" Valid x => takeFileName (x </> "fred") == "fred" Valid x => isRelative (takeFileName x)
takeBaseName :: FilePath -> String Source #
Get the base name, without an extension or path.
takeBaseName "/directory/file.ext" == "file" takeBaseName "file/test.txt" == "test" takeBaseName "dave.ext" == "dave" takeBaseName "" == "" takeBaseName "test" == "test" takeBaseName (addTrailingPathSeparator x) == "" takeBaseName "file/file.tar.gz" == "file.tar"
replaceBaseName :: FilePath -> String -> FilePath Source #
Set the base name.
replaceBaseName "/directory/other.ext" "file" == "/directory/file.ext" replaceBaseName "file/test.txt" "bob" == "file/bob.txt" replaceBaseName "fred" "bill" == "bill" replaceBaseName "/dave/fred/bob.gz.tar" "new" == "/dave/fred/new.tar" Valid x => replaceBaseName x (takeBaseName x) == x
hasTrailingPathSeparator :: FilePath -> Bool Source #
Is an item either a directory or the last character a path separator?
hasTrailingPathSeparator "test" == False hasTrailingPathSeparator "test/" == True
addTrailingPathSeparator :: FilePath -> FilePath Source #
Add a trailing file path separator if one is not already present.
hasTrailingPathSeparator (addTrailingPathSeparator x) hasTrailingPathSeparator x ==> addTrailingPathSeparator x == x Posix: addTrailingPathSeparator "test/rest" == "test/rest/"
takeDirectory :: FilePath -> FilePath Source #
Get the directory name, move up one level.
takeDirectory "/directory/other.ext" == "/directory"
isPrefixOf (takeDirectory x) x || takeDirectory x == "."
takeDirectory "foo" == "."
takeDirectory "/" == "/"
takeDirectory "/foo" == "/"
takeDirectory "/foo/bar/baz" == "/foo/bar"
takeDirectory "/foo/bar/baz/" == "/foo/bar/baz"
takeDirectory "foo/bar/baz" == "foo/bar"
Windows: takeDirectory "foo\\bar" == "foo"
Windows: takeDirectory "foo\\bar\\\\" == "foo\\bar"
Windows: takeDirectory "C:\\" == "C:\\"replaceDirectory :: FilePath -> String -> FilePath Source #
Set the directory, keeping the filename the same.
replaceDirectory "root/file.ext" "/directory/" == "/directory/file.ext" Valid x => replaceDirectory x (takeDirectory x) `equalFilePath` x
splitPath :: FilePath -> [FilePath] Source #
Split a path by the directory separator.
splitPath "/directory/file.ext" == ["/","directory/","file.ext"] concat (splitPath x) == x splitPath "test//item/" == ["test//","item/"] splitPath "test/item/file" == ["test/","item/","file"] splitPath "" == [] Windows: splitPath "c:\\test\\path" == ["c:\\","test\\","path"] Posix: splitPath "/file/test" == ["/","file/","test"]
splitDirectories :: FilePath -> [FilePath] Source #
Just as splitPath, but don't add the trailing slashes to each element.
splitDirectories "/directory/file.ext" == ["/","directory","file.ext"]
splitDirectories "test/file" == ["test","file"]
splitDirectories "/test/file" == ["/","test","file"]
Windows: splitDirectories "C:\\test\\file" == ["C:\\", "test", "file"]
Valid x => joinPath (splitDirectories x) `equalFilePath` x
splitDirectories "" == []
Windows: splitDirectories "C:\\test\\\\\\file" == ["C:\\", "test", "file"]
splitDirectories "/test///file" == ["/","test","file"]joinPath :: [FilePath] -> FilePath Source #
Join path elements back together.
joinPath z == foldr (</>) "" z joinPath ["/","directory/","file.ext"] == "/directory/file.ext" Valid x => joinPath (splitPath x) == x joinPath [] == "" Posix: joinPath ["test","file","path"] == "test/file/path"
equalFilePath :: FilePath -> FilePath -> Bool Source #
Equality of two FILEPATHs.
If you call System.Directory.canonicalizePath
first this has a much better chance of working.
Note that this doesn't follow symlinks or DOSNAM~1s.
Similar to normalise, this does not expand "..", because of symlinks.
x == y ==> equalFilePath x y
normalise x == normalise y ==> equalFilePath x y
equalFilePath "foo" "foo/"
not (equalFilePath "/a/../c" "/c")
not (equalFilePath "foo" "/foo")
Posix: not (equalFilePath "foo" "FOO")
Windows: equalFilePath "foo" "FOO"
Windows: not (equalFilePath "C:" "C:/")isValid :: FilePath -> Bool Source #
Is a FilePath valid, i.e. could you create a file like it? This function checks for invalid names, and invalid characters, but does not check if length limits are exceeded, as these are typically filesystem dependent.
isValid "" == False
isValid "\0" == False
Posix: isValid "/random_ path:*" == True
Posix: isValid x == not (null x)
Windows: isValid "c:\\test" == True
Windows: isValid "c:\\test:of_test" == False
Windows: isValid "test*" == False
Windows: isValid "c:\\test\\nul" == False
Windows: isValid "c:\\test\\prn.txt" == False
Windows: isValid "c:\\nul\\file" == False
Windows: isValid "\\\\" == False
Windows: isValid "\\\\\\foo" == False
Windows: isValid "\\\\?\\D:file" == False
Windows: isValid "foo\tbar" == False
Windows: isValid "nul .txt" == False
Windows: isValid " nul.txt" == TruemakeValid :: FilePath -> FilePath Source #
Take a FilePath and make it valid; does not change already valid FILEPATHs.
isValid (makeValid x) isValid x ==> makeValid x == x makeValid "" == "_" makeValid "file\0name" == "file_name" Windows: makeValid "c:\\already\\/valid" == "c:\\already\\/valid" Windows: makeValid "c:\\test:of_test" == "c:\\test_of_test" Windows: makeValid "test*" == "test_" Windows: makeValid "c:\\test\\nul" == "c:\\test\\nul_" Windows: makeValid "c:\\test\\prn.txt" == "c:\\test\\prn_.txt" Windows: makeValid "c:\\test/prn.txt" == "c:\\test/prn_.txt" Windows: makeValid "c:\\nul\\file" == "c:\\nul_\\file" Windows: makeValid "\\\\\\foo" == "\\\\drive" Windows: makeValid "\\\\?\\D:file" == "\\\\?\\D:\\file" Windows: makeValid "nul .txt" == "nul _.txt"
isRelative :: FilePath -> Bool Source #
Is a path relative, or is it fixed to the root?
Windows: isRelative "path\\test" == True Windows: isRelative "c:\\test" == False Windows: isRelative "c:test" == True Windows: isRelative "c:\\" == False Windows: isRelative "c:/" == False Windows: isRelative "c:" == True Windows: isRelative "\\\\foo" == False Windows: isRelative "\\\\?\\foo" == False Windows: isRelative "\\\\?\\UNC\\foo" == False Windows: isRelative "/foo" == True Windows: isRelative "\\foo" == True Posix: isRelative "test/path" == True Posix: isRelative "/test" == False Posix: isRelative "/" == False
According to [1]:
- "A UNC name of any format [is never relative]."
- "You cannot use the "\?" prefix with a relative path."
isAbsolute :: FilePath -> Bool Source #
not . isRelativeisAbsolute x == not (isRelative x)
foldl1Note :: Partial => String -> (a -> a -> a) -> [a] -> a #
foldr1Note :: Partial => String -> (a -> a -> a) -> [a] -> a #
minimumMay :: Ord a => [a] -> Maybe a #
maximumMay :: Ord a => [a] -> Maybe a #
minimumNote :: (Partial, Ord a) => String -> [a] -> a #
maximumNote :: (Partial, Ord a) => String -> [a] -> a #
minimumByMay :: (a -> a -> Ordering) -> [a] -> Maybe a #
maximumByMay :: (a -> a -> Ordering) -> [a] -> Maybe a #
minimumByNote :: Partial => String -> (a -> a -> Ordering) -> [a] -> a #
maximumByNote :: Partial => String -> (a -> a -> Ordering) -> [a] -> a #
maximumBoundBy :: a -> (a -> a -> Ordering) -> [a] -> a #
minimumBoundBy :: a -> (a -> a -> Ordering) -> [a] -> a #
maximumBound :: Ord a => a -> [a] -> a #
minimumBound :: Ord a => a -> [a] -> a #
maximumBounded :: (Ord a, Bounded a) => [a] -> a #
minimumBounded :: (Ord a, Bounded a) => [a] -> a #
findJustDef :: a -> (a -> Bool) -> [a] -> a #
findJustNote :: Partial => String -> (a -> Bool) -> [a] -> a #
minimumDef :: Ord a => a -> [a] -> a #
maximumDef :: Ord a => a -> [a] -> a #
minimumByDef :: a -> (a -> a -> Ordering) -> [a] -> a #
maximumByDef :: a -> (a -> a -> Ordering) -> [a] -> a #
foldl1May' :: (a -> a -> a) -> [a] -> Maybe a #
foldl1Note' :: Partial => String -> (a -> a -> a) -> [a] -> a #
scanr1Note :: Partial => String -> (a -> a -> a) -> [a] -> [a] #
scanl1Note :: Partial => String -> (a -> a -> a) -> [a] -> [a] #
fromJustDef :: a -> Maybe a -> a #
fromJustNote :: Partial => String -> Maybe a -> a #
assertNote :: Partial => String -> Bool -> a -> a #
lookupJust :: (Eq a, Partial) => a -> [(a, b)] -> b #
lookupJustDef :: Eq a => b -> a -> [(a, b)] -> b #
lookupJustNote :: (Partial, Eq a) => String -> a -> [(a, b)] -> b #
elemIndexJust :: (Partial, Eq a) => a -> [a] -> Int #
elemIndexJustDef :: Eq a => Int -> a -> [a] -> Int #
elemIndexJustNote :: (Partial, Eq a) => String -> a -> [a] -> Int #
findIndexJust :: (a -> Bool) -> [a] -> Int #
findIndexJustDef :: Int -> (a -> Bool) -> [a] -> Int #
findIndexJustNote :: Partial => String -> (a -> Bool) -> [a] -> Int #
toEnumSafe :: (Enum a, Bounded a) => Int -> a #
foldl1Def' :: a -> (a -> a -> a) -> [a] -> a #
argsToCliOpts :: [String] -> [String] -> IO CliOpts Source #
A helper for addons/scripts: this parses hledger CliOpts from these command line arguments and add-on command names, roughly how hledger main does. If option parsing/validating fails, it exits the program with usageError. Unlike main, this does not read extra args from a config file or search for addons; to do those things, mimic the code in main for now.