Skip to content

Commit 02ec84d

Browse files
Base profile commands
1 parent e86c3a3 commit 02ec84d

File tree

4 files changed

+134
-0
lines changed

4 files changed

+134
-0
lines changed

src/commands/profiles/delete.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {Args, Command} from '@oclif/core'
2+
3+
import {deleteProfile} from '../../lib/profile/storage.js'
4+
5+
export default class ProfilesDelete extends Command {
6+
static args = {
7+
name: Args.string({
8+
description: 'Profile name to delete',
9+
required: true,
10+
}),
11+
}
12+
static description = 'Delete a profile'
13+
static examples = ['<%= config.bin %> <%= command.id %> my-profile']
14+
15+
async run(): Promise<void> {
16+
const {args} = await this.parse(ProfilesDelete)
17+
18+
try {
19+
deleteProfile(args.name)
20+
this.log(`Profile "${args.name}" deleted successfully`)
21+
} catch (error) {
22+
if (error instanceof Error) {
23+
this.error(error.message)
24+
}
25+
26+
throw error
27+
}
28+
}
29+
}

src/commands/profiles/list.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import {Command} from '@oclif/core'
2+
3+
import {listProfiles} from '../../lib/profile/storage.js'
4+
5+
export default class ProfilesList extends Command {
6+
static description = 'List all profiles'
7+
static examples = ['<%= config.bin %> <%= command.id %>']
8+
9+
async run(): Promise<void> {
10+
const profiles = listProfiles()
11+
12+
if (profiles.length === 0) {
13+
this.log('No profiles found')
14+
return
15+
}
16+
17+
for (const profile of profiles) {
18+
this.log(profile)
19+
}
20+
}
21+
}

src/commands/profiles/set.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
import {Args, Command, Flags} from '@oclif/core'
2+
3+
import type {OpenAIProfileConfig, WatsonxProfileConfig} from '../../lib/profile/types.js'
4+
5+
import {saveProfile} from '../../lib/profile/storage.js'
6+
7+
export default class ProfilesSet extends Command {
8+
static args = {
9+
name: Args.string({
10+
description: 'Profile name',
11+
required: true,
12+
}),
13+
}
14+
static description = 'Create or update a profile'
15+
static examples = [
16+
'<%= config.bin %> <%= command.id %> my-openai-profile --provider openai --api-key sk-... --model gpt-4o',
17+
'<%= config.bin %> <%= command.id %> my-watsonx-profile --provider watsonx --api-key ... --project-id ... --service-url https://... --model ibm/granite-3-8b-instruct',
18+
]
19+
static flags = {
20+
'api-key': Flags.string({
21+
description: 'API key for the provider',
22+
required: true,
23+
}),
24+
model: Flags.string({
25+
description: 'Model to use',
26+
required: true,
27+
}),
28+
'project-id': Flags.string({
29+
description: 'Watsonx project ID (required for watsonx)',
30+
required: false,
31+
}),
32+
provider: Flags.string({
33+
description: 'LLM provider',
34+
options: ['openai', 'watsonx'],
35+
required: true,
36+
}),
37+
'service-url': Flags.string({
38+
description: 'Watsonx service URL (required for watsonx)',
39+
required: false,
40+
}),
41+
}
42+
43+
async run(): Promise<void> {
44+
const {args, flags} = await this.parse(ProfilesSet)
45+
46+
if (flags.provider === 'openai') {
47+
const config: OpenAIProfileConfig = {
48+
apiKey: flags['api-key'],
49+
model: flags.model,
50+
}
51+
52+
saveProfile({
53+
config,
54+
name: args.name,
55+
provider: 'openai',
56+
})
57+
58+
this.log(`Profile "${args.name}" saved successfully`)
59+
} else if (flags.provider === 'watsonx') {
60+
if (!flags['project-id']) {
61+
this.error('--project-id is required for watsonx provider')
62+
}
63+
64+
if (!flags['service-url']) {
65+
this.error('--service-url is required for watsonx provider')
66+
}
67+
68+
const config: WatsonxProfileConfig = {
69+
apiKey: flags['api-key'],
70+
model: flags.model,
71+
projectId: flags['project-id'],
72+
serviceUrl: flags['service-url'],
73+
}
74+
75+
saveProfile({
76+
config,
77+
name: args.name,
78+
provider: 'watsonx',
79+
})
80+
81+
this.log(`Profile "${args.name}" saved successfully`)
82+
}
83+
}
84+
}
File renamed without changes.

0 commit comments

Comments
 (0)