The previous cleanup defined long help separately from the usage text generated by cmdargs. This meant keeping flag descriptions synced between the two, and also the short help was often too verbose and longer than the long help. Now, the non-usage bits of long help are defined as pre and postambles within the cmdargs mode, letting cmdargs generate the long help including all flags. We derive the short help from this by truncating at the start of the hledger common flags. Most of the bundled addons (all but hledger-budget) now use the new scheme and have pretty reasonable -h and --help output. We can do more to reduce boilerplate for addon authors.
		
			
				
	
	
		
			34 lines
		
	
	
		
			956 B
		
	
	
	
		
			Haskell
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			34 lines
		
	
	
		
			956 B
		
	
	
	
		
			Haskell
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/env stack
 | |
| {- stack runghc --verbosity info
 | |
|    --package hledger-lib
 | |
|    --package hledger
 | |
|    --package here
 | |
| -}
 | |
| 
 | |
| {-# LANGUAGE QuasiQuotes #-}
 | |
| 
 | |
| import Data.List
 | |
| import Data.Ord
 | |
| import Data.String.Here
 | |
| import Hledger.Cli
 | |
| 
 | |
| ------------------------------------------------------------------------------
 | |
| cmdmode = (defAddonCommandMode "print-unique") {
 | |
|    modeHelp = [here|
 | |
| Print only journal entries which are unique by description (or
 | |
| something else). Reads the default or specified journal, or stdin.
 | |
|   |]
 | |
|   ,modeHelpSuffix=lines [here|
 | |
|   |]
 | |
|   }
 | |
| ------------------------------------------------------------------------------
 | |
| 
 | |
| main = do
 | |
|   opts <- getHledgerCliOpts cmdmode
 | |
|   withJournalDo opts $
 | |
|     \opts j@Journal{jtxns=ts} -> print' opts j{jtxns=uniquify ts}
 | |
|     where
 | |
|       uniquify = nubBy (\t1 t2 -> thingToCompare t1 == thingToCompare t2) . sortBy (comparing thingToCompare)
 | |
|       thingToCompare = tdescription
 | |
|       -- thingToCompare = tdate
 |