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

feat(cli): Implemented pagination support #453

Merged
merged 8 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
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
30 changes: 30 additions & 0 deletions apps/cli/src/util/pagination-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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).'
},
{
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.