diff --git a/apps/cli/CHANGELOG.md b/apps/cli/CHANGELOG.md index 0ea284c1..bd935a4d 100644 --- a/apps/cli/CHANGELOG.md +++ b/apps/cli/CHANGELOG.md @@ -29,3 +29,9 @@ ### Minor Changes - Fixed binary path in package.json + +## 2.1.0 + +### Major Changes + +- Modified a lot of commands to use more options rather than arguments diff --git a/apps/cli/package-lock.json b/apps/cli/package-lock.json index ff18016b..2fa6fbe9 100644 --- a/apps/cli/package-lock.json +++ b/apps/cli/package-lock.json @@ -1,12 +1,12 @@ { "name": "@keyshade/cli", - "version": "2.0.7", + "version": "2.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@keyshade/cli", - "version": "2.0.7", + "version": "2.1.0", "license": "MPL-2.0", "dependencies": { "@clack/core": "^0.3.4", diff --git a/apps/cli/package.json b/apps/cli/package.json index 71a67463..fa2df1a4 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -1,6 +1,6 @@ { "name": "@keyshade/cli", - "version": "2.0.7", + "version": "2.1.0", "description": "CLI for keyshade", "main": "dist/index.cjs", "module": "dist/index.esm.js", diff --git a/apps/cli/src/commands/secret/list.secret.ts b/apps/cli/src/commands/secret/list.secret.ts index 382951ff..5364fcea 100644 --- a/apps/cli/src/commands/secret/list.secret.ts +++ b/apps/cli/src/commands/secret/list.secret.ts @@ -1,6 +1,7 @@ import type { CommandActionData, - CommandArgument + CommandArgument, + CommandOption } from '@/types/command/command.types' import BaseCommand from '@/commands/base.command' import ControllerInstance from '@/util/controller-instance' @@ -20,21 +21,29 @@ export default class ListSecret extends BaseCommand { { name: '', description: 'Slug of the project whose secrets you want.' - }, + } + ] + } + + getOptions(): CommandOption[] { + return [ { - name: '', + short: '-e', + long: '--environment ', description: 'Slug of the environment whose secrets you want.' } ] } - async action({ args }: CommandActionData): Promise { - const [projectSlug, environmentSlug] = args + async action({ args, options }: CommandActionData): Promise { + const [projectSlug] = args + const { environment } = options + const { data, error, success } = await ControllerInstance.getInstance().secretController.getAllSecretsOfEnvironment( { projectSlug, - environmentSlug + environmentSlug: environment }, this.headers ) diff --git a/apps/cli/src/commands/secret/revisions.secret.ts b/apps/cli/src/commands/secret/revisions.secret.ts index 9a031b63..02549788 100644 --- a/apps/cli/src/commands/secret/revisions.secret.ts +++ b/apps/cli/src/commands/secret/revisions.secret.ts @@ -1,6 +1,7 @@ import type { CommandActionData, - CommandArgument + CommandArgument, + CommandOption } from '@/types/command/command.types' import BaseCommand from '@/commands/base.command' import ControllerInstance from '@/util/controller-instance' @@ -20,22 +21,29 @@ export default class FetchSecretRevisions extends BaseCommand { { name: '', description: 'Slug of the secret whose revisions you want.' - }, + } + ] + } + + getOptions(): CommandOption[] { + return [ { - name: '', + short: '-e', + long: '--environment ', description: 'Environment slug of the secret whose revisions you want.' } ] } - async action({ args }: CommandActionData): Promise { - const [secretSlug, environmentSlug] = args + async action({ args, options }: CommandActionData): Promise { + const [secretSlug] = args + const { environment } = options const { data, error, success } = await ControllerInstance.getInstance().secretController.getRevisionsOfSecret( { secretSlug, - environmentSlug + environmentSlug: environment }, this.headers ) diff --git a/apps/cli/src/commands/secret/rollback.secret.ts b/apps/cli/src/commands/secret/rollback.secret.ts index db44d4d1..966b446f 100644 --- a/apps/cli/src/commands/secret/rollback.secret.ts +++ b/apps/cli/src/commands/secret/rollback.secret.ts @@ -34,7 +34,7 @@ export default class RollbackSecret extends BaseCommand { }, { short: '-e', - long: '--environmentSlug ', + long: '--environment ', description: 'Slug of the environment of the secret to which you want to rollback' } @@ -43,11 +43,12 @@ export default class RollbackSecret extends BaseCommand { async action({ args, options }: CommandActionData): Promise { const [secretSlug] = args - const { environmentSlug, version } = await this.parseInput(options) + const { environment, version } = await this.parseInput(options) + const { data, error, success } = await ControllerInstance.getInstance().secretController.rollbackSecret( { - environmentSlug, + environmentSlug: environment, version, secretSlug }, @@ -62,13 +63,13 @@ export default class RollbackSecret extends BaseCommand { } private async parseInput(options: CommandActionData['options']): Promise<{ - environmentSlug: string + environment: string version: number }> { - const { environmentSlug, version } = options + const { environment, version } = options return { - environmentSlug, + environment, version: parseInt(version, 10) } } diff --git a/apps/cli/src/commands/variable/revisions.variable.ts b/apps/cli/src/commands/variable/revisions.variable.ts index 18c9f0d5..8f2f753a 100644 --- a/apps/cli/src/commands/variable/revisions.variable.ts +++ b/apps/cli/src/commands/variable/revisions.variable.ts @@ -1,6 +1,7 @@ import type { CommandActionData, - CommandArgument + CommandArgument, + CommandOption } from '@/types/command/command.types' import BaseCommand from '@/commands/base.command' import ControllerInstance from '@/util/controller-instance' @@ -29,14 +30,26 @@ export default class FetchVariableRevisions extends BaseCommand { ] } - async action({ args }: CommandActionData): Promise { - const [variableSlug, environmentSlug] = args + getOptions(): CommandOption[] { + return [ + { + short: '-e', + long: '--environment ', + description: + 'Environment slug of the variable whose revisions you want.' + } + ] + } + + async action({ args, options }: CommandActionData): Promise { + const [variableSlug] = args + const { environment } = options const { data, error, success } = await ControllerInstance.getInstance().variableController.getRevisionsOfVariable( { variableSlug, - environmentSlug + environmentSlug: environment }, this.headers ) diff --git a/apps/cli/src/commands/variable/rollback.variable.ts b/apps/cli/src/commands/variable/rollback.variable.ts index d480b313..fbf92640 100644 --- a/apps/cli/src/commands/variable/rollback.variable.ts +++ b/apps/cli/src/commands/variable/rollback.variable.ts @@ -34,7 +34,7 @@ export default class RollbackVariable extends BaseCommand { }, { short: '-e', - long: '--environmentSlug ', + long: '--environment ', description: 'Slug of the environment of the variable to which you want to rollback' } @@ -43,11 +43,11 @@ export default class RollbackVariable extends BaseCommand { async action({ args, options }: CommandActionData): Promise { const [variableSlug] = args - const { environmentSlug, version } = await this.parseInput(options) + const { environment, version } = await this.parseInput(options) const { data, error, success } = await ControllerInstance.getInstance().variableController.rollbackVariable( { - environmentSlug, + environmentSlug: environment, version, variableSlug }, @@ -64,13 +64,13 @@ export default class RollbackVariable extends BaseCommand { } private async parseInput(options: CommandActionData['options']): Promise<{ - environmentSlug: string + environment: string version: number }> { - const { environmentSlug, version } = options + const { environment, version } = options return { - environmentSlug, + environment, version: parseInt(version, 10) } } diff --git a/apps/cli/src/commands/workspace/membership/cancel-invitation.membership.ts b/apps/cli/src/commands/workspace/membership/cancel-invitation.membership.ts index a0aa2d95..182cd951 100644 --- a/apps/cli/src/commands/workspace/membership/cancel-invitation.membership.ts +++ b/apps/cli/src/commands/workspace/membership/cancel-invitation.membership.ts @@ -1,7 +1,8 @@ import BaseCommand from '@/commands/base.command' -import { - type CommandActionData, - type CommandArgument +import type { + CommandOption, + CommandActionData, + CommandArgument } from '@/types/command/command.types' import { Logger } from '@/util/logger' import ControllerInstance from '@/util/controller-instance' @@ -20,9 +21,15 @@ export default class CancelInvitationCommand extends BaseCommand { { name: '', description: 'Slug of the workspace which you want to fetch.' - }, + } + ] + } + + getOptions(): CommandOption[] { + return [ { - name: '', + short: '-e', + long: '--email ', description: 'Email of the user that was invited.' } ] @@ -32,14 +39,15 @@ export default class CancelInvitationCommand extends BaseCommand { return true } - async action({ args }: CommandActionData): Promise { - const [workspaceSlug, userEmail] = args + async action({ args, options }: CommandActionData): Promise { + const [workspaceSlug] = args + const { email } = options const { error, success } = await ControllerInstance.getInstance().workspaceMembershipController.cancelInvitation( { workspaceSlug, - userEmail + userEmail: email }, this.headers ) @@ -47,7 +55,7 @@ export default class CancelInvitationCommand extends BaseCommand { if (success) { Logger.info('Cancelled an invitation for workspace successfully!') Logger.info(`Workspace slug: ${workspaceSlug}`) - Logger.info(`Invitee: ${userEmail}`) + Logger.info(`Invitee: ${email}`) } else { Logger.error(`Failed to cancel invitation: ${error.message}`) } diff --git a/apps/cli/src/commands/workspace/membership/invite.membership.ts b/apps/cli/src/commands/workspace/membership/invite.membership.ts index 5b8f4df7..39367f77 100644 --- a/apps/cli/src/commands/workspace/membership/invite.membership.ts +++ b/apps/cli/src/commands/workspace/membership/invite.membership.ts @@ -1,7 +1,8 @@ import BaseCommand from '@/commands/base.command' -import { - type CommandActionData, - type CommandArgument +import type { + CommandOption, + CommandActionData, + CommandArgument } from '@/types/command/command.types' import { Logger } from '@/util/logger' import ControllerInstance from '@/util/controller-instance' @@ -20,14 +21,21 @@ export default class InviteUserCommand extends BaseCommand { { name: '', description: 'Slug of the workspace which you want to fetch.' - }, + } + ] + } + + getOptions(): CommandOption[] { + return [ { - name: '', + short: '-e', + long: '--email ', description: 'Email of the user to invite.' }, { - name: '', - description: 'Space-separated list of role slugs to assign to the user.' + short: '-r', + long: '--roles ', + description: 'Comma-separated list of role slugs to assign to the user.' } ] } @@ -36,8 +44,9 @@ export default class InviteUserCommand extends BaseCommand { return true } - async action({ args }: CommandActionData): Promise { - const [workspaceSlug, email, roleSlugs] = args + async action({ args, options }: CommandActionData): Promise { + const [workspaceSlug] = args + const { email, roles } = options const { error, success } = await ControllerInstance.getInstance().workspaceMembershipController.inviteUsers( @@ -46,18 +55,17 @@ export default class InviteUserCommand extends BaseCommand { members: [ { email, - roleSlugs: roleSlugs.split(',') + roleSlugs: roles.split(',') } ] }, this.headers ) - if (success) { Logger.info('Invited to workspace successfully!') Logger.info(`Workspace slug: ${workspaceSlug}`) Logger.info(`Invitee: ${email}`) - Logger.info(`Roles: ${roleSlugs}`) + Logger.info(`Roles: ${roles}`) } else { Logger.error(`Failed to invite user: ${error.message}`) } diff --git a/apps/cli/src/commands/workspace/membership/remove.membership.ts b/apps/cli/src/commands/workspace/membership/remove.membership.ts index 5a94d1e4..0c99d626 100644 --- a/apps/cli/src/commands/workspace/membership/remove.membership.ts +++ b/apps/cli/src/commands/workspace/membership/remove.membership.ts @@ -1,7 +1,8 @@ import BaseCommand from '@/commands/base.command' -import { - type CommandActionData, - type CommandArgument +import type { + CommandOption, + CommandActionData, + CommandArgument } from '@/types/command/command.types' import ControllerInstance from '@/util/controller-instance' import { Logger } from '@/util/logger' @@ -20,10 +21,16 @@ export default class RemoveUserCommand extends BaseCommand { { name: '', description: 'Slug of the workspace which you want to fetch.' - }, + } + ] + } + + getOptions(): CommandOption[] { + return [ { - name: '', - description: 'Email of the user to remove.' + short: '-e', + long: '--emails ', + description: 'Comma separated list of emails of the users to remove.' } ] } @@ -32,14 +39,15 @@ export default class RemoveUserCommand extends BaseCommand { return true } - async action({ args }: CommandActionData): Promise { - const [workspaceSlug, email] = args + async action({ args, options }: CommandActionData): Promise { + const [workspaceSlug] = args + const { emails } = options const { error, success } = await ControllerInstance.getInstance().workspaceMembershipController.removeUsers( { workspaceSlug, - userEmails: email + userEmails: emails.split(',') }, this.headers ) @@ -47,9 +55,9 @@ export default class RemoveUserCommand extends BaseCommand { if (success) { Logger.info('Removed user from workspace successfully!') Logger.info(`Workspace slug: ${workspaceSlug}`) - Logger.info(`User email: ${email}`) + Logger.info(`Email: ${emails}`) } else { - Logger.error(`Failed to remove user: ${error.message}`) + Logger.error(`Failed to remove users: ${error.message}`) } } } diff --git a/apps/cli/src/commands/workspace/membership/transfer-ownership.membership copy.ts b/apps/cli/src/commands/workspace/membership/transfer-ownership.membership copy.ts index e140c5ff..7815b065 100644 --- a/apps/cli/src/commands/workspace/membership/transfer-ownership.membership copy.ts +++ b/apps/cli/src/commands/workspace/membership/transfer-ownership.membership copy.ts @@ -1,7 +1,8 @@ import BaseCommand from '@/commands/base.command' -import { - type CommandActionData, - type CommandArgument +import type { + CommandOption, + CommandActionData, + CommandArgument } from '@/types/command/command.types' import { Logger } from '@/util/logger' import ControllerInstance from '@/util/controller-instance' @@ -28,25 +29,36 @@ export default class TransferOwnershipCommand extends BaseCommand { ] } + getOptions(): CommandOption[] { + return [ + { + short: '-e', + long: '--email ', + description: 'Email of the user to transfer ownership to.' + } + ] + } + canMakeHttpRequests(): boolean { return true } - async action({ args }: CommandActionData): Promise { - const [workspaceSlug, newOwnerEmail] = args + async action({ args, options }: CommandActionData): Promise { + const [workspaceSlug] = args + const { email } = options const { error, success } = await ControllerInstance.getInstance().workspaceMembershipController.transferOwnership( { workspaceSlug, - userEmail: newOwnerEmail + userEmail: email }, this.headers ) if (success) { Logger.info('Workspace Ownership transferred successfully!') - Logger.info(`New owner email: ${newOwnerEmail}`) + Logger.info(`New owner email: ${email}`) Logger.info(`Workspace slug: ${workspaceSlug}`) } else { Logger.error(`Failed to transfer ownership: ${error.message}`) diff --git a/apps/cli/src/commands/workspace/membership/update-role.membership.ts b/apps/cli/src/commands/workspace/membership/update-role.membership.ts index 9334cd97..9cb70860 100644 --- a/apps/cli/src/commands/workspace/membership/update-role.membership.ts +++ b/apps/cli/src/commands/workspace/membership/update-role.membership.ts @@ -1,7 +1,8 @@ import BaseCommand from '@/commands/base.command' -import { - type CommandActionData, - type CommandArgument +import type { + CommandOption, + CommandActionData, + CommandArgument } from '@/types/command/command.types' import { Logger } from '@/util/logger' import ControllerInstance from '@/util/controller-instance' @@ -32,19 +33,35 @@ export default class UpdateRolesCommand extends BaseCommand { ] } + getOptions(): CommandOption[] { + return [ + { + short: '-e', + long: '--email ', + description: 'Email of the user to update.' + }, + { + short: '-r', + long: '--roles ', + description: 'Comma-separated list of role slugs to assign to the user.' + } + ] + } + canMakeHttpRequests(): boolean { return true } - async action({ args }: CommandActionData): Promise { - const [workspaceSlug, userEmail, roleSlugs] = args + async action({ args, options }: CommandActionData): Promise { + const [workspaceSlug] = args + const { email, roles } = options const { error, success } = await ControllerInstance.getInstance().workspaceMembershipController.updateMemberRoles( { workspaceSlug, - userEmail, - roleSlugs: roleSlugs.split(',') + userEmail: email, + roleSlugs: roles.split(',') }, this.headers ) @@ -52,8 +69,8 @@ export default class UpdateRolesCommand extends BaseCommand { if (success) { Logger.info('Updated the roles of user!') Logger.info(`Workspace slug: ${workspaceSlug}`) - Logger.info(`Member Email: ${userEmail}`) - Logger.info(`New Roles: ${roleSlugs}`) + Logger.info(`Member Email: ${email}`) + Logger.info(`New Roles: ${roles}`) } else { Logger.error(`Failed to update roles: ${error.message}`) } diff --git a/apps/cli/src/commands/workspace/role.workspace.ts b/apps/cli/src/commands/workspace/role.workspace.ts index 37c14bb5..e5e2ae5e 100644 --- a/apps/cli/src/commands/workspace/role.workspace.ts +++ b/apps/cli/src/commands/workspace/role.workspace.ts @@ -1,4 +1,5 @@ import BaseCommand from '../base.command' +import CreateRoleCommand from './role/create.role' import DeleteRoleCommand from './role/delete.role' import GetRoleCommand from './role/get.role' import ListRoleCommand from './role/list.role' @@ -15,6 +16,7 @@ export default class WorkspaceRoleCommand extends BaseCommand { getSubCommands(): BaseCommand[] { return [ + new CreateRoleCommand(), new ListRoleCommand(), new GetRoleCommand(), new DeleteRoleCommand(), diff --git a/apps/cli/src/commands/workspace/role/create.role.ts b/apps/cli/src/commands/workspace/role/create.role.ts index 96b59a05..c1695c3c 100644 --- a/apps/cli/src/commands/workspace/role/create.role.ts +++ b/apps/cli/src/commands/workspace/role/create.role.ts @@ -7,7 +7,7 @@ import { import { Logger } from '@/util/logger' import ControllerInstance from '@/util/controller-instance' -export default class UpdateRoleCommand extends BaseCommand { +export default class CreateRoleCommand extends BaseCommand { getName() { return 'create' } @@ -39,7 +39,7 @@ export default class UpdateRoleCommand extends BaseCommand { }, { short: '-c', - long: '--color-code ', + long: '--color-code ', description: 'Color code of the workspace role.' }, { @@ -49,12 +49,12 @@ export default class UpdateRoleCommand extends BaseCommand { }, { short: '-p', - long: '--project-slugs ', + long: '--projects ', description: 'Project slugs of the workspace role.' }, { short: '-e', - long: '--environment-slugs ', + long: '--environments ', description: 'Environment slugs to be associated for projects. Separate list of environments with colon(:) for each project. And comma(,) to separate each project.' } @@ -68,13 +68,13 @@ export default class UpdateRoleCommand extends BaseCommand { description, colorCode, authorities, - projectSlugs, - environmentSlugs + projects, + environments } = options const authoritiesArray = authorities?.split(',') - const projectSlugsArray = projectSlugs?.split(',') - const environmentSlugsArray = environmentSlugs?.split(',') + const projectSlugsArray = projects?.split(',') + const environmentSlugsArray = environments?.split(',') if ( projectSlugsArray && diff --git a/apps/cli/src/commands/workspace/role/update.role.ts b/apps/cli/src/commands/workspace/role/update.role.ts index e9e917ae..91dc679e 100644 --- a/apps/cli/src/commands/workspace/role/update.role.ts +++ b/apps/cli/src/commands/workspace/role/update.role.ts @@ -49,12 +49,12 @@ export default class UpdateRoleCommand extends BaseCommand { }, { short: '-p', - long: '--project-slugs ', + long: '--projects ', description: 'Project slugs of the workspace role.' }, { short: '-e', - long: '--environment-slugs ', + long: '--environments ', description: 'Environment slugs to be associated for projects. Separate list of environments with colon(:) for each project. And comma(,) to separate each project.' } @@ -68,13 +68,13 @@ export default class UpdateRoleCommand extends BaseCommand { description, colorCode, authorities, - projectSlugs, - environmentSlugs + projects, + environments } = options const authoritiesArray = authorities?.split(',') - const projectSlugsArray = projectSlugs?.split(',') - const environmentSlugsArray = environmentSlugs?.split(',') + const projectSlugsArray = projects?.split(',') + const environmentSlugsArray = environments?.split(',') if (projectSlugsArray?.length !== environmentSlugsArray?.length) { Logger.error('Number of projects and environments should be equal')