hledger-1.50.3: Command-line interface for the hledger accounting system

Safe Haskell | None
Language | GHC2021

Hledger.Cli.Version

Synopsis

- type PackageVersionString = String
- type Version = NonEmpty Int
- nullversion :: NonEmpty Int
- toVersion :: PackageVersionString -> Maybe Version
- showVersion :: Version -> String
- isReleaseVersion :: Version -> Bool
- type HledgerVersionString = String
- data HledgerBinaryInfo = HledgerBinaryInfo {
  - hbinVersionOutput :: String
  - hbinProgramName :: ProgramName
  - hbinPackageVersion :: Version
  - hbinPackageVersionStr :: String
  - hbinGitHash :: Maybe GitHash
  - hbinReleaseDate :: Maybe Day
  - hbinOs :: Maybe OsName
  - hbinArch :: Maybe ArchName
  }
- nullbinaryinfo :: HledgerBinaryInfo
- type ProgramName = String
- type GitHash = String
- type ArchName = String
- parseHledgerVersion :: HledgerVersionString -> Either String HledgerBinaryInfo
- packageversion :: PackageVersionString
- packagemajorversion :: PackageVersionString
- versionStringWith :: Either String GitInfo -> Bool -> ProgramName -> PackageVersionString -> HledgerVersionString

# Documentation

type PackageVersionString = String Source #

A Cabal/Hackage-compatible package version string: one or more dot-separated integers.

type Version = NonEmpty Int Source #

The number parts parsed from a PackageVersionString.

nullversion :: NonEmpty Int Source #

toVersion :: PackageVersionString -> Maybe Version Source #

Parse a valid Cabal/Hackage-compatible package version.

showVersion :: Version -> String Source #

isReleaseVersion :: Version -> Bool Source #

type HledgerVersionString = String Source #

A hledger version string, as shown by hledger --version. This can vary; some examples:

- dev builds: hledger 1.42.99-g2288f5193-20250422, mac-aarch64
- release builds: hledger 1.42.1, mac-aarch64
- older versions: hledger 1.21

data HledgerBinaryInfo Source #

The name and package version of a hledger binary, and the build's git hash, the release date, and the binary's intended operating machine and machine architecture, if we can detect these. Also, a copy of the --version output from which it was parsed.

Constructors

HledgerBinaryInfo |

Fields

- hbinVersionOutput :: String
- hbinProgramName :: ProgramName
- hbinPackageVersion :: Version
- hbinPackageVersionStr :: String
- hbinGitHash :: Maybe GitHash
- hbinReleaseDate :: Maybe Day
- hbinOs :: Maybe OsName
- hbinArch :: Maybe ArchName

#### Instances

Instances details

Show HledgerBinaryInfo Source # |
Instance details Defined in Hledger.Cli.Version Methods showsPrec :: Int -> HledgerBinaryInfo -> ShowS Source # show :: HledgerBinaryInfo -> String Source # showList :: [HledgerBinaryInfo] -> ShowS Source #
Eq HledgerBinaryInfo Source # |
Instance details Defined in Hledger.Cli.Version Methods (==) :: HledgerBinaryInfo -> HledgerBinaryInfo -> Bool Source # (/=) :: HledgerBinaryInfo -> HledgerBinaryInfo -> Bool Source #

nullbinaryinfo :: HledgerBinaryInfo Source #

type ProgramName = String Source #

The program name from a hledger version string: hledger, hledger-ui, hledger-web..

type GitHash = String Source #

The git hash from a hledger version string, excluding the g prefix.

type ArchName = String Source #

The machine architecture from a hledger version string. This is the value of `System.Info.arch`, eg: aarch64, alpha, arm, hppa, hppa1_1, i386, ia64, loongarch32, loongarch64, m68k, mips, mipseb, mipsel, nios2, powerpc, powerpc64, powerpc64le, riscv32, riscv64, rs6000, s390, s390x, sh4, sparc, sparc64, vax, x86_64..

parseHledgerVersion :: HledgerVersionString -> Either String HledgerBinaryInfo Source #

Parse hledger's --version output.

    >>> isRight $ parseHledgerVersion "hledger 1.21"
    True
    >>> isRight $ parseHledgerVersion "hledger 1.42.1, mac-aarch64"
    True
    >>> isRight $ parseHledgerVersion "hledger 1.42.99-g2288f5193-20250422, mac-aarch64"
    True

packageversion :: PackageVersionString Source #

The "1.50.3" string defined with -D in this package's package.yaml/.cabal file (by Shake setversion), if any. Normally a dotted number string with 1-3 components.

packagemajorversion :: PackageVersionString Source #

Just the first 1-2 components of packageversion.

versionStringWith :: Either String GitInfo -> Bool -> ProgramName -> PackageVersionString -> HledgerVersionString Source #

Given possible git state info from the build directory (or a git error, which is ignored), and the debug build flag, executable name and package version for the package being built, make the best version string we can. Here is the logic:

- Program name, OS and architecture are always shown.
- The package version is always shown.
- If there is git info at build time, the latest commit hash and commit date are shown, and (TODO, requires githash to use -uno for giDirty): if the working copy has uncommitted changes a + sign is appended.
- (TODO, requires adding --match support to githash: If there are tags matching THISPKG-[0-9]*, the latest one is used to calculate patch level (number of commits since tag), and if non-zero, it and the branch name are shown.)
- If the debug build flag was enabled for the package being built, and for hledger-lib (both are needed), "ghc-debug support" is shown.

Some example outputs:

- A homebrew binary, not built in git repo: hledger-ui 1.24, mac-aarch64
- A CI release build, built in git repo at release tag: hledger-ui 1.24.1-g455b35293-20211210, mac-x86_64
- (TODO) A dev build, built in git repo: hledger-ui 1.24.1+1-g4abd8ef10-20211210 (1.24-branch), mac-x86_64

This function requires git log to show the default (rfc2822-style) date format, so that must not be overridden by a log.date git config variable.

The GitInfo if any, fetched by template haskell, is passed down from a top-level module, reducing wasteful recompilation. The status of the debug build flag is also passed down, since it is specific to each hledger package.

This is used indirectly by at least hledger, hledger-ui, and hledger-web, so output should be suitable for all of those.