-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): revamp command structure and a tenant create
- Loading branch information
Showing
23 changed files
with
342 additions
and
85 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Command } from 'commander'; | ||
import { marked } from 'marked'; | ||
import { markedTerminal } from 'marked-terminal'; | ||
//@ts-expect-error - This is a workaround to import the changelog file as text. It's working with bun. | ||
import Changelog from '../../CHANGELOG.md' with { type: 'text' }; | ||
// @ts-ignore | ||
marked.use(markedTerminal()); | ||
|
||
export const createChangelogCommand = (): Command => { | ||
const command = new Command('changelog'); | ||
command.description('Render the changelog.'); | ||
command.action(async () => { | ||
console.log(marked.parse(Changelog)); | ||
}); | ||
return command; | ||
}; |
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,55 @@ | ||
import { Argument, Command } from 'commander'; | ||
import type { Logger } from '../../domain/contracts/logger'; | ||
import type { CommandBus } from '../../domain/contracts/bus'; | ||
import type { GetAuthenticatedUser } from '../../domain/contracts/get-authenticated-user'; | ||
import type { FetchAvailableTenantIdentifier } from '../../domain/contracts/fetch-available-tenant-identifier'; | ||
|
||
type Deps = { | ||
logger: Logger; | ||
commandBus: CommandBus; | ||
getAuthenticatedUserWithInteractivityIfPossible: GetAuthenticatedUser; | ||
fetchAvailableTenantIdentifier: FetchAvailableTenantIdentifier; | ||
}; | ||
|
||
export const createCreateTenantCommand = ({ | ||
logger, | ||
commandBus, | ||
fetchAvailableTenantIdentifier, | ||
getAuthenticatedUserWithInteractivityIfPossible, | ||
}: Deps): Command => { | ||
const command = new Command('create'); | ||
command.description('Create a tenant in Crystallize'); | ||
command.addArgument(new Argument('<tenant-identifier>', 'The tenant identifier that you would like.')); | ||
command.option('--token_id <token_id>', 'Your access token id.'); | ||
command.option('--token_secret <token_secret>', 'Your access token secret.'); | ||
command.option('--no-interactive', 'Disable the interactive mode.'); | ||
command.option('--fail-if-not-available', 'Stop execution if the tenant identifier is not available.'); | ||
command.action(async (tenantIdentifier: string, flags) => { | ||
const { credentials } = await getAuthenticatedUserWithInteractivityIfPossible({ | ||
isInteractive: !flags.noInteractive, | ||
token_id: flags.token_id, | ||
token_secret: flags.token_secret, | ||
}); | ||
const finalTenantIdentifier = await fetchAvailableTenantIdentifier(credentials, tenantIdentifier); | ||
if (flags.failIfNotAvailable && finalTenantIdentifier !== tenantIdentifier) { | ||
throw new Error( | ||
`The tenant identifier ${tenantIdentifier} is not available. Suggestion: ${finalTenantIdentifier}.`, | ||
); | ||
} | ||
const intent = commandBus.createCommand('CreateCleanTenant', { | ||
credentials, | ||
tenant: { | ||
identifier: finalTenantIdentifier, | ||
}, | ||
}); | ||
const { result } = await commandBus.dispatch(intent); | ||
if (!result) { | ||
throw new Error('Failed to create tenant.'); | ||
} | ||
if (result.identifier !== tenantIdentifier) { | ||
logger.note(`Please note we change the identifier for you as the requested one was taken.`); | ||
} | ||
logger.success(`Tenant created with identifier: ${result.identifier}`); | ||
}); | ||
return command; | ||
}; |
File renamed without changes.
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
Oops, something went wrong.