Skip to content

Commit 9682ff5

Browse files
committed
fix: honor configured quota output format
1 parent 906a57b commit 9682ff5

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

src/commands/quota/show.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ export default defineCommand({
1717
'mmx quota show',
1818
'mmx quota show --output json',
1919
],
20-
async run(config: Config, flags: GlobalFlags) {
20+
async run(config: Config, _flags: GlobalFlags) {
2121
if (config.dryRun) {
2222
console.log('Would fetch quota information.');
2323
return;
2424
}
2525

26-
const format = detectOutputFormat(flags.output as string | undefined);
26+
const format = detectOutputFormat(config.output);
2727
const credential = await resolveCredential(config);
2828
const endpoint = selectUsageEndpoint(config.baseUrl, credential);
2929

test/commands/quota/show.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,39 @@ describe('quota show command', () => {
6262
}
6363
});
6464

65+
it('honors JSON output resolved from config without an output flag', async () => {
66+
server = createMockServer({
67+
routes: {
68+
'/v1/token_plan/remains': () => jsonResponse({
69+
model_remains: [],
70+
base_resp: { status_code: 0, status_msg: 'ok' },
71+
}),
72+
},
73+
});
74+
75+
const output: string[] = [];
76+
const originalLog = console.log;
77+
const ttyDescriptor = Object.getOwnPropertyDescriptor(process.stdout, 'isTTY');
78+
console.log = (message?: unknown) => { output.push(String(message ?? '')); };
79+
Object.defineProperty(process.stdout, 'isTTY', { value: true, configurable: true });
80+
81+
try {
82+
await showCommand.execute(
83+
{ ...baseConfig, baseUrl: server.url, output: 'json' },
84+
{ ...baseFlags, output: undefined },
85+
);
86+
} finally {
87+
console.log = originalLog;
88+
if (ttyDescriptor) {
89+
Object.defineProperty(process.stdout, 'isTTY', ttyDescriptor);
90+
} else {
91+
delete (process.stdout as unknown as Record<string, unknown>).isTTY;
92+
}
93+
}
94+
95+
expect(JSON.parse(output.join('\n'))).toMatchObject({ model_remains: [] });
96+
});
97+
6598
it('uses account/query_balance for sk-api keys', async () => {
6699
server = createMockServer({
67100
routes: {

0 commit comments

Comments
 (0)