Skip to content

Commit 9fe5a21

Browse files
jakeschepisclaude
andcommitted
feat: add --output/-o flag for all commands, bump to v6.2.0
Add --output <format> string flag as alternative to boolean flags (--json, --csv, etc). Supports: json, compact-json, csv, markdown, table, raw, pretty. Invalid values return structured error envelope with suggestions. Also fixes publish workflow to report platform package failures instead of silently ignoring them with || true. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6c9f2d7 commit 9fe5a21

11 files changed

Lines changed: 159 additions & 12 deletions

File tree

.github/workflows/publish.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,20 @@ jobs:
107107
env:
108108
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
109109
run: |
110+
FAILED=0
110111
for pkg in npm/notion-cli-*/; do
111112
echo "Publishing $pkg..."
112113
cd "$pkg"
113-
npm publish --access public || true
114+
if ! npm publish --access public; then
115+
echo "::warning::Failed to publish $pkg"
116+
FAILED=1
117+
fi
114118
cd ../..
115119
done
120+
if [ "$FAILED" -eq 1 ]; then
121+
echo "::error::One or more platform packages failed to publish. Check that the NPM_TOKEN has write access to the @coastal-programs scope and that the token owner is an org member with publish permissions."
122+
exit 1
123+
fi
116124
117125
- name: Publish main wrapper package
118126
if: steps.check-version.outputs.version_exists == 'false'

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [6.2.0] - 2026-03-02
11+
12+
### Added
13+
- **`--output` / `-o` flag**: All commands now accept `--output <format>` (or `-o <format>`) as an alternative to boolean flags like `--json`, `--csv`, etc. Valid formats: `json`, `compact-json`, `csv`, `markdown`, `table`, `raw`, `pretty`. Invalid values return a structured error with suggestions.
14+
- **Platform binary packages on npm**: First publish of all 5 platform-specific packages (`@coastal-programs/notion-cli-darwin-arm64`, `-darwin-x64`, `-linux-x64`, `-linux-arm64`, `-win32-x64`). Users on supported platforms now get a native binary via npm's optional dependency resolution instead of relying on the postinstall GitHub Release fallback.
15+
16+
### Fixed
17+
- **Publish workflow**: Platform package publish failures are no longer silently ignored (`|| true` removed). The workflow now reports explicit errors with guidance when platform packages fail to publish.
18+
1019
## [6.1.2] - 2026-03-02
1120

1221
### Fixed

internal/cli/commands/db.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,17 @@ func resolveID(raw string) (string, error) {
5252
}
5353

5454
// outputFormat returns the output.Format from command flags.
55+
// The --output string flag takes precedence over the boolean shorthand flags.
5556
func outputFormat(cmd *cobra.Command) output.Format {
57+
// Check --output string flag first (takes precedence).
58+
if outStr, _ := cmd.Flags().GetString("output"); outStr != "" {
59+
f, err := output.ParseFormat(outStr)
60+
if err == nil {
61+
return f
62+
}
63+
// Invalid value — fall through to boolean flags.
64+
}
65+
5666
if v, _ := cmd.Flags().GetBool("json"); v {
5767
return output.FormatJSON
5868
}
@@ -74,6 +84,26 @@ func outputFormat(cmd *cobra.Command) output.Format {
7484
return output.FormatTable
7585
}
7686

87+
// validateOutputFlag checks the --output flag value upfront and returns an error
88+
// for invalid values. Call this at the start of RunE handlers.
89+
func validateOutputFlag(cmd *cobra.Command) error {
90+
outStr, _ := cmd.Flags().GetString("output")
91+
if outStr == "" {
92+
return nil
93+
}
94+
_, err := output.ParseFormat(outStr)
95+
if err != nil {
96+
return &clierrors.NotionCLIError{
97+
Code: clierrors.CodeInvalidRequest,
98+
Message: fmt.Sprintf("Invalid --output format %q", outStr),
99+
Suggestions: []string{
100+
fmt.Sprintf("Valid formats: %s", strings.Join(output.ValidFormats, ", ")),
101+
},
102+
}
103+
}
104+
return nil
105+
}
106+
77107
// handleError prints an error using the output printer and returns it for
78108
// cobra to handle the exit code.
79109
func handleError(cmd *cobra.Command, err error) error {
@@ -106,14 +136,38 @@ func handleError(cmd *cobra.Command, err error) error {
106136
}
107137

108138
// addOutputFlags adds the shared output format flags to a command.
139+
// Both --output <format> and boolean shorthand flags (--json, --csv, …) are
140+
// supported. The --output flag takes precedence when both are provided.
141+
// A PreRunE hook is chained to validate the --output value early.
109142
func addOutputFlags(cmd *cobra.Command) {
143+
cmd.Flags().StringP("output", "o", "", "Output format: json, compact-json, csv, markdown, table, raw, pretty")
110144
cmd.Flags().Bool("json", false, "Output as JSON envelope")
111145
cmd.Flags().Bool("compact-json", false, "Output as compact JSON (single line)")
112146
cmd.Flags().Bool("raw", false, "Output raw API response without envelope")
113147
cmd.Flags().Bool("csv", false, "Output as CSV")
114148
cmd.Flags().Bool("markdown", false, "Output as markdown table")
115149
cmd.Flags().Bool("pretty", false, "Output as pretty-printed JSON")
116150
cmd.MarkFlagsMutuallyExclusive("json", "compact-json", "csv", "markdown", "raw", "pretty")
151+
152+
// Chain a PreRunE that validates the --output value upfront.
153+
prev := cmd.PreRunE
154+
cmd.PreRunE = func(c *cobra.Command, args []string) error {
155+
if prev != nil {
156+
if err := prev(c, args); err != nil {
157+
return err
158+
}
159+
}
160+
if err := validateOutputFlag(c); err != nil {
161+
// Print the structured error envelope before returning,
162+
// since SilenceErrors is set on the root command.
163+
p := output.NewPrinter(output.FormatTable)
164+
if cliErr, ok := err.(*clierrors.NotionCLIError); ok {
165+
p.PrintError(cliErr.Code, cliErr.Message, cliErr.Details, cliErr.Suggestions)
166+
}
167+
return err
168+
}
169+
return nil
170+
}
117171
}
118172

119173
// maxPaginationPages is the safety limit for pagination loops.

npm/notion-cli-darwin-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coastal-programs/notion-cli-darwin-arm64",
3-
"version": "6.1.2",
3+
"version": "6.2.0",
44
"description": "notion-cli binary for macOS ARM64 (Apple Silicon)",
55
"os": ["darwin"],
66
"cpu": ["arm64"],

npm/notion-cli-darwin-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coastal-programs/notion-cli-darwin-x64",
3-
"version": "6.1.2",
3+
"version": "6.2.0",
44
"description": "notion-cli binary for macOS x64 (Intel)",
55
"os": ["darwin"],
66
"cpu": ["x64"],

npm/notion-cli-linux-arm64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coastal-programs/notion-cli-linux-arm64",
3-
"version": "6.1.2",
3+
"version": "6.2.0",
44
"description": "notion-cli binary for Linux ARM64",
55
"os": ["linux"],
66
"cpu": ["arm64"],

npm/notion-cli-linux-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coastal-programs/notion-cli-linux-x64",
3-
"version": "6.1.2",
3+
"version": "6.2.0",
44
"description": "notion-cli binary for Linux x64",
55
"os": ["linux"],
66
"cpu": ["x64"],

npm/notion-cli-win32-x64/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coastal-programs/notion-cli-win32-x64",
3-
"version": "6.1.2",
3+
"version": "6.2.0",
44
"description": "notion-cli binary for Windows x64",
55
"os": ["win32"],
66
"cpu": ["x64"],

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@coastal-programs/notion-cli",
3-
"version": "6.1.2",
3+
"version": "6.2.0",
44
"description": "Unofficial Notion CLI optimized for automation and AI agents. Single-binary Go implementation with intelligent caching, retry logic, structured error handling.",
55
"author": "Jake Schepis <jake@coastalprograms.com>",
66
"bin": {
@@ -24,11 +24,11 @@
2424
"release": "make release"
2525
},
2626
"optionalDependencies": {
27-
"@coastal-programs/notion-cli-darwin-arm64": "6.1.2",
28-
"@coastal-programs/notion-cli-darwin-x64": "6.1.2",
29-
"@coastal-programs/notion-cli-linux-x64": "6.1.2",
30-
"@coastal-programs/notion-cli-linux-arm64": "6.1.2",
31-
"@coastal-programs/notion-cli-win32-x64": "6.1.2"
27+
"@coastal-programs/notion-cli-darwin-arm64": "6.2.0",
28+
"@coastal-programs/notion-cli-darwin-x64": "6.2.0",
29+
"@coastal-programs/notion-cli-linux-x64": "6.2.0",
30+
"@coastal-programs/notion-cli-linux-arm64": "6.2.0",
31+
"@coastal-programs/notion-cli-win32-x64": "6.2.0"
3232
},
3333
"engines": {
3434
"node": ">=18.0.0"

pkg/output/output.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"io"
77
"os"
88
"sort"
9+
"strings"
910
"time"
1011
)
1112

@@ -22,6 +23,31 @@ const (
2223
FormatPretty Format = "pretty"
2324
)
2425

26+
// ValidFormats lists all accepted values for the --output flag.
27+
var ValidFormats = []string{"json", "compact-json", "raw", "table", "csv", "markdown", "pretty"}
28+
29+
// ParseFormat converts a string to a Format, returning an error for unknown values.
30+
func ParseFormat(s string) (Format, error) {
31+
switch strings.ToLower(strings.TrimSpace(s)) {
32+
case "json":
33+
return FormatJSON, nil
34+
case "compact-json":
35+
return FormatCompactJSON, nil
36+
case "raw":
37+
return FormatRaw, nil
38+
case "table":
39+
return FormatTable, nil
40+
case "csv":
41+
return FormatCSV, nil
42+
case "markdown":
43+
return FormatMarkdown, nil
44+
case "pretty":
45+
return FormatPretty, nil
46+
default:
47+
return "", fmt.Errorf("unknown output format %q (valid: %s)", s, strings.Join(ValidFormats, ", "))
48+
}
49+
}
50+
2551
// Printer handles formatted output for CLI commands.
2652
type Printer struct {
2753
Format Format

0 commit comments

Comments
 (0)