Skip to content

Commit

Permalink
Allow overwriting the version with a .version file
Browse files Browse the repository at this point in the history
  • Loading branch information
dasJ committed Aug 7, 2024
1 parent 08144b4 commit 47b9dc2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
3 changes: 3 additions & 0 deletions MAINTENANCE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Maintainer documentation

Writing to .version in the root of the project causes this version to be returned by `nixfmt --version`
rather than the version from the cabalfile.

## Making a new release

- Check the commit log if anything is missing from the change log.
Expand Down
10 changes: 9 additions & 1 deletion main/Main.hs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE TemplateHaskell #-}

module Main where

import Control.Concurrent (Chan, forkIO, newChan, readChan, writeChan)
import Data.ByteString.Char8 (unpack)
import Data.Either (lefts)
import Data.FileEmbed
import Data.List (isSuffixOf)
import Data.Text (Text)
import qualified Data.Text.IO as TextIO (getContents, hPutStr, putStr)
Expand Down Expand Up @@ -46,6 +49,11 @@ data Nixfmt = Nixfmt
}
deriving (Show, Data, Typeable)

versionFromFile :: String
versionFromFile = case $(embedFileIfExists ".version") of
Just ver -> unpack ver
_ -> showVersion version

options :: Nixfmt
options =
let defaultWidth = 100
Expand All @@ -67,7 +75,7 @@ options =
&= help
"Pretty print the internal AST, only for debugging"
}
&= summary ("nixfmt v" ++ showVersion version)
&= summary ("nixfmt " ++ versionFromFile)
&= help "Format Nix source code"

data Target = Target
Expand Down
2 changes: 2 additions & 0 deletions nixfmt.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ executable nixfmt
hs-source-dirs: main
build-depends:
base >= 4.12.0 && < 4.19
, bytestring
, cmdargs >= 0.10.20 && < 0.11
, file-embed
, nixfmt
, unix >= 2.7.2 && < 2.9
, text >= 1.2.3 && < 2.2
Expand Down

0 comments on commit 47b9dc2

Please sign in to comment.