Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overwriting the version with a .version file #231

Merged
merged 2 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 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,9 @@ data Nixfmt = Nixfmt
}
deriving (Show, Data, Typeable)

versionFromFile :: String
versionFromFile = maybe (showVersion version) unpack $(embedFileIfExists ".version")

options :: Nixfmt
options =
let defaultWidth = 100
Expand All @@ -67,7 +73,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