Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@absmartly/cli",
"version": "1.6.0",
"version": "1.7.0",
"description": "ABSmartly CLI - A/B Testing and Feature Flags command-line tool for AI agents and humans",
"type": "module",
"main": "./dist/index.js",
Expand Down
6 changes: 4 additions & 2 deletions src/commands/actiondialogfields/actiondialogfields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('actiondialogfields command', () => {
]);

expect(mockClient.createExperimentActionDialogField).toHaveBeenCalledWith({ name: 'Reason' });
expect(printFormatted).toHaveBeenCalled();
expect(consoleSpy).toHaveBeenCalledWith(expect.stringContaining('Action dialog field created'));
});

it('should update an action dialog field', async () => {
Expand All @@ -88,6 +88,8 @@ describe('actiondialogfields command', () => {
expect(mockClient.updateExperimentActionDialogField).toHaveBeenCalledWith(1, {
required: true,
});
expect(printFormatted).toHaveBeenCalled();
expect(consoleSpy).toHaveBeenCalledWith(
expect.stringContaining('Action dialog field 1 updated')
);
});
});
17 changes: 12 additions & 5 deletions src/commands/actiondialogfields/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command } from 'commander';
import chalk from 'chalk';
import {
getAPIClientFromOptions,
getGlobalOptions,
printFormatted,
printResult,
withErrorHandling,
} from '../../lib/utils/api-helper.js';
import { validateJSON } from '../../lib/utils/validators.js';
Expand Down Expand Up @@ -61,8 +61,12 @@ const createCommand = new Command('create')
const result = await coreCreateActionDialogField(client, {
config: config as Record<string, unknown>,
});
console.log(chalk.green(`✓ Action dialog field created`));
printFormatted(result.data, globalOptions);
const data = result.data as { id?: unknown } | undefined;
printResult(globalOptions, {
message: `✓ Action dialog field created`,
id: data?.id,
raw: result.data,
});
})
);

Expand All @@ -82,8 +86,11 @@ const updateCommand = new Command('update')
id,
config: config as Record<string, unknown>,
});
console.log(chalk.green(`✓ Action dialog field ${id} updated`));
printFormatted(result.data, globalOptions);
printResult(globalOptions, {
message: `✓ Action dialog field ${id} updated`,
id,
raw: result.data,
});
})
);

Expand Down
22 changes: 16 additions & 6 deletions src/commands/apikeys/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getAPIClientFromOptions,
getGlobalOptions,
printFormatted,
printResult,
withErrorHandling,
} from '../../lib/utils/api-helper.js';
import { parseApiKeyId } from '../../lib/utils/validators.js';
Expand Down Expand Up @@ -55,10 +56,19 @@ const createCommand = new Command('create')
description: options.description,
permissions: options.permissions,
});
console.log(chalk.green(`✓ API key created with ID: ${result.data.id}`));
if (result.data.key) {
console.log(` Key: ${result.data.key}`);
console.log(chalk.yellow(' Save this key now — it cannot be retrieved later.'));
const format = globalOptions.output ?? 'table';
if (format === 'table' || format === 'rendered') {
console.log(chalk.green(`✓ API key created with ID: ${result.data.id}`));
if (result.data.key) {
console.log(` Key: ${result.data.key}`);
console.log(chalk.yellow(' Save this key now — it cannot be retrieved later.'));
}
} else {
printResult(globalOptions, {
message: `✓ API key created with ID: ${result.data.id}`,
id: result.data.id,
raw: result.data,
});
}
})
);
Expand All @@ -77,7 +87,7 @@ const updateCommand = new Command('update')
name: options.name,
description: options.description,
});
console.log(chalk.green(`✓ API key ${id} updated`));
printResult(globalOptions, { message: `✓ API key ${id} updated`, id });
})
);

Expand All @@ -89,7 +99,7 @@ const deleteCommand = new Command('delete')
const globalOptions = getGlobalOptions(deleteCommand);
const client = await getAPIClientFromOptions(globalOptions);
await deleteApiKey(client, { id });
console.log(chalk.green(`✓ API key ${id} deleted`));
printResult(globalOptions, { message: `✓ API key ${id} deleted`, id });
})
);

Expand Down
15 changes: 9 additions & 6 deletions src/commands/apps/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command } from 'commander';
import chalk from 'chalk';
import {
getAPIClientFromOptions,
getGlobalOptions,
printFormatted,
printResult,
withErrorHandling,
} from '../../lib/utils/api-helper.js';
import { parseApplicationId } from '../../lib/utils/validators.js';
Expand Down Expand Up @@ -67,9 +67,12 @@ const createCommand = new Command('create')
const globalOptions = getGlobalOptions(createCommand);
const client = await getAPIClientFromOptions(globalOptions);
const result = await createApp(client, { name: options.name });
console.log(
chalk.green(`✓ Application created with ID: ${(result.data as Record<string, unknown>).id}`)
);
const newId = (result.data as Record<string, unknown>).id;
printResult(globalOptions, {
message: `✓ Application created with ID: ${newId}`,
id: newId,
raw: result.data,
});
})
);

Expand All @@ -82,7 +85,7 @@ const updateCommand = new Command('update')
const globalOptions = getGlobalOptions(updateCommand);
const client = await getAPIClientFromOptions(globalOptions);
await updateApp(client, { id, name: options.name });
console.log(chalk.green(`✓ Application ${id} updated`));
printResult(globalOptions, { message: `✓ Application ${id} updated`, id });
})
);

Expand All @@ -96,7 +99,7 @@ const archiveCommand = new Command('archive')
const client = await getAPIClientFromOptions(globalOptions);
await archiveApp(client, { id, unarchive: options.unarchive });
const action = options.unarchive ? 'unarchived' : 'archived';
console.log(chalk.green(`✓ Application ${id} ${action}`));
printResult(globalOptions, { message: `✓ Application ${id} ${action}`, id });
})
);

Expand Down
15 changes: 9 additions & 6 deletions src/commands/assetroles/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command } from 'commander';
import chalk from 'chalk';
import {
getAPIClientFromOptions,
getGlobalOptions,
printFormatted,
printResult,
withErrorHandling,
} from '../../lib/utils/api-helper.js';
import { parseAssetRoleId } from '../../lib/utils/validators.js';
Expand Down Expand Up @@ -49,9 +49,12 @@ const createCommand = new Command('create')
const globalOptions = getGlobalOptions(createCommand);
const client = await getAPIClientFromOptions(globalOptions);
const result = await createAssetRole(client, { name: options.name });
console.log(
chalk.green(`✓ Asset role created with ID: ${(result.data as Record<string, unknown>).id}`)
);
const newId = (result.data as Record<string, unknown>).id;
printResult(globalOptions, {
message: `✓ Asset role created with ID: ${newId}`,
id: newId,
raw: result.data,
});
})
);

Expand All @@ -64,7 +67,7 @@ const updateCommand = new Command('update')
const globalOptions = getGlobalOptions(updateCommand);
const client = await getAPIClientFromOptions(globalOptions);
await updateAssetRole(client, { id, name: options.name });
console.log(chalk.green(`✓ Asset role ${id} updated`));
printResult(globalOptions, { message: `✓ Asset role ${id} updated`, id });
})
);

Expand All @@ -76,7 +79,7 @@ const deleteCommand = new Command('delete')
const globalOptions = getGlobalOptions(deleteCommand);
const client = await getAPIClientFromOptions(globalOptions);
await deleteAssetRole(client, { id });
console.log(chalk.green(`✓ Asset role ${id} deleted`));
printResult(globalOptions, { message: `✓ Asset role ${id} deleted`, id });
})
);

Expand Down
19 changes: 13 additions & 6 deletions src/commands/cors/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command } from 'commander';
import chalk from 'chalk';
import {
getAPIClientFromOptions,
getGlobalOptions,
printFormatted,
printResult,
withErrorHandling,
} from '../../lib/utils/api-helper.js';
import { parseCorsOriginId } from '../../lib/utils/validators.js';
Expand Down Expand Up @@ -47,8 +47,12 @@ const createCommand = new Command('create')
const globalOptions = getGlobalOptions(createCommand);
const client = await getAPIClientFromOptions(globalOptions);
const result = await createCorsOrigin(client, { origin: options.origin });
console.log(chalk.green(`✓ CORS origin created`));
printFormatted(result.data, globalOptions);
const data = result.data as { id?: unknown } | undefined;
printResult(globalOptions, {
message: `✓ CORS origin created`,
id: data?.id,
raw: result.data,
});
})
);

Expand All @@ -61,8 +65,11 @@ const updateCommand = new Command('update')
const globalOptions = getGlobalOptions(updateCommand);
const client = await getAPIClientFromOptions(globalOptions);
const result = await updateCorsOrigin(client, { id, origin: options.origin });
console.log(chalk.green(`✓ CORS origin ${id} updated`));
printFormatted(result.data, globalOptions);
printResult(globalOptions, {
message: `✓ CORS origin ${id} updated`,
id,
raw: result.data,
});
})
);

Expand All @@ -74,7 +81,7 @@ const deleteCommand = new Command('delete')
const globalOptions = getGlobalOptions(deleteCommand);
const client = await getAPIClientFromOptions(globalOptions);
await deleteCorsOrigin(client, { id });
console.log(chalk.green(`✓ CORS origin ${id} deleted`));
printResult(globalOptions, { message: `✓ CORS origin ${id} deleted`, id });
})
);

Expand Down
28 changes: 16 additions & 12 deletions src/commands/customfields/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command } from 'commander';
import chalk from 'chalk';
import {
getAPIClientFromOptions,
getGlobalOptions,
printFormatted,
printResult,
withErrorHandling,
} from '../../lib/utils/api-helper.js';
import { parseCustomSectionFieldId } from '../../lib/utils/validators.js';
Expand Down Expand Up @@ -67,12 +67,12 @@ const createCommand = new Command('create')
type: options.type,
defaultValue: options.defaultValue,
});
console.log(
chalk.green(
`✓ Custom section field created with ID: ${(result.data as Record<string, unknown>).id}`
)
);
printFormatted(result.data, globalOptions);
const newId = (result.data as Record<string, unknown>).id;
printResult(globalOptions, {
message: `✓ Custom section field created with ID: ${newId}`,
id: newId,
raw: result.data,
});
})
);

Expand All @@ -99,8 +99,11 @@ const updateCommand = new Command('update')
type: options.type,
defaultValue: options.defaultValue,
});
console.log(chalk.green(`✓ Custom section field ${id} updated`));
printFormatted(result.data, globalOptions);
printResult(globalOptions, {
message: `✓ Custom section field ${id} updated`,
id,
raw: result.data,
});
})
);

Expand All @@ -113,9 +116,10 @@ const archiveCommand = new Command('archive')
const globalOptions = getGlobalOptions(archiveCommand);
const client = await getAPIClientFromOptions(globalOptions);
await archiveCustomField(client, { id, unarchive: !!options.unarchive });
console.log(
chalk.green(`✓ Custom section field ${id} ${options.unarchive ? 'unarchived' : 'archived'}`)
);
printResult(globalOptions, {
message: `✓ Custom section field ${id} ${options.unarchive ? 'unarchived' : 'archived'}`,
id,
});
})
);

Expand Down
21 changes: 14 additions & 7 deletions src/commands/customsections/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Command } from 'commander';
import chalk from 'chalk';
import {
getAPIClientFromOptions,
getGlobalOptions,
printFormatted,
printResult,
withErrorHandling,
} from '../../lib/utils/api-helper.js';
import { parseCustomSectionId } from '../../lib/utils/validators.js';
Expand Down Expand Up @@ -38,8 +38,12 @@ const createCommand = new Command('create')
const globalOptions = getGlobalOptions(createCommand);
const client = await getAPIClientFromOptions(globalOptions);
const result = await createCustomSection(client, { name: options.name, type: options.type });
console.log(chalk.green(`✓ Custom section created`));
printFormatted(result.data, globalOptions);
const data = result.data as { id?: unknown } | undefined;
printResult(globalOptions, {
message: `✓ Custom section created`,
id: data?.id,
raw: result.data,
});
})
);

Expand All @@ -52,8 +56,11 @@ const updateCommand = new Command('update')
const globalOptions = getGlobalOptions(updateCommand);
const client = await getAPIClientFromOptions(globalOptions);
const result = await updateCustomSection(client, { id, name: options.name });
console.log(chalk.green(`✓ Custom section ${id} updated`));
printFormatted(result.data, globalOptions);
printResult(globalOptions, {
message: `✓ Custom section ${id} updated`,
id,
raw: result.data,
});
})
);

Expand All @@ -67,7 +74,7 @@ const archiveCommand = new Command('archive')
const client = await getAPIClientFromOptions(globalOptions);
await archiveCustomSection(client, { id, unarchive: !!options.unarchive });
const action = options.unarchive ? 'unarchived' : 'archived';
console.log(chalk.green(`✓ Custom section ${id} ${action}`));
printResult(globalOptions, { message: `✓ Custom section ${id} ${action}`, id });
})
);

Expand All @@ -90,7 +97,7 @@ const reorderCommand = new Command('reorder')
return { id, order_index };
});
await reorderCustomSections(client, { sections });
console.log(chalk.green(`✓ Custom sections reordered`));
printResult(globalOptions, { message: `✓ Custom sections reordered` });
})
);

Expand Down
Loading
Loading