add: integrate CLI help & manual

This commit is contained in:
Simon Michael 2019-01-26 17:13:44 -08:00
parent 53620d0df2
commit 64d78f1644
6 changed files with 179 additions and 187 deletions

View File

@ -4,6 +4,7 @@ A history-aware add command to help with data entry.
{-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-unused-do-bind #-} {-# OPTIONS_GHC -fno-warn-missing-signatures -fno-warn-unused-do-bind #-}
{-# LANGUAGE ScopedTypeVariables, DeriveDataTypeable, RecordWildCards, TypeOperators, FlexibleContexts, OverloadedStrings, PackageImports #-} {-# LANGUAGE ScopedTypeVariables, DeriveDataTypeable, RecordWildCards, TypeOperators, FlexibleContexts, OverloadedStrings, PackageImports #-}
{-# LANGUAGE TemplateHaskell #-}
module Hledger.Cli.Commands.Add ( module Hledger.Cli.Commands.Add (
addmode addmode
@ -46,17 +47,12 @@ import Hledger.Cli.CliOptions
import Hledger.Cli.Commands.Register (postingsReportAsText) import Hledger.Cli.Commands.Register (postingsReportAsText)
addmode = (defCommandMode ["add"]) { addmode = hledgerCommandMode
modeHelp = "prompt for transactions and add them to the journal" $(hereFileRelative "Hledger/Cli/Commands/Add.md")
,modeHelpSuffix = ["Defaults come from previous similar transactions; use query patterns to restrict these."] [flagNone ["no-new-accounts"] (\opts -> setboolopt "no-new-accounts" opts) "don't allow creating new accounts"]
,modeGroupFlags = Group { [generalflagsgroup2]
groupUnnamed = [ []
flagNone ["no-new-accounts"] (\opts -> setboolopt "no-new-accounts" opts) "don't allow creating new accounts" ([], Just $ argsFlag "[QUERY]")
]
,groupHidden = []
,groupNamed = [generalflagsgroup2]
}
}
-- | State used while entering transactions. -- | State used while entering transactions.
data EntryState = EntryState { data EntryState = EntryState {

View File

@ -0,0 +1,61 @@
add\
Prompt for transactions and add them to the journal.
_FLAGS_
Many hledger users edit their journals directly with a text editor, or generate them from CSV.
For more interactive data entry, there is the `add` command,
which prompts interactively on the console for new transactions, and appends
them to the journal file (if there are multiple `-f FILE` options, the first file is used.)
Existing transactions are not changed.
This is the only hledger command that writes to the journal file.
To use it, just run `hledger add` and follow the prompts.
You can add as many transactions as you like; when you are finished,
enter `.` or press control-d or control-c to exit.
Features:
- add tries to provide useful defaults, using the most similar (by description)
recent transaction (filtered by the query, if any) as a template.
- You can also set the initial defaults with command line arguments.
- [Readline-style edit keys](http://tiswww.case.edu/php/chet/readline/rluserman.html#SEC3)
can be used during data entry.
- The tab key will auto-complete whenever possible - accounts,
descriptions, dates (`yesterday`, `today`, `tomorrow`). If the input
area is empty, it will insert the default value.
- If the journal defines a [default commodity](#default-commodity),
it will be added to any bare numbers entered.
- A parenthesised transaction [code](#entries) may be entered following a date.
- [Comments](#comments) and tags may be entered following a description or amount.
- If you make a mistake, enter `<` at any prompt to restart the transaction.
- Input prompts are displayed in a different colour when the terminal supports it.
Example (see the [tutorial](step-by-step.html#record-a-transaction-with-hledger-add) for a detailed explanation):
``` shell
$ hledger add
Adding transactions to journal file /src/hledger/examples/sample.journal
Any command line arguments will be used as defaults.
Use tab key to complete, readline keys to edit, enter to accept defaults.
An optional (CODE) may follow transaction dates.
An optional ; COMMENT may follow descriptions or amounts.
If you make a mistake, enter < at any prompt to restart the transaction.
To end a transaction, enter . when prompted.
To quit, enter . at a date prompt or press control-d or control-c.
Date [2015/05/22]:
Description: supermarket
Account 1: expenses:food
Amount 1: $10
Account 2: assets:checking
Amount 2 [$-10.0]:
Account 3 (or . or enter to finish this transaction): .
2015/05/22 supermarket
expenses:food $10
assets:checking $-10.0
Save this transaction to the journal ? [y]:
Saved.
Starting the next transaction (. or ctrl-D/ctrl-C to quit)
Date [2015/05/22]: <CTRL-D> $
```

View File

@ -1409,13 +1409,11 @@ $\ hledger\ activity\ \-\-quarterly
.fi .fi
.SS add .SS add
.PP .PP
add
.PD 0
.P
.PD
Prompt for transactions and add them to the journal. Prompt for transactions and add them to the journal.
.TP
.B \f[C]\-\-no\-new\-accounts\f[]
don\[aq]t allow creating new accounts; helps prevent typos when entering
account names
.RS
.RE
.PP .PP
Many hledger users edit their journals directly with a text editor, or Many hledger users edit their journals directly with a text editor, or
generate them from CSV. generate them from CSV.
@ -1432,8 +1430,9 @@ enter \f[C]\&.\f[] or press control\-d or control\-c to exit.
.PP .PP
Features: Features:
.IP \[bu] 2 .IP \[bu] 2
add tries to provide useful defaults, using the most similar recent add tries to provide useful defaults, using the most similar (by
transaction (by description) as a template. description) recent transaction (filtered by the query, if any) as a
template.
.IP \[bu] 2 .IP \[bu] 2
You can also set the initial defaults with command line arguments. You can also set the initial defaults with command line arguments.
.IP \[bu] 2 .IP \[bu] 2

View File

@ -1071,13 +1071,9 @@ File: hledger.info, Node: add, Next: balance, Prev: activity, Up: COMMANDS
4.3 add 4.3 add
======= =======
add
Prompt for transactions and add them to the journal. Prompt for transactions and add them to the journal.
'--no-new-accounts'
don't allow creating new accounts; helps prevent typos when
entering account names
Many hledger users edit their journals directly with a text editor, Many hledger users edit their journals directly with a text editor,
or generate them from CSV. For more interactive data entry, there is the or generate them from CSV. For more interactive data entry, there is the
'add' command, which prompts interactively on the console for new 'add' command, which prompts interactively on the console for new
@ -1092,8 +1088,9 @@ or press control-d or control-c to exit.
Features: Features:
* add tries to provide useful defaults, using the most similar recent * add tries to provide useful defaults, using the most similar (by
transaction (by description) as a template. description) recent transaction (filtered by the query, if any) as
a template.
* You can also set the initial defaults with command line arguments. * You can also set the initial defaults with command line arguments.
* Readline-style edit keys can be used during data entry. * Readline-style edit keys can be used during data entry.
* The tab key will auto-complete whenever possible - accounts, * The tab key will auto-complete whenever possible - accounts,
@ -2768,94 +2765,94 @@ Node: activity34448
Ref: #activity34558 Ref: #activity34558
Node: add34941 Node: add34941
Ref: #add35040 Ref: #add35040
Node: balance37701 Node: balance37627
Ref: #balance37812 Ref: #balance37738
Node: Classic balance report40932 Node: Classic balance report40858
Ref: #classic-balance-report41105 Ref: #classic-balance-report41031
Node: Customising the classic balance report42474 Node: Customising the classic balance report42400
Ref: #customising-the-classic-balance-report42702 Ref: #customising-the-classic-balance-report42628
Node: Colour support44776 Node: Colour support44702
Ref: #colour-support44943 Ref: #colour-support44869
Node: Flat mode45116 Node: Flat mode45042
Ref: #flat-mode45264 Ref: #flat-mode45190
Node: Depth limited balance reports45677 Node: Depth limited balance reports45603
Ref: #depth-limited-balance-reports45877 Ref: #depth-limited-balance-reports45803
Node: Multicolumn balance report46333 Node: Multicolumn balance report46259
Ref: #multicolumn-balance-report46531 Ref: #multicolumn-balance-report46457
Node: Budget report51771 Node: Budget report51697
Ref: #budget-report51914 Ref: #budget-report51840
Node: Nested budgets56598 Node: Nested budgets56524
Ref: #nested-budgets56710 Ref: #nested-budgets56636
Ref: #output-format-160190 Ref: #output-format-160116
Node: balancesheet60268 Node: balancesheet60194
Ref: #balancesheet60404 Ref: #balancesheet60330
Node: balancesheetequity62715 Node: balancesheetequity62641
Ref: #balancesheetequity62864 Ref: #balancesheetequity62790
Node: cashflow63401 Node: cashflow63327
Ref: #cashflow63529 Ref: #cashflow63455
Node: check-dates65652 Node: check-dates65578
Ref: #check-dates65779 Ref: #check-dates65705
Node: check-dupes65896 Node: check-dupes65822
Ref: #check-dupes66020 Ref: #check-dupes65946
Node: close66157 Node: close66083
Ref: #close66265 Ref: #close66191
Node: files69678 Node: files69604
Ref: #files69779 Ref: #files69705
Node: help69920 Node: help69846
Ref: #help70020 Ref: #help69946
Node: import71094 Node: import71020
Ref: #import71208 Ref: #import71134
Node: incomestatement71938 Node: incomestatement71864
Ref: #incomestatement72072 Ref: #incomestatement71998
Node: prices74476 Node: prices74402
Ref: #prices74591 Ref: #prices74517
Node: print74863 Node: print74789
Ref: #print74973 Ref: #print74899
Node: print-unique79867 Node: print-unique79793
Ref: #print-unique79993 Ref: #print-unique79919
Node: register80061 Node: register79987
Ref: #register80188 Ref: #register80114
Node: Custom register output84689 Node: Custom register output84615
Ref: #custom-register-output84818 Ref: #custom-register-output84744
Node: register-match86048 Node: register-match85974
Ref: #register-match86182 Ref: #register-match86108
Node: rewrite86365 Node: rewrite86291
Ref: #rewrite86480 Ref: #rewrite86406
Node: roi86549 Node: roi86475
Ref: #roi86647 Ref: #roi86573
Node: stats86763 Node: stats86689
Ref: #stats86862 Ref: #stats86788
Node: tags87732 Node: tags87658
Ref: #tags87830 Ref: #tags87756
Node: test88066 Node: test87992
Ref: #test88150 Ref: #test88076
Node: ADD-ON COMMANDS88858 Node: ADD-ON COMMANDS88784
Ref: #add-on-commands88968 Ref: #add-on-commands88894
Node: Official add-ons90255 Node: Official add-ons90181
Ref: #official-add-ons90395 Ref: #official-add-ons90321
Node: api90482 Node: api90408
Ref: #api90571 Ref: #api90497
Node: ui90623 Node: ui90549
Ref: #ui90722 Ref: #ui90648
Node: web90780 Node: web90706
Ref: #web90869 Ref: #web90795
Node: Third party add-ons90915 Node: Third party add-ons90841
Ref: #third-party-add-ons91090 Ref: #third-party-add-ons91016
Node: diff91225 Node: diff91151
Ref: #diff91322 Ref: #diff91248
Node: iadd91421 Node: iadd91347
Ref: #iadd91535 Ref: #iadd91461
Node: interest91618 Node: interest91544
Ref: #interest91739 Ref: #interest91665
Node: irr91834 Node: irr91760
Ref: #irr91932 Ref: #irr91858
Node: Experimental add-ons92063 Node: Experimental add-ons91989
Ref: #experimental-add-ons92215 Ref: #experimental-add-ons92141
Node: autosync92495 Node: autosync92421
Ref: #autosync92606 Ref: #autosync92532
Node: chart92845 Node: chart92771
Ref: #chart92964 Ref: #chart92890
Node: check93035 Node: check92961
Ref: #check93137 Ref: #check93063
 
End Tag Table End Tag Table

View File

@ -944,28 +944,26 @@ COMMANDS
2008-10-01 ** 2008-10-01 **
add add
add
Prompt for transactions and add them to the journal. Prompt for transactions and add them to the journal.
--no-new-accounts Many hledger users edit their journals directly with a text editor, or
don't allow creating new accounts; helps prevent typos when generate them from CSV. For more interactive data entry, there is the
entering account names add command, which prompts interactively on the console for new trans-
actions, and appends them to the journal file (if there are multiple
Many hledger users edit their journals directly with a text editor, or
generate them from CSV. For more interactive data entry, there is the
add command, which prompts interactively on the console for new trans-
actions, and appends them to the journal file (if there are multiple
-f FILE options, the first file is used.) Existing transactions are not -f FILE options, the first file is used.) Existing transactions are not
changed. This is the only hledger command that writes to the journal changed. This is the only hledger command that writes to the journal
file. file.
To use it, just run hledger add and follow the prompts. You can add as To use it, just run hledger add and follow the prompts. You can add as
many transactions as you like; when you are finished, enter . or press many transactions as you like; when you are finished, enter . or press
control-d or control-c to exit. control-d or control-c to exit.
Features: Features:
o add tries to provide useful defaults, using the most similar recent o add tries to provide useful defaults, using the most similar (by
transaction (by description) as a template. description) recent transaction (filtered by the query, if any) as a
template.
o You can also set the initial defaults with command line arguments. o You can also set the initial defaults with command line arguments.

View File

@ -32,67 +32,8 @@ _include_(Hledger/Cli/Commands/Accounts.md)
_include_(Hledger/Cli/Commands/Activity.md) _include_(Hledger/Cli/Commands/Activity.md)
## add ## add
Prompt for transactions and add them to the journal.
`--no-new-accounts` _include_(Hledger/Cli/Commands/Add.md)
: don't allow creating new accounts; helps prevent typos when entering account names
Many hledger users edit their journals directly with a text editor, or generate them from CSV.
For more interactive data entry, there is the `add` command,
which prompts interactively on the console for new transactions, and appends
them to the journal file (if there are multiple `-f FILE` options, the first file is used.)
Existing transactions are not changed.
This is the only hledger command that writes to the journal file.
To use it, just run `hledger add` and follow the prompts.
You can add as many transactions as you like; when you are finished,
enter `.` or press control-d or control-c to exit.
Features:
- add tries to provide useful defaults, using the most similar recent
transaction (by description) as a template.
- You can also set the initial defaults with command line arguments.
- [Readline-style edit keys](http://tiswww.case.edu/php/chet/readline/rluserman.html#SEC3)
can be used during data entry.
- The tab key will auto-complete whenever possible - accounts,
descriptions, dates (`yesterday`, `today`, `tomorrow`). If the input
area is empty, it will insert the default value.
- If the journal defines a [default commodity](#default-commodity),
it will be added to any bare numbers entered.
- A parenthesised transaction [code](#entries) may be entered following a date.
- [Comments](#comments) and tags may be entered following a description or amount.
- If you make a mistake, enter `<` at any prompt to restart the transaction.
- Input prompts are displayed in a different colour when the terminal supports it.
Example (see the [tutorial](step-by-step.html#record-a-transaction-with-hledger-add) for a detailed explanation):
_shell_({{
$ hledger add
Adding transactions to journal file /src/hledger/examples/sample.journal
Any command line arguments will be used as defaults.
Use tab key to complete, readline keys to edit, enter to accept defaults.
An optional (CODE) may follow transaction dates.
An optional ; COMMENT may follow descriptions or amounts.
If you make a mistake, enter < at any prompt to restart the transaction.
To end a transaction, enter . when prompted.
To quit, enter . at a date prompt or press control-d or control-c.
Date [2015/05/22]:
Description: supermarket
Account 1: expenses:food
Amount 1: $10
Account 2: assets:checking
Amount 2 [$-10.0]:
Account 3 (or . or enter to finish this transaction): .
2015/05/22 supermarket
expenses:food $10
assets:checking $-10.0
Save this transaction to the journal ? [y]:
Saved.
Starting the next transaction (. or ctrl-D/ctrl-C to quit)
Date [2015/05/22]: <CTRL-D> $
}})
_include_({{hledger_balance.m4.md}}) _include_({{hledger_balance.m4.md}})