Skip to content

Commit

Permalink
feat(cli): Implemented pagination support (keyshade-xyz#453)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nil2000 authored and Kiranchaudhary537 committed Oct 13, 2024
1 parent ad48593 commit 2ec6577
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 147 deletions.
10 changes: 8 additions & 2 deletions apps/cli/src/commands/environment/list.environment.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import BaseCommand from '../base.command'
import { EnvironmentController } from '@keyshade/api-client'
import {
CommandOption,
type CommandActionData,
type CommandArgument
} from 'src/types/command/command.types'
import { Logger } from '@/util/logger'
import { PAGINATION_OPTION } from '@/util/pagination-options'

export class ListEnvironment extends BaseCommand {
getName(): string {
Expand All @@ -24,7 +26,11 @@ export class ListEnvironment extends BaseCommand {
]
}

async action({ args }: CommandActionData): Promise<void> {
getOptions(): CommandOption[] {
return PAGINATION_OPTION
}

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

if (!projectSlug) {
Expand All @@ -44,7 +50,7 @@ export class ListEnvironment extends BaseCommand {
data: environments,
error
} = await environmentController.getAllEnvironmentsOfProject(
{ projectSlug },
{ projectSlug, ...options },
headers
)

Expand Down
12 changes: 10 additions & 2 deletions apps/cli/src/commands/workspace/list.workspace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import BaseCommand from '@/commands/base.command'
import { Logger } from '@/util/logger'
import ControllerInstance from '@/util/controller-instance'
import { CommandActionData, CommandOption } from '@/types/command/command.types'
import { PAGINATION_OPTION } from '@/util/pagination-options'

export default class ListWorkspace extends BaseCommand {
getName(): string {
Expand All @@ -11,12 +13,18 @@ export default class ListWorkspace extends BaseCommand {
return 'Fetches all the workspace you have access to'
}

async action(): Promise<void> {
getOptions(): CommandOption[] {
return PAGINATION_OPTION
}

async action({ options }: CommandActionData): Promise<void> {
Logger.info('Fetching all workspaces...')

const { success, data, error } =
await ControllerInstance.getInstance().workspaceController.getWorkspacesOfUser(
{},
{
...options
},
this.headers
)

Expand Down
31 changes: 31 additions & 0 deletions apps/cli/src/util/pagination-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { CommandOption } from '@/types/command/command.types'

export const PAGINATION_OPTION: CommandOption[] = [
{
short: '-p',
long: '--page <int>',
description: 'Index of the page.'
},
{
short: '-l',
long: '--limit <int>',
description: 'Total number of items per page.'
},
{
short: '-o',
long: '--order <string>',
description:
'Order to sort by - either ascending (ASC) or descending (DESC).',
choices: ['ASC', 'DESC']
},
{
short: '--sort',
long: '--sort <string>',
description: 'Field to sort by.'
},
{
short: '-s',
long: '--search <string>',
description: 'Search term.'
}
]
153 changes: 10 additions & 143 deletions pnpm-lock.yaml

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

0 comments on commit 2ec6577

Please sign in to comment.