-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from autonomys/feat/af-char-cli
Enhance Character Selection UX and Fix Minor Typos
- Loading branch information
Showing
6 changed files
with
387 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import inquirer from 'inquirer'; | ||
import { createLogger } from '../utils/logger.js'; | ||
import { listAvailableCharacters } from './utils/characterLoader.js'; | ||
|
||
const logger = createLogger('onboarding'); | ||
|
||
interface UserAnswers { | ||
character: string; | ||
} | ||
|
||
export const onboarding = async (preselectedCharacter?: string): Promise<UserAnswers> => { | ||
const characters = await listAvailableCharacters(); | ||
|
||
if (preselectedCharacter) { | ||
const character = characters.find(char => char.id === preselectedCharacter); | ||
if (character) { | ||
logger.info(`Using preselected character: ${character.id}`); | ||
return { character: character.id }; | ||
} | ||
throw new Error(`Character "${preselectedCharacter}" not found`); | ||
} | ||
|
||
const answers: UserAnswers = await inquirer.prompt([ | ||
{ | ||
type: 'list', | ||
name: 'character', | ||
message: 'Select a character to run the workflow:', | ||
choices: characters.map(char => ({ | ||
name: `${char.id} - ${char.description.split('.')[0]}`, | ||
value: char.id, | ||
})), | ||
}, | ||
]); | ||
logger.info(`Character: ${answers.character}`); | ||
|
||
return answers; | ||
}; |
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,30 @@ | ||
import { readdir } from 'fs/promises'; | ||
import { join } from 'path'; | ||
import { loadCharacter } from '../../config/characters.js'; | ||
|
||
interface CharacterInfo { | ||
id: string; | ||
name: string; | ||
description: string; | ||
username: string; | ||
} | ||
|
||
export const listAvailableCharacters = async (): Promise<CharacterInfo[]> => { | ||
const charactersPath = join(process.cwd(), 'config', 'characters'); | ||
const files = await readdir(charactersPath); | ||
const characterFiles = files.filter(file => file.endsWith('.yaml')); | ||
|
||
const characters = await Promise.all( | ||
characterFiles.map(async file => { | ||
const id = file.replace(/\.yaml$/, ''); | ||
const character = loadCharacter(id); | ||
return { | ||
id, | ||
name: character.name, | ||
description: character.description, | ||
username: character.username, | ||
}; | ||
}), | ||
); | ||
return 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.