Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): Replace arguments with options #615

Merged
merged 2 commits into from
Jan 9, 2025
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
6 changes: 6 additions & 0 deletions apps/cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions apps/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/cli/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
21 changes: 15 additions & 6 deletions apps/cli/src/commands/secret/list.secret.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -20,21 +21,29 @@ export default class ListSecret extends BaseCommand {
{
name: '<Project Slug>',
description: 'Slug of the project whose secrets you want.'
},
}
]
}

getOptions(): CommandOption[] {
return [
{
name: '<Environment Slug>',
short: '-e',
long: '--environment <string>',
description: 'Slug of the environment whose secrets you want.'
}
]
}

async action({ args }: CommandActionData): Promise<void> {
const [projectSlug, environmentSlug] = args
async action({ args, options }: CommandActionData): Promise<void> {
const [projectSlug] = args
const { environment } = options

const { data, error, success } =
await ControllerInstance.getInstance().secretController.getAllSecretsOfEnvironment(
{
projectSlug,
environmentSlug
environmentSlug: environment
},
this.headers
)
Expand Down
20 changes: 14 additions & 6 deletions apps/cli/src/commands/secret/revisions.secret.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -20,22 +21,29 @@ export default class FetchSecretRevisions extends BaseCommand {
{
name: '<Secret Slug>',
description: 'Slug of the secret whose revisions you want.'
},
}
]
}

getOptions(): CommandOption[] {
return [
{
name: '<Environment Slug>',
short: '-e',
long: '--environment <string>',
description: 'Environment slug of the secret whose revisions you want.'
}
]
}

async action({ args }: CommandActionData): Promise<void> {
const [secretSlug, environmentSlug] = args
async action({ args, options }: CommandActionData): Promise<void> {
const [secretSlug] = args
const { environment } = options

const { data, error, success } =
await ControllerInstance.getInstance().secretController.getRevisionsOfSecret(
{
secretSlug,
environmentSlug
environmentSlug: environment
},
this.headers
)
Expand Down
13 changes: 7 additions & 6 deletions apps/cli/src/commands/secret/rollback.secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class RollbackSecret extends BaseCommand {
},
{
short: '-e',
long: '--environmentSlug <string>',
long: '--environment <string>',
description:
'Slug of the environment of the secret to which you want to rollback'
}
Expand All @@ -43,11 +43,12 @@ export default class RollbackSecret extends BaseCommand {

async action({ args, options }: CommandActionData): Promise<void> {
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
},
Expand All @@ -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)
}
}
Expand Down
21 changes: 17 additions & 4 deletions apps/cli/src/commands/variable/revisions.variable.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -29,14 +30,26 @@ export default class FetchVariableRevisions extends BaseCommand {
]
}

async action({ args }: CommandActionData): Promise<void> {
const [variableSlug, environmentSlug] = args
getOptions(): CommandOption[] {
return [
{
short: '-e',
long: '--environment <string>',
description:
'Environment slug of the variable whose revisions you want.'
}
]
}

async action({ args, options }: CommandActionData): Promise<void> {
const [variableSlug] = args
const { environment } = options

const { data, error, success } =
await ControllerInstance.getInstance().variableController.getRevisionsOfVariable(
{
variableSlug,
environmentSlug
environmentSlug: environment
},
this.headers
)
Expand Down
12 changes: 6 additions & 6 deletions apps/cli/src/commands/variable/rollback.variable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default class RollbackVariable extends BaseCommand {
},
{
short: '-e',
long: '--environmentSlug <string>',
long: '--environment <string>',
description:
'Slug of the environment of the variable to which you want to rollback'
}
Expand All @@ -43,11 +43,11 @@ export default class RollbackVariable extends BaseCommand {

async action({ args, options }: CommandActionData): Promise<void> {
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
},
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -20,9 +21,15 @@ export default class CancelInvitationCommand extends BaseCommand {
{
name: '<Workspace Slug>',
description: 'Slug of the workspace which you want to fetch.'
},
}
]
}

getOptions(): CommandOption[] {
return [
{
name: '<Invitee Email>',
short: '-e',
long: '--email <string>',
description: 'Email of the user that was invited.'
}
]
Expand All @@ -32,22 +39,23 @@ export default class CancelInvitationCommand extends BaseCommand {
return true
}

async action({ args }: CommandActionData): Promise<void> {
const [workspaceSlug, userEmail] = args
async action({ args, options }: CommandActionData): Promise<void> {
const [workspaceSlug] = args
const { email } = options

const { error, success } =
await ControllerInstance.getInstance().workspaceMembershipController.cancelInvitation(
{
workspaceSlug,
userEmail
userEmail: email
},
this.headers
)

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}`)
}
Expand Down
32 changes: 20 additions & 12 deletions apps/cli/src/commands/workspace/membership/invite.membership.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -20,14 +21,21 @@ export default class InviteUserCommand extends BaseCommand {
{
name: '<Workspace Slug>',
description: 'Slug of the workspace which you want to fetch.'
},
}
]
}

getOptions(): CommandOption[] {
return [
{
name: '<Invitee Email>',
short: '-e',
long: '--email <string>',
description: 'Email of the user to invite.'
},
{
name: '<Role Slugs...>',
description: 'Space-separated list of role slugs to assign to the user.'
short: '-r',
long: '--roles <string>',
description: 'Comma-separated list of role slugs to assign to the user.'
}
]
}
Expand All @@ -36,8 +44,9 @@ export default class InviteUserCommand extends BaseCommand {
return true
}

async action({ args }: CommandActionData): Promise<void> {
const [workspaceSlug, email, roleSlugs] = args
async action({ args, options }: CommandActionData): Promise<void> {
const [workspaceSlug] = args
const { email, roles } = options

const { error, success } =
await ControllerInstance.getInstance().workspaceMembershipController.inviteUsers(
Expand All @@ -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}`)
}
Expand Down
Loading
Loading