Skip to content

Commit

Permalink
feat: added the description functions for human-readable
Browse files Browse the repository at this point in the history
  • Loading branch information
kurone-kito committed May 11, 2021
1 parent 16c74b8 commit c048f65
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/dantalion-cli/src/detail.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,25 @@
import { getDetail, Genius, types } from '@kurone-kito/dantalion-core';
import { Genius, getDetail, types } from '@kurone-kito/dantalion-core';
import { getDescriptionAsync } from '@kurone-kito/dantalion-i18n';
import article from './toMarkdown/article';
import { list } from './toMarkdown/list';
import { detailsAsync } from './toMarkdown/template';
import type { Command } from './type';

const command: Command = {
getDescriptionAsync: async (detail) => {
const type = detail as Genius;
const result = getDetail(type);
const desc = await getDescriptionAsync(type);
return result
? article({
body: await detailsAsync(type, result),
head: `Dantalion: ${desc?.detail}`,
})
: article({
head: `Dantalion: ${desc?.details}`,
body: list(...types.genius),
});
},
getObject: (detail) => getDetail(detail as Genius) || types.genius,
alias: 'dt',
command: 'detail [genius]',
Expand Down
17 changes: 17 additions & 0 deletions packages/dantalion-cli/src/personality.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,24 @@
import { getPersonality } from '@kurone-kito/dantalion-core';
import { getDescriptionAsync } from '@kurone-kito/dantalion-i18n';
import article from './toMarkdown/article';
import { personalityAsync } from './toMarkdown/template';
import type { Command } from './type';

const command: Command = {
getDescriptionAsync: async (birthday) => {
const b = birthday as string;
const result = getPersonality(b);
const date = new Date(b);
const desc = await getDescriptionAsync(
Number.isNaN(date.getTime()) ? b : date.toDateString()
);
return result
? article({
body: await personalityAsync(result),
head: `Dantalion: ${desc?.personality}`,
})
: article({ head: `Dantalion: ${desc?.invalid}` });
},
getObject: (birthday) => getPersonality(birthday as string),
alias: 'ps',
command: 'personality <birthday>',
Expand Down
3 changes: 3 additions & 0 deletions packages/dantalion-cli/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
export interface Command {
readonly getDescriptionAsync: (
...arg: readonly unknown[]
) => string | Promise<string>;
readonly getObject: (
...arg: readonly unknown[]
) => unknown | Promise<unknown>;
Expand Down

0 comments on commit c048f65

Please sign in to comment.