Documentation
¶
Overview ¶
Package docsgen renders docs/cli.md from a cobra command tree using cobra/doc. It is its own package -- imported only by the docsgen-tagged cli/internal/cmd/docs_cmd.go -- so cobra/doc (and the go-md2man and blackfriday packages it pulls in) never links into the release freshbooks binary (D6). This package is the only non-test importer of github.com/spf13/cobra/doc in the cli module.
Index ¶
Constants ¶
const Header = `# freshbooks CLI reference
A kubectl-style command-line client for the FreshBooks REST API. This file's "Command reference" section below is generated by ` + "`mise run docs`" + ` (` + "`scripts/docs.sh`" + `, which runs ` + "`freshbooks docs`" + `) from the cobra command tree; do not hand-edit past that point.
## Install
Download a release archive from the ` + "`cli/vX.Y.Z`" + ` GitHub releases, or build from source: ` + "`go build ./cli/cmd/freshbooks`" + ` from the repository root (requires the ` + "`go.work`" + ` workspace, so build from inside the repo).
## First login
1. Register an app at https://www.freshbooks.com/api/start and note its client id and secret. Its registered redirect URI must be ` + "`https://localhost:8765/callback`" + ` (or whatever ` + "`--callback-port`" + ` you pass).
2. Set ` + "`FRESHBOOKS_CLIENT_ID`" + ` and ` + "`FRESHBOOKS_CLIENT_SECRET`" + ` and run ` + "`freshbooks auth login`" + ` (or pass ` + "`--client-id <id> --client-secret <secret>`" + ` directly, though that puts the secret in ` + "`ps`" + ` output and shell history -- see Security notes below). This opens a browser to FreshBooks' consent screen and starts a loopback HTTPS listener on 127.0.0.1 to receive the redirect.
3. Your browser will warn that the certificate is untrusted -- this is expected. The CLI generates a throwaway, self-signed certificate for this one callback, in-process, and never writes it to disk. Accept the warning to continue.
4. On success the CLI stores the token under ` + "`$XDG_CONFIG_HOME/freshbooks/credentials/<context>.json`" + ` (falling back to ` + "`~/.config/freshbooks/credentials/<context>.json`" + ` if ` + "`$XDG_CONFIG_HOME`" + ` is unset -- the common case on macOS and most Linux desktops), mode 0600, and prints nothing from the token itself.
5. Over SSH or in an environment with no browser, pass ` + "`--no-browser`" + `: the CLI prints the authorization URL and reads either the full redirected URL or a bare authorization code from stdin instead of listening.
## Contexts
A context is a named account/business/business-uuid triple plus its own credentials file. ` + "`freshbooks config set-context <name> --account ... --business ...`" + ` creates or updates one; ` + "`freshbooks config use-context <name>`" + ` switches ` + "`config.yaml`" + `'s current context; ` + "`freshbooks config contexts`" + ` lists them; ` + "`freshbooks config view`" + ` prints the resolved file. ` + "`config.yaml`" + ` never carries a secret -- credentials are a separate file per context, managed by ` + "`freshbooks auth`" + `.
The scope flags (` + "`--account`/`--business`/`--business-uuid`" + `) and ` + "`--context`" + ` resolve in this order: an explicit flag, then an environment variable, then the current context's config.yaml value, then (for ` + "`--context`" + `) the built-in default ` + "`\"default\"`" + `. An empty environment variable counts as unset, not as an explicit empty value. Every other global flag resolves flag then env then its own built-in default -- config.yaml is consulted only for the scope fields and the current context, never for ` + "`--output`, `--base-url`, `--timeout`, or `--log-level`" + `. The remaining global flags are booleans (` + "`--dry-run`, `--yes`, `--no-headers`, `-q/--quiet`" + `) and have no environment twin at all; nobody has asked for one (` + "`FRESHBOOKS_YES`" + `, say), and adding one before someone needs it would just be more surface to keep documented.
The nine environment variables the resolution chain above actually reads:
| Variable | Resolves | Falls back to |
|---|---|---|
| ` + "`FRESHBOOKS_CONTEXT`" + ` | ` + "`--context`" + ` | config.yaml ` + "`current-context`" + `, then ` + "`\"default\"`" + ` |
| ` + "`FRESHBOOKS_ACCOUNT_ID`" + ` | ` + "`--account`" + ` | the current context's config.yaml account |
| ` + "`FRESHBOOKS_BUSINESS_ID`" + ` | ` + "`--business`" + ` | the current context's config.yaml business |
| ` + "`FRESHBOOKS_BUSINESS_UUID`" + ` | ` + "`--business-uuid`" + ` | the current context's config.yaml business-uuid |
| ` + "`FRESHBOOKS_CONFIG`" + ` | ` + "`--config`" + ` | ` + "`$XDG_CONFIG_HOME/freshbooks/config.yaml`" + `, or ` + "`~/.config/freshbooks/config.yaml`" + ` if ` + "`$XDG_CONFIG_HOME`" + ` is unset |
| ` + "`FRESHBOOKS_OUTPUT`" + ` | ` + "`-o/--output`" + ` | ` + "`table`" + ` on a TTY, ` + "`json`" + ` otherwise (does not apply to the two Binary commands, which read their local ` + "`-o`" + ` file-path flag directly and ignore this one entirely) |
| ` + "`FRESHBOOKS_BASE_URL`" + ` | ` + "`--base-url`" + ` | the lib's default API base URL (` + "`--base-url`" + ` itself is hidden from ` + "`--help`" + ` -- it exists for testing and sandboxes, not everyday use) |
| ` + "`FRESHBOOKS_TIMEOUT`" + ` | ` + "`--timeout`" + ` | ` + "`30s`" + ` |
| ` + "`FRESHBOOKS_LOG_LEVEL`" + ` | ` + "`--log-level`" + ` | ` + "`warn`" + ` |
` + "`FRESHBOOKS_CLIENT_ID`" + ` and ` + "`FRESHBOOKS_CLIENT_SECRET`" + ` are read too, but outside this chain: registry commands have no ` + "`--client-id`/`--client-secret`" + ` flags of their own (only ` + "`auth login`/`auth token`/`auth logout`" + ` take those directly), so a registry command's token-refresh path falls back to these two env vars with nothing above them to override.
## Output formats
` + "`-o/--output`" + ` selects ` + "`json`" + `, ` + "`yaml`" + `, ` + "`table`" + `, or ` + "`name`" + `. The default is ` + "`table`" + ` when stdout is a terminal and ` + "`json`" + ` otherwise, so scripts and pipelines get structured output without passing the flag explicitly. ` + "`--no-headers`" + ` suppresses the header row in table output; ` + "`-q/--quiet`" + ` suppresses non-result chatter (never errors).
## Exit codes
| Code | Meaning |
|---|---|
| 0 | success |
| 1 | an API or other runtime error |
| 2 | a usage error, for example: a bad flag, an unrecognized --log-level, a malformed --file body, a missing scope, --all combined with --page/--per-page, --dry-run on an auth or config command, a destructive command run without --yes on a TTY, -o/--output on a binary command refusing to overwrite an existing file (without --force) or write to a TTY, a wrong positional argument count, a non-integer --account/--business, an invalid FRESHBOOKS_TIMEOUT, a --query parse failure, a --file open/read failure, an unknown context passed to config use-context, or missing client credentials on auth login |
| 3 | an auth error: no stored credentials for the context, or the API answered 401 |
| 4 | the API answered 404 |
Under ` + "`-o json`" + `, an error is one JSON object on stderr: ` + "`{\"error\": {\"status\", \"code\", \"message\", \"field\", \"family\", \"exit\"}}`" + `. Otherwise it is one human-readable line on stderr.
## Automation notes
Every registry command accepts ` + "`--dry-run`" + `, which prints the request's method and URL (and its body, for a write) to stdout and sends nothing -- useful for verifying a command's shape before running it for real. ` + "`auth`" + ` and ` + "`config`" + ` commands reject ` + "`--dry-run`" + ` outright (exit 2) instead of silently ignoring it: there is no request to preview, and ` + "`auth logout`" + ` in particular really does revoke and delete on every run.
Destructive commands -- the ones whose ` + "`Short`" + ` help line in the command reference below ends with " (destructive: requires --yes on a TTY)" -- refuse to run without ` + "`--yes`" + ` when stdin is a terminal.
A Binary command's ` + "`-o <file>`" + ` (` + "`invoices pdf`, `reports download-invoice-details-csv`" + `) refuses to overwrite an existing file without ` + "`--force`" + `, and refuses ` + "`-o -`" + ` when stdout is a terminal (binary bytes would corrupt it). This ` + "`-o`" + ` is a different flag from the global ` + "`-o/--output`" + ` formatting flag above and shadows it locally on these two commands; similarly, ` + "`auth login --login-timeout`" + ` (how long to wait for the browser callback) is a different flag from the global ` + "`--timeout`" + ` (per-request timeout) -- named differently precisely so it does not shadow it. The scopes ` + "`auth login`" + ` requests (43 by default -- the grantable ` + "`user:*`" + ` scopes this toolset's endpoints use, which is not the same list as https://www.freshbooks.com/api/scopes and deliberately leaves out ` + "`account`" + `, ` + "`riskhub`" + `, and ` + "`mcp:*`" + ` -- or an explicit ` + "`--scopes`" + ` list) must all exist AND be enabled on the app in the developer portal; otherwise the consent page answers "The requested scope is invalid, unknown, or malformed" and nothing is stored. See ` + "`docs/authentication.md`" + `.
## The api escape hatch
` + "`freshbooks api <METHOD> <path> [-f file|-] [--query key=value]...`" + ` calls the same authenticated, retrying transport every registry command uses, for an endpoint this CLI does not model as its own command yet. path is rooted at the API base, e.g. ` + "`/accounting/account/ACM123/systems/systems/1`" + `.
## Security notes
- The access token is printed by exactly one command: ` + "`freshbooks auth token`" + `. Every other command, including ` + "`--dry-run`" + `, ` + "`config view`" + `, and ` + "`auth status`" + `, never prints it.
- Credentials files are written 0600 inside a 0700 directory.
- The loopback login listener's TLS certificate is generated fresh for each login, in-process, and never touches disk.
- ` + "`identity applications`" + ` redacts every ` + "`client_secret`" + ` in its output by default; pass ` + "`--show-secrets`" + ` to include them. ` + "`identity create-application`" + ` and ` + "`identity update-application`" + ` always print the ` + "`client_secret`" + ` in their result -- that is the only time it is shown, since it cannot be retrieved later. Passing ` + "`--client-secret`" + ` (or ` + "`--client-id`" + `) on the command line to ` + "`auth login`/`auth token`/`auth logout`" + ` puts it in ` + "`ps`" + ` output and shell history; prefer ` + "`FRESHBOOKS_CLIENT_ID`/`FRESHBOOKS_CLIENT_SECRET`" + ` instead.
## Command reference
`
Header is the hand-written section docs/cli.md opens with, ahead of the generated command reference Generate appends below it.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
Generate renders the full docs/cli.md content: Header followed by one cobra/doc Markdown section per command in the tree, depth-first, children sorted by name at each level for a deterministic, idempotent result (mise run docs must produce byte-identical output on every run against an unchanged command tree).
Types ¶
This section is empty.