Skip to content

Commit e34372b

Browse files
refactor(cli): output format is a profile setting, not a flag
Drops `-o, --output`. Format is set once per profile with `sim configure --set-output <format>`, or overridden ambiently with SIM_OUTPUT for a one-off (`SIM_OUTPUT=json sim logs list | jq`) and for CI, which already runs file-less on env alone. Both remaining sources are ambient — set once, then read by every later command — so an unrecognized value falls back to `table` rather than breaking the CLI. There is no longer a strict tier, because there is no longer anything typed per-invocation to be strict about. Frees `-o` for `sim files download -o <path>`, which previously had to share the short flag with a global that meant something else entirely. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EsThUPqZXjwuuyRjBbmVkj
1 parent 7ef8b49 commit e34372b

5 files changed

Lines changed: 35 additions & 26 deletions

File tree

packages/sim-cli/README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Each setting resolves independently, first match wins:
5353

5454
| Rank | Source |
5555
| --- | --- |
56-
| 1 | Command-line flag (`--endpoint`, `--workspace`, `--output`) |
56+
| 1 | Command-line flag (`--endpoint`, `--workspace`) |
5757
| 2 | Environment (`SIM_ENDPOINT`, `SIM_API_KEY`, `SIM_WORKSPACE`, `SIM_OUTPUT`) |
5858
| 3 | `~/.sim/config` / `~/.sim/credentials` for the selected profile |
5959
| 4 | Built-in default (`https://sim.ai`, `table`) |
@@ -154,7 +154,9 @@ everything" default.
154154

155155
### Output formats
156156

157-
`--output` / `-o`, or `SIM_OUTPUT`, or `output =` in the profile:
157+
Output format is a **profile setting**, not a per-command flag — there is no
158+
`--output`. Set it once with `sim configure --set-output <format>`, or override
159+
ambiently with `SIM_OUTPUT` for a one-off or for CI:
158160

159161
| Format | For |
160162
| --- | --- |
@@ -169,20 +171,23 @@ duration stays `1500`, not `"1.5s"` — so switching format never changes the da
169171
parsing.
170172

171173
```bash
172-
sim logs list --level error -o json | jq -r '.[].executionId'
173-
sim logs list --level error -o yaml > logs.yaml
174+
sim configure --set-output json # for this profile, from now on
175+
sim configure --set-output text --profile scripts # a profile dedicated to scripting
174176

175-
sim files list -o text | while IFS=$'\t' read -r id name size type uploaded; do
177+
SIM_OUTPUT=json sim logs list --level error | jq -r '.[].executionId'
178+
SIM_OUTPUT=yaml sim logs list --level error > logs.yaml
179+
180+
SIM_OUTPUT=text sim files list | while IFS=$'\t' read -r id name size type uploaded; do
176181
echo "$id $name"
177182
done
178183
```
179184

180185
An absent value is an em-dash in `table` and an **empty field** in `text`, so
181186
emptiness tests downstream behave.
182187

183-
A bad `--output` is an error; a bad `SIM_OUTPUT` or `output =` is ignored and
184-
falls back to `table` — ambient settings should not brick every command, but a
185-
flag you just typed should not be silently disregarded.
188+
A bad `SIM_OUTPUT` or `output =` is ignored and falls back to `table`. Both are
189+
ambient — set once, then read by every later command — so one bad value should
190+
not break the CLI outright.
186191

187192
## How this stays in sync with the API
188193

packages/sim-cli/src/config/profile.test.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,23 @@ describe('profile resolution', () => {
9797
})
9898

9999
it('ignores an unrecognized output format instead of failing the whole resolve', () => {
100-
// Ambient sources tolerate garbage so one bad value cannot brick every
101-
// command; the `--output` flag is strict instead (commander `.choices`).
100+
// Both output sources are ambient — set once, then every later command reads
101+
// them — so a bad value falls back rather than breaking the CLI outright.
102102
process.env.SIM_OUTPUT = 'xml'
103103
expect(resolveProfile().output).toBe('table')
104+
105+
process.env.SIM_OUTPUT = undefined
106+
writeConfigProfile('default', { output: 'xml' })
107+
expect(resolveProfile().output).toBe('table')
108+
})
109+
110+
it('takes the output format from the profile, and lets the env override it', () => {
111+
// There is deliberately no `--output` flag: format is a profile setting.
112+
writeConfigProfile('default', { output: 'yaml' })
113+
expect(resolveProfile()).toMatchObject({ output: 'yaml', sources: { output: 'config' } })
114+
115+
process.env.SIM_OUTPUT = 'json'
116+
expect(resolveProfile()).toMatchObject({ output: 'json', sources: { output: 'env' } })
104117
})
105118

106119
it('accepts every documented output format from the environment', () => {

packages/sim-cli/src/config/profile.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ export interface ProfileOverrides {
4747
endpoint?: string
4848
apiKey?: string
4949
workspaceId?: string
50-
output?: string
5150
}
5251

5352
/**
@@ -186,9 +185,13 @@ export function resolveProfile(overrides: ProfileOverrides = {}): ResolvedProfil
186185
'unset'
187186
)
188187

188+
/**
189+
* No flag tier: output format is a profile setting, not a per-command one.
190+
* `SIM_OUTPUT` stays as the one-off escape hatch (`SIM_OUTPUT=json sim … | jq`)
191+
* and as the file-less path for CI, but there is deliberately no `--output`.
192+
*/
189193
const output = resolve<OutputFormat>(
190194
[
191-
['flag', parseOutput(overrides.output)],
192195
['env', parseOutput(process.env.SIM_OUTPUT)],
193196
['config', parseOutput(config.output)],
194197
],

packages/sim-cli/src/context.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export interface GlobalOptions {
77
profile?: string
88
endpoint?: string
99
workspace?: string
10-
output?: string
1110
}
1211

1312
/**
@@ -25,7 +24,6 @@ export function profileFrom(command: Command, extra: ProfileOverrides = {}): Res
2524
profile: globals.profile,
2625
endpoint: globals.endpoint,
2726
workspaceId: globals.workspace,
28-
output: globals.output,
2927
...extra,
3028
})
3129
}

packages/sim-cli/src/index.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#!/usr/bin/env node
22

33
import chalk from 'chalk'
4-
import { Command, Option } from 'commander'
4+
import { Command } from 'commander'
55
import { loginCommand, logoutCommand, profilesCommand, whoamiCommand } from './commands/auth.js'
66
import { configureCommand } from './commands/configure.js'
77
import { filesCommand } from './commands/files.js'
88
import { knowledgeCommand } from './commands/knowledge.js'
99
import { logsCommand } from './commands/logs.js'
1010
import { tablesCommand } from './commands/tables.js'
1111
import { workflowsCommand } from './commands/workflows.js'
12-
import { OUTPUT_FORMATS } from './config/index.js'
1312
import { SimApiError } from './http/client.js'
1413

1514
const program = new Command()
@@ -21,16 +20,6 @@ program
2120
.option('-p, --profile <name>', 'Profile to use (env: SIM_PROFILE)')
2221
.option('--endpoint <url>', 'Sim deployment to talk to (env: SIM_ENDPOINT)')
2322
.option('-w, --workspace <id>', 'Workspace to target (env: SIM_WORKSPACE)')
24-
// `.choices` so a typo'd format is an error, not a silent fall back to
25-
// `table`. Deliberately stricter than SIM_OUTPUT and the config file, which
26-
// tolerate an unknown value: those are ambient and set once, and a bad one
27-
// should not make every command fail — but a flag is an instruction just
28-
// typed, so honouring something else is a lie.
29-
.addOption(
30-
new Option('-o, --output <format>', 'Output format (env: SIM_OUTPUT)').choices([
31-
...OUTPUT_FORMATS,
32-
])
33-
)
3423

3524
program.addCommand(loginCommand())
3625
program.addCommand(logoutCommand())
@@ -54,6 +43,7 @@ Examples:
5443
$ sim login --profile dev --endpoint http://localhost:3000
5544
$ sim workflows list
5645
$ sim logs list --level error --limit 20
46+
$ sim configure --set-output json Output format is a profile setting
5747
$ sim knowledge search "refund policy" --kb kb_123
5848
$ sim whoami --profile dev
5949
`

0 commit comments

Comments
 (0)