Skip to content

Commit

Permalink
imp:close: omit file extension from tag value
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmichael committed Jan 10, 2025
1 parent bde97b8 commit 87cc3e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions hledger/Hledger/Cli/Commands/Close.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import System.Console.CmdArgs.Explicit as C
import Hledger
import Hledger.Cli.CliOptions
import Safe (lastDef, readMay, readDef)
import System.FilePath (takeFileName)
import System.FilePath (takeBaseName)
import Data.Char (isDigit)
import Hledger.Read.RulesReader (parseBalanceAssertionType)
import Hledger.Cli.Commands.Print (roundFlag, amountStylesSetRoundingFromRawOpts)
Expand Down Expand Up @@ -87,12 +87,12 @@ close CliOpts{rawopts_=rawopts, reportspec_=rspec0} j = do
| mode_ == Retain -> "retain:" <> tagval
| otherwise -> "clopen:" <> if null tagval then inferredval else tagval
where
inferredval = newfilename
inferredval = newfilebasename
where
oldfilename = takeFileName $ journalFilePath j
(nonnum, rest) = break isDigit $ reverse oldfilename
oldfilebasename = takeBaseName $ journalFilePath j
(nonnum, rest) = break isDigit $ reverse oldfilebasename
(oldnum, rest2) = span isDigit rest
newfilename = case oldnum of
newfilebasename = case oldnum of
[] -> ""
_ -> reverse rest2 <> newnum <> reverse nonnum
where
Expand Down
4 changes: 2 additions & 2 deletions hledger/Hledger/Cli/Commands/Close.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ When migrating to a new file, you'll usually want to bring along the AL or ALE a
but not the RX accounts (Revenue, Expense).

The generated transactions will have a `clopen:` tag.
If the main journal's file name contains a number (eg a year number),
the tag's value will be that file name with the number incremented.
If the main journal's base file name contains a number (eg a year number),
the tag's value will be that base file name with the number incremented.
Or you can choose the tag value yourself, by using `--clopen=TAGVAL`.

### close --close
Expand Down

0 comments on commit 87cc3e1

Please sign in to comment.