Skip to content

Commit b1857bf

Browse files
authored
Merge pull request #10 from quantcli/feat/format-markdown-alias
feat!: drop --json shortcut, default --format to "markdown"
2 parents 76471ab + 054064e commit b1857bf

4 files changed

Lines changed: 22 additions & 24 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Export your personal nutrition, biometric, and food-log data from [Cronometer](h
1010
## Features
1111

1212
- **Five export endpoints** — servings (per-food log with full nutrient breakdown), nutrition (daily totals), biometrics (weight, body fat, custom metrics), exercises, and notes
13-
- **Markdown by default, JSON on demand** — narrow fitdown-style markdown reads well in chat and terminals; pass `--json` for the full structured row to pipe through `jq`
13+
- **Markdown by default, JSON on demand** — narrow fitdown-style markdown reads well in chat and terminals; pass `--format json` for the full structured row to pipe through `jq`
1414
- **Date selection**`--since` / `--until` accepting `today`, `yesterday`, `YYYY-MM-DD`, or `Nd`/`Nw`/`Nm`/`Ny` on every subcommand
1515
- **Single static binary** — no Python or Node runtime; drop it in `~/bin/` and go
1616
- **Credentials via env**`CRONOMETER_USERNAME` / `CRONOMETER_PASSWORD`, no config file needed
@@ -153,11 +153,11 @@ crono-export notes --since 30d
153153

154154
Default output is narrow, [Fitdown](https://github.com/datavis-tech/fitdown)-style markdown — date-grouped headings, one bullet per non-zero field, no wide tables. Markdown reads well in chat and on a terminal and is easy for an LLM to consume inline.
155155

156-
For programmatic use, pass `--json` (or `--format json`) to get the full structured row as a JSON array on stdout — nothing suppressed, easy to pipe through `jq`. Errors always go to stderr, so JSON output stays clean for piping.
156+
For programmatic use, pass `--format json` to get the full structured row as a JSON array on stdout — nothing suppressed, easy to pipe through `jq`. Errors always go to stderr, so JSON output stays clean for piping.
157157

158158
```sh
159159
crono-export servings --since today # markdown, default
160-
crono-export servings --since today --json | jq '[.[] | {food: .FoodName, protein: .ProteinG}]'
160+
crono-export servings --since today --format json | jq '[.[] | {food: .FoodName, protein: .ProteinG}]'
161161
```
162162

163163
LLM agents: run `crono-export prime` for a one-screen orientation describing both formats, all subcommands, the date flags, and `jq` recipes.

cmd/format.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,23 @@ const (
2323
kindNotes
2424
)
2525

26-
// AddFormatFlags registers --format and --json on every export subcommand.
26+
// AddFormatFlags registers --format on every export subcommand, per the
27+
// quantcli shared contract §4.
28+
// https://github.com/quantcli/common/blob/main/CONTRACT.md#4-output-format
2729
func AddFormatFlags(cmd *cobra.Command) {
28-
cmd.Flags().String("format", "md", "output format: md|json")
29-
cmd.Flags().Bool("json", false, "shortcut for --format json")
30+
cmd.Flags().String("format", "markdown",
31+
"Output format: markdown (default, fitdown-style) or json")
3032
}
3133

3234
func chosenFormat(cmd *cobra.Command) (string, error) {
3335
f, _ := cmd.Flags().GetString("format")
34-
if j, _ := cmd.Flags().GetBool("json"); j {
35-
f = "json"
36-
}
3736
switch f {
38-
case "md", "markdown":
39-
return "md", nil
37+
case "", "markdown", "md":
38+
return "markdown", nil
4039
case "json":
4140
return "json", nil
4241
default:
43-
return "", fmt.Errorf("unknown --format %q (want md or json)", f)
42+
return "", fmt.Errorf("unknown --format %q (use markdown or json)", f)
4443
}
4544
}
4645

cmd/prime.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ OUTPUT FORMATS
1818
bullet per non-zero field, easy to skim and easy for an LLM to consume
1919
inline. Zero-valued nutrients are suppressed in markdown.
2020
21-
--json (or --format json) Pretty-printed JSON ARRAY of full rows.
22-
Use this when you want the complete row,
23-
when piping to jq, or when round-tripping
24-
into other tools. Nothing is suppressed.
21+
--format json Pretty-printed JSON ARRAY of full rows. Use this when
22+
you want the complete row, when piping to jq, or when
23+
round-tripping into other tools. Nothing is suppressed.
2524
2625
Errors go to stderr. You do NOT need '2>&1'. Exit code is 0 on
2726
success and non-zero on auth or network failure. An empty result is
@@ -77,28 +76,28 @@ EXAMPLES
7776
crono-export nutrition --since today
7877
7978
# Today's macros, parsed (numbers via tonumber)
80-
crono-export nutrition --since today --json | jq '.[] | {
79+
crono-export nutrition --since today --format json | jq '.[] | {
8180
date: .Date,
8281
kcal: (."Energy (kcal)" | tonumber),
8382
protein: (."Protein (g)" | tonumber)
8483
}'
8584
8685
# 7-day protein total (servings is typed — no tonumber needed)
87-
crono-export servings --since 7d --json | jq '[.[] | .ProteinG] | add'
86+
crono-export servings --since 7d --format json | jq '[.[] | .ProteinG] | add'
8887
8988
# All foods from today's breakfast
90-
crono-export servings --since today --json | jq '[.[] | select(.Group == "Breakfast") | .FoodName]'
89+
crono-export servings --since today --format json | jq '[.[] | select(.Group == "Breakfast") | .FoodName]'
9190
9291
# Latest weight reading in a 30-day window
93-
crono-export biometrics --since 30d --json | jq 'map(select(.Metric == "Weight")) | sort_by(.RecordedTime) | last'
92+
crono-export biometrics --since 30d --format json | jq 'map(select(.Metric == "Weight")) | sort_by(.RecordedTime) | last'
9493
9594
GOTCHAS
9695
- "Today" is your LOCAL calendar day, not UTC.
9796
- 'nutrition' and 'notes' JSON values are STRINGS (raw CSV) — cast with
9897
'jq tonumber' when doing math. 'servings', 'biometrics', 'exercises'
9998
JSON values are already typed numbers.
10099
- Markdown drops zero-valued nutrients to stay readable. If you need
101-
every column (including zeros), use --json.
100+
every column (including zeros), use --format json.
102101
- Cronometer logs by calendar day; nothing here is real-time. Two
103102
'--since today' calls moments apart return the same data.
104103
`
@@ -107,7 +106,7 @@ var primeCmd = &cobra.Command{
107106
Use: "prime",
108107
Short: "Print an LLM-targeted primer (output formats, subcommands, jq recipes)",
109108
Long: `Print a one-screen primer aimed at LLM agents calling this CLI as a tool.
110-
Covers the output formats (markdown by default, --json for structured),
109+
Covers the output formats (markdown by default, --format json for structured),
111110
auth env vars, the subcommands and what their rows look like, the shared
112111
date flags, and a few jq recipes for common questions.`,
113112
RunE: func(cmd *cobra.Command, _ []string) error {

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var rootCmd = &cobra.Command{
1313
Short: "Export Cronometer nutrition, biometrics, and food log data",
1414
Long: `crono-export reads your personal Cronometer data via the same export
1515
endpoints the web app uses and prints it on stdout. Default output is
16-
narrow, fitdown-style markdown; pass --json (or --format json) for the
17-
full structured row.
16+
narrow, fitdown-style markdown; pass --format json for the full
17+
structured row.
1818
1919
Credentials must be supplied via environment variables:
2020
CRONOMETER_USERNAME your Cronometer email

0 commit comments

Comments
 (0)