-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): Add project command (#451)
- Loading branch information
Showing
24 changed files
with
660 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import BaseCommand from './base.command' | ||
import CreateProject from './project/create.project' | ||
import DeleteProject from './project/delete.project' | ||
import ForkProject from './project/fork.project' | ||
import GetProject from './project/get.project' | ||
import ListProjectForks from './project/list-forks.project' | ||
import ListProject from './project/list.project' | ||
import SyncProject from './project/sync.project' | ||
import UnlinkProject from './project/unlink.project' | ||
import UpdateProject from './project/update.project' | ||
|
||
export default class ProjectCommand extends BaseCommand { | ||
getName(): string { | ||
return 'project' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Manage projects of a workspace' | ||
} | ||
|
||
getSubCommands(): BaseCommand[] { | ||
return [ | ||
new CreateProject(), | ||
new DeleteProject(), | ||
new ForkProject(), | ||
new GetProject(), | ||
new ListProjectForks(), | ||
new ListProject(), | ||
new SyncProject(), | ||
new UnlinkProject(), | ||
new UpdateProject() | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import type { | ||
CommandActionData, | ||
CommandArgument, | ||
CommandOption | ||
} from '@/types/command/command.types' | ||
import BaseCommand from '../base.command' | ||
import { text } from '@clack/prompts' | ||
import ControllerInstance from '@/util/controller-instance' | ||
import { Logger } from '@/util/logger' | ||
|
||
export default class CreateProject extends BaseCommand { | ||
getName(): string { | ||
return 'create' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Creates a project' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Workspace Slug>', | ||
description: | ||
'Slug of the workspace under which you want to create the project' | ||
} | ||
] | ||
} | ||
|
||
getOptions(): CommandOption[] { | ||
return [ | ||
{ | ||
short: '-n', | ||
long: '--name <string>', | ||
description: 'Name of the project' | ||
}, | ||
{ | ||
short: '-d', | ||
long: '--description <string>', | ||
description: 'Description of the project. Defaults to project name' | ||
}, | ||
{ | ||
short: '-k', | ||
long: '--store-private-key', | ||
description: 'Store the private key in the project. Defaults to true', | ||
defaultValue: true | ||
}, | ||
{ | ||
short: '-a', | ||
long: '--access-level <string>', | ||
description: 'Access level of the project. Defaults to PRIVATE.', | ||
defaultValue: 'PRIVATE', | ||
choices: ['GLOBAL', 'PRIVATE', 'INTERNAL'] | ||
} | ||
] | ||
} | ||
|
||
async action({ args, options }: CommandActionData): Promise<void> { | ||
const [workspaceSlug] = args | ||
|
||
const parsedData = await this.parseOptions(options) | ||
|
||
const { data, error, success } = | ||
await ControllerInstance.getInstance().projectController.createProject( | ||
{ | ||
workspaceSlug, | ||
...parsedData | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
Logger.info(`Project ${data.name} (${data.slug}) created successfully!`) | ||
Logger.info(`Created at ${data.createdAt}`) | ||
Logger.info(`Updated at ${data.updatedAt}`) | ||
} else { | ||
Logger.error(`Failed to create project: ${error.message}`) | ||
} | ||
} | ||
|
||
async parseOptions(options: CommandActionData['options']): Promise<{ | ||
name: string | ||
description?: string | ||
storePrivateKey: boolean | ||
accessLevel: string | ||
}> { | ||
let { name, description } = options | ||
const { storePrivateKey, accessLevel } = options | ||
|
||
if (!name) { | ||
name = await text({ | ||
message: 'Enter the name of the Project', | ||
placeholder: 'My Project' | ||
}) | ||
} | ||
|
||
if (!description) { | ||
description = name | ||
} | ||
|
||
return { name, description, storePrivateKey, accessLevel } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { | ||
CommandActionData, | ||
CommandArgument | ||
} from '@/types/command/command.types' | ||
import BaseCommand from '../base.command' | ||
import { Logger } from '@/util/logger' | ||
import ControllerInstance from '@/util/controller-instance' | ||
|
||
export default class DeleteProject extends BaseCommand { | ||
getName(): string { | ||
return 'delete' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Deletes a project' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Project Slug>', | ||
description: 'Slug of the project that you want to delete.' | ||
} | ||
] | ||
} | ||
|
||
async action({ args }: CommandActionData): Promise<void> { | ||
const [projectSlug] = args | ||
|
||
const { error, success } = | ||
await ControllerInstance.getInstance().projectController.deleteProject( | ||
{ | ||
projectSlug | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
Logger.info(`Project ${projectSlug} deleted successfully!`) | ||
} else { | ||
Logger.error(`Failed to delete project: ${error.message}`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { | ||
CommandActionData, | ||
CommandArgument, | ||
CommandOption | ||
} from '@/types/command/command.types' | ||
import BaseCommand from '../base.command' | ||
import ControllerInstance from '@/util/controller-instance' | ||
import { Logger } from '@/util/logger' | ||
|
||
export default class ForkProject extends BaseCommand { | ||
getName(): string { | ||
return 'fork' | ||
} | ||
|
||
getDescription(): string { | ||
return 'Forks a project' | ||
} | ||
|
||
getArguments(): CommandArgument[] { | ||
return [ | ||
{ | ||
name: '<Project Slug>', | ||
description: 'Slug of the project which you want to fork.' | ||
} | ||
] | ||
} | ||
|
||
getOptions(): CommandOption[] { | ||
return [ | ||
{ | ||
short: '-n', | ||
long: '--name <Workspace Name>', | ||
description: 'Name of the workspace.' | ||
}, | ||
{ | ||
short: '-k', | ||
long: '--store-private-key <boolean>', | ||
description: 'Store the private key in the project. Defaults to true', | ||
defaultValue: true | ||
}, | ||
{ | ||
short: '-w', | ||
long: '--workspace <string>', | ||
description: 'Workspace slug to fork the project in' | ||
} | ||
] | ||
} | ||
|
||
async action({ options, args }: CommandActionData): Promise<void> { | ||
const [projectSlug] = args | ||
|
||
console.log(options) | ||
|
||
const { data, error, success } = | ||
await ControllerInstance.getInstance().projectController.forkProject( | ||
{ | ||
projectSlug, | ||
...options | ||
}, | ||
this.headers | ||
) | ||
|
||
if (success) { | ||
Logger.info(`Project ${data.name} (${data.slug}) forked successfully!`) | ||
Logger.info(`Created at ${data.createdAt}`) | ||
Logger.info(`Updated at ${data.updatedAt}`) | ||
} else { | ||
Logger.error(`Failed to fork project: ${error.message}`) | ||
} | ||
} | ||
} |
Oops, something went wrong.