Skip to content

Commit b0e40d1

Browse files
committed
format
1 parent 3324d2e commit b0e40d1

File tree

11 files changed

+751
-895
lines changed

11 files changed

+751
-895
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ hume tts "I said, are you serious?" --voice-name whisperer
2121
## Installation
2222

2323
The Hume CLI is distributed [via NPM](https://www.npmjs.com/package/@humeai/cli). You can install it globally via:
24+
2425
```shell
2526
npm install -g @humeai/cli
2627
```
2728

28-
2929
## Usage
30+
3031
```
3132
Text to speech
3233

src/common.ts

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { HumeClient } from "hume";
2-
import { join } from "path";
3-
import { homedir } from "os";
4-
import { mkdir } from "fs/promises";
5-
import { readConfig, type ConfigData } from "./config";
6-
import * as clack from "@clack/prompts";
7-
import createDebug from "debug";
1+
import { HumeClient } from 'hume';
2+
import { join } from 'path';
3+
import { homedir } from 'os';
4+
import { mkdir } from 'fs/promises';
5+
import { readConfig, type ConfigData } from './config';
6+
import * as clack from '@clack/prompts';
7+
import createDebug from 'debug';
88

9-
export const debug = createDebug("hume-cli");
10-
const HUME_DIR = join(homedir(), ".hume");
9+
export const debug = createDebug('hume-cli');
10+
const HUME_DIR = join(homedir(), '.hume');
1111

1212
export const ensureHumeDir = async (): Promise<string> => {
1313
await mkdir(HUME_DIR, { recursive: true });
1414
return HUME_DIR;
1515
};
1616

17-
export type ReporterMode = "json" | "pretty";
17+
export type ReporterMode = 'json' | 'pretty';
1818

1919
export interface CommonOpts {
2020
json?: boolean;
@@ -35,22 +35,19 @@ export class ApiKeyNotSetError extends Error {
3535
constructor() {
3636
super();
3737
this.message =
38-
"No API key provided. You may run `hume login`, set the HUME_API_KEY environment variable, or pass the --api-key flag.";
38+
'No API key provided. You may run `hume login`, set the HUME_API_KEY environment variable, or pass the --api-key flag.';
3939
}
4040
}
4141

4242
// Removed log function - moved to test files where needed
4343

44-
export const redactFieldsNamedAudio = (k: string, v: unknown) =>
45-
k === "audio" ? "<audio>" : v;
44+
export const redactFieldsNamedAudio = (k: string, v: unknown) => (k === 'audio' ? '<audio>' : v);
4645

4746
/** A "reporter" reports the results of operations, i.e. the audience is the CLI user.*/
48-
export const makeReporter = (opts: {
49-
mode: "json" | "pretty";
50-
}): Reporter => {
47+
export const makeReporter = (opts: { mode: 'json' | 'pretty' }): Reporter => {
5148
const spin = clack.spinner();
5249

53-
if (opts.mode === "json") {
50+
if (opts.mode === 'json') {
5451
const printJson = (data: unknown) =>
5552
console.log(JSON.stringify(data, redactFieldsNamedAudio, 2));
5653
return {
@@ -82,7 +79,7 @@ export const makeReporter = (opts: {
8279
};
8380

8481
export const getSettings = async (
85-
opts: CommonOpts,
82+
opts: CommonOpts
8683
): Promise<{
8784
env: typeof process.env;
8885
globalConfig: ConfigData;
@@ -91,30 +88,25 @@ export const getSettings = async (
9188
hume: HumeClient | null;
9289
}> => {
9390
const env = process.env;
94-
const globalConfig = (await readConfig("global")) ?? {};
95-
const session = (await readConfig("session")) ?? {};
91+
const globalConfig = (await readConfig('global')) ?? {};
92+
const session = (await readConfig('session')) ?? {};
9693

9794
// Enable debug if requested
9895
if (opts.debug) {
9996
debug.enabled = true;
10097
}
10198

10299
// Determine reporter mode with priority: opts > session > globalConfig
103-
let reporterMode: ReporterMode = "pretty";
100+
let reporterMode: ReporterMode = 'pretty';
104101
if (opts.json || session.json || globalConfig.json) {
105-
reporterMode = "json";
102+
reporterMode = 'json';
106103
} else if (opts.pretty || session.pretty) {
107-
reporterMode = "pretty";
104+
reporterMode = 'pretty';
108105
}
109-
debug("Reporter mode: %s", reporterMode);
106+
debug('Reporter mode: %s', reporterMode);
110107
const reporter = makeReporter({ mode: reporterMode });
111-
const apiKey =
112-
globalConfig.apiKey ?? session.apiKey ?? env.HUME_API_KEY ?? opts.apiKey;
113-
const baseUrl =
114-
opts.baseUrl ??
115-
env.HUME_BASE_URL ??
116-
session.baseUrl ??
117-
globalConfig.baseUrl;
108+
const apiKey = globalConfig.apiKey ?? session.apiKey ?? env.HUME_API_KEY ?? opts.apiKey;
109+
const baseUrl = opts.baseUrl ?? env.HUME_BASE_URL ?? session.baseUrl ?? globalConfig.baseUrl;
118110
const hume = apiKey ? getHumeClient({ apiKey, baseUrl }) : null;
119111
return {
120112
hume,
@@ -126,10 +118,10 @@ export const getSettings = async (
126118
};
127119

128120
export const getHumeClient = (opts: { apiKey: string; baseUrl?: string }) => {
129-
const environment = opts.baseUrl || "https://test-api.hume.ai";
130-
debug("Creating HumeClient with environment: %s", environment)
121+
const environment = opts.baseUrl || 'https://test-api.hume.ai';
122+
debug('Creating HumeClient with environment: %s', environment);
131123
return new HumeClient({
132124
apiKey: opts.apiKey,
133-
environment: opts.baseUrl ?? "https://api.hume.ai",
125+
environment: opts.baseUrl ?? 'https://api.hume.ai',
134126
});
135127
};

src/config.test.ts

Lines changed: 39 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { expect, test, mock, describe, beforeEach, type Mock } from "bun:test";
1+
import { expect, test, mock, describe, beforeEach, type Mock } from 'bun:test';
22
import {
33
showGlobalConfig,
44
showSession,
@@ -7,34 +7,30 @@ import {
77
endSession,
88
resetGlobalConfig,
99
type ConfigData,
10-
} from "./config";
11-
import * as common from "./common";
10+
} from './config';
11+
import * as common from './common';
1212

13-
describe("Config management", () => {
13+
describe('Config management', () => {
1414
const mockConfig: ConfigData = {
1515
tts: {
16-
voiceName: "test_voice",
17-
voiceId: "voice123",
18-
outputDir: "/test/output",
19-
play: "all",
20-
format: "wav",
16+
voiceName: 'test_voice',
17+
voiceId: 'voice123',
18+
outputDir: '/test/output',
19+
play: 'all',
20+
format: 'wav',
2121
},
2222
json: true,
23-
apiKey: "test-api-key",
23+
apiKey: 'test-api-key',
2424
};
2525

2626
const mockSettings = {
2727
globalConfig: { ...mockConfig },
2828
session: { ...mockConfig },
2929
reporter: {
30-
json: mock((_: unknown) => {}) as unknown as Mock<
31-
common.Reporter["json"]
32-
>,
33-
info: mock((_: unknown) => {}) as unknown as Mock<
34-
common.Reporter["info"]
35-
>,
30+
json: mock((_: unknown) => {}) as unknown as Mock<common.Reporter['json']>,
31+
info: mock((_: unknown) => {}) as unknown as Mock<common.Reporter['info']>,
3632
withSpinner: mock((msg, callback) => callback()) as unknown as Mock<
37-
common.Reporter["withSpinner"]
33+
common.Reporter['withSpinner']
3834
>,
3935
},
4036
};
@@ -46,83 +42,73 @@ describe("Config management", () => {
4642
mockSettings.reporter.withSpinner.mockReset();
4743

4844
// Mock getSettings and makeReporter
49-
mock.module("./common", () => ({
45+
mock.module('./common', () => ({
5046
...common,
5147
getSettings: () => Promise.resolve(mockSettings),
5248
makeReporter: () => mockSettings.reporter,
5349
}));
5450
});
5551

56-
describe("show commands", () => {
57-
test("showGlobalConfig displays global config", async () => {
52+
describe('show commands', () => {
53+
test('showGlobalConfig displays global config', async () => {
5854
await showGlobalConfig();
5955
expect(mockSettings.reporter.json).toHaveBeenCalledWith(mockConfig);
6056
});
6157

62-
test("showSession displays session config", async () => {
58+
test('showSession displays session config', async () => {
6359
await showSession();
6460
expect(mockSettings.reporter.json).toHaveBeenCalledWith(mockConfig);
6561
});
6662
});
6763

68-
describe("set commands", () => {
64+
describe('set commands', () => {
6965
const mockWriteFile = mock(() => Promise.resolve());
70-
mock.module("node:fs/promises", () => ({
66+
mock.module('node:fs/promises', () => ({
7167
writeFile: mockWriteFile,
7268
readFile: mock(() => Promise.resolve(JSON.stringify(mockConfig))),
7369
}));
7470

75-
test("setGlobalConfig updates global config", async () => {
71+
test('setGlobalConfig updates global config', async () => {
7672
await setGlobalConfig({
77-
name: "tts.voiceName",
78-
value: "new_voice",
73+
name: 'tts.voiceName',
74+
value: 'new_voice',
7975
});
8076

81-
expect(mockSettings.reporter.info.mock.calls).toEqual([
82-
["global config updated"],
83-
]);
84-
expect(mockSettings.reporter.json.mock.calls).toEqual([
85-
[{ "tts.voiceName": "new_voice" }],
86-
]);
77+
expect(mockSettings.reporter.info.mock.calls).toEqual([['global config updated']]);
78+
expect(mockSettings.reporter.json.mock.calls).toEqual([[{ 'tts.voiceName': 'new_voice' }]]);
8779
});
8880

89-
test("setSessionConfig updates session config", async () => {
81+
test('setSessionConfig updates session config', async () => {
9082
await setSessionConfig({
91-
name: "tts.format",
92-
value: "mp3",
83+
name: 'tts.format',
84+
value: 'mp3',
9385
});
9486

95-
expect(mockSettings.reporter.info).toHaveBeenCalledWith(
96-
"session config updated",
97-
);
87+
expect(mockSettings.reporter.info).toHaveBeenCalledWith('session config updated');
9888
expect(mockSettings.reporter.json).toHaveBeenCalledWith({
99-
"tts.format": "mp3",
89+
'tts.format': 'mp3',
10090
});
10191
});
10292

103-
test("setConfig validates input values", async () => {
93+
test('setConfig validates input values', async () => {
10494
await expect(
10595
setGlobalConfig({
106-
name: "tts.play",
107-
value: "invalid",
108-
}),
109-
).rejects.toThrow("Invalid value for tts.play");
96+
name: 'tts.play',
97+
value: 'invalid',
98+
})
99+
).rejects.toThrow('Invalid value for tts.play');
110100
});
111101
});
112102

113-
describe("clear commands", () => {
114-
test("endSession clears session config", async () => {
103+
describe('clear commands', () => {
104+
test('endSession clears session config', async () => {
115105
await endSession();
116-
expect(mockSettings.reporter.info).toHaveBeenCalledWith(
117-
"session config cleared",
118-
);
106+
expect(mockSettings.reporter.info).toHaveBeenCalledWith('session config cleared');
119107
});
120108

121-
test("resetGlobalConfig clears global config", async () => {
109+
test('resetGlobalConfig clears global config', async () => {
122110
await resetGlobalConfig();
123-
expect(mockSettings.reporter.info).toHaveBeenCalledWith(
124-
"global config cleared",
125-
);
111+
expect(mockSettings.reporter.info).toHaveBeenCalledWith('global config cleared');
126112
});
127113
});
128114
});

0 commit comments

Comments
 (0)