@@ -31,7 +31,8 @@ export enum CONFIG_KEYS {
3131
3232export enum CONFIG_MODES {
3333 get = 'get' ,
34- set = 'set'
34+ set = 'set' ,
35+ describe = 'describe'
3536}
3637
3738export const MODEL_LIST = {
@@ -603,28 +604,166 @@ export const setConfig = (
603604 outro ( `${ chalk . green ( '✔' ) } config successfully set` ) ;
604605} ;
605606
607+ // --- HELP MESSAGE GENERATION ---
608+ function getConfigKeyDetails ( key ) {
609+ switch ( key ) {
610+ case CONFIG_KEYS . OCO_MODEL :
611+ return {
612+ description : 'The AI model to use for generating commit messages' ,
613+ values : {
614+ openai : MODEL_LIST . openai ,
615+ anthropic : MODEL_LIST . anthropic ,
616+ gemini : MODEL_LIST . gemini ,
617+ groq : MODEL_LIST . groq ,
618+ mistral : MODEL_LIST . mistral ,
619+ deepseek : MODEL_LIST . deepseek
620+ }
621+ } ;
622+ case CONFIG_KEYS . OCO_AI_PROVIDER :
623+ return {
624+ description : 'The AI provider to use' ,
625+ values : Object . values ( OCO_AI_PROVIDER_ENUM )
626+ } ;
627+ case CONFIG_KEYS . OCO_PROMPT_MODULE :
628+ return {
629+ description : 'The prompt module to use for commit message generation' ,
630+ values : [ 'conventional-commit' , '@commitlint' ]
631+ } ;
632+ case CONFIG_KEYS . OCO_LANGUAGE :
633+ return {
634+ description : 'The language to use for commit messages' ,
635+ values : Object . keys ( i18n )
636+ } ;
637+ case CONFIG_KEYS . OCO_TEST_MOCK_TYPE :
638+ return {
639+ description : 'The type of test mock to use' ,
640+ values : [ 'commit-message' , 'prompt-module-commitlint-config' ]
641+ } ;
642+ case CONFIG_KEYS . OCO_DESCRIPTION :
643+ case CONFIG_KEYS . OCO_EMOJI :
644+ case CONFIG_KEYS . OCO_WHY :
645+ case CONFIG_KEYS . OCO_ONE_LINE_COMMIT :
646+ case CONFIG_KEYS . OCO_OMIT_SCOPE :
647+ case CONFIG_KEYS . OCO_GITPUSH :
648+ return {
649+ description : 'Boolean flag' ,
650+ values : [ 'true' , 'false' ]
651+ } ;
652+ case CONFIG_KEYS . OCO_TOKENS_MAX_INPUT :
653+ case CONFIG_KEYS . OCO_TOKENS_MAX_OUTPUT :
654+ return {
655+ description : 'Integer number' ,
656+ values : [ 'Any positive integer' ]
657+ } ;
658+ case CONFIG_KEYS . OCO_API_KEY :
659+ return {
660+ description : 'API key for the selected provider' ,
661+ values : [ 'String (required for most providers)' ]
662+ } ;
663+ case CONFIG_KEYS . OCO_API_URL :
664+ return {
665+ description : 'Custom API URL' ,
666+ values : [ "URL string (must start with 'http://' or 'https://')" ]
667+ } ;
668+ case CONFIG_KEYS . OCO_API_CUSTOM_HEADERS :
669+ return {
670+ description : 'Custom headers for API requests' ,
671+ values : [ 'JSON string of headers' ]
672+ } ;
673+ case CONFIG_KEYS . OCO_MESSAGE_TEMPLATE_PLACEHOLDER :
674+ return {
675+ description : 'Template placeholder for commit messages' ,
676+ values : [ "String (must start with $)" ]
677+ } ;
678+ default :
679+ return {
680+ description : 'String value' ,
681+ values : [ 'Any string' ]
682+ } ;
683+ }
684+ }
685+
686+ function printConfigKeyHelp ( param ) {
687+ if ( ! Object . values ( CONFIG_KEYS ) . includes ( param ) ) {
688+ console . log ( chalk . red ( `Unknown config parameter: ${ param } ` ) ) ;
689+ return ;
690+ }
691+
692+ const details = getConfigKeyDetails ( param as CONFIG_KEYS ) ;
693+
694+ console . log ( chalk . bold ( `\n${ param } :` ) ) ;
695+ console . log ( chalk . gray ( ` Description: ${ details . description } ` ) ) ;
696+
697+ if ( Array . isArray ( details . values ) ) {
698+ console . log ( chalk . gray ( ' Accepted values:' ) ) ;
699+ details . values . forEach ( value => {
700+ console . log ( chalk . gray ( ` - ${ value } ` ) ) ;
701+ } ) ;
702+ } else {
703+ console . log ( chalk . gray ( ' Accepted values by provider:' ) ) ;
704+ Object . entries ( details . values ) . forEach ( ( [ provider , values ] ) => {
705+ console . log ( chalk . gray ( ` ${ provider } :` ) ) ;
706+ ( values as string [ ] ) . forEach ( value => {
707+ console . log ( chalk . gray ( ` - ${ value } ` ) ) ;
708+ } ) ;
709+ } ) ;
710+ }
711+ }
712+
713+ function printAllConfigHelp ( ) {
714+ console . log ( chalk . bold ( 'Available config parameters:' ) ) ;
715+ for ( const key of Object . values ( CONFIG_KEYS ) ) {
716+ printConfigKeyHelp ( key ) ;
717+ }
718+ console . log ( chalk . gray ( '\nFor more help, see https://github.com/di-sukharev/opencommit' ) ) ;
719+ }
720+
606721export const configCommand = command (
607722 {
608723 name : COMMANDS . config ,
609- parameters : [ '<mode>' , '<key=values...>' ]
724+ parameters : [ '<mode>' , '[key=values...]' ] ,
725+ help : {
726+ description : 'Configure opencommit settings' ,
727+ examples : [
728+ 'Describe all config parameters: oco config describe' ,
729+ 'Describe a specific parameter: oco config describe OCO_MODEL' ,
730+ 'Get a config value: oco config get OCO_MODEL' ,
731+ 'Set a config value: oco config set OCO_MODEL=gpt-4'
732+ ]
733+ }
610734 } ,
611735 async ( argv ) => {
612736 try {
613737 const { mode, keyValues } = argv . _ ;
614738 intro ( `COMMAND: config ${ mode } ${ keyValues } ` ) ;
615739
616- if ( mode === CONFIG_MODES . get ) {
740+ if ( mode === CONFIG_MODES . describe ) {
741+ if ( ! keyValues || keyValues . length === 0 ) {
742+ printAllConfigHelp ( ) ;
743+ } else {
744+ for ( const key of keyValues ) {
745+ printConfigKeyHelp ( key ) ;
746+ }
747+ }
748+ process . exit ( 0 ) ;
749+ } else if ( mode === CONFIG_MODES . get ) {
750+ if ( ! keyValues || keyValues . length === 0 ) {
751+ throw new Error ( 'No config keys specified for get mode' ) ;
752+ }
617753 const config = getConfig ( ) || { } ;
618754 for ( const key of keyValues ) {
619755 outro ( `${ key } =${ config [ key as keyof typeof config ] } ` ) ;
620756 }
621757 } else if ( mode === CONFIG_MODES . set ) {
758+ if ( ! keyValues || keyValues . length === 0 ) {
759+ throw new Error ( 'No config keys specified for set mode' ) ;
760+ }
622761 await setConfig (
623762 keyValues . map ( ( keyValue ) => keyValue . split ( '=' ) as [ string , string ] )
624763 ) ;
625764 } else {
626765 throw new Error (
627- `Unsupported mode: ${ mode } . Valid modes are: "set" and "get "`
766+ `Unsupported mode: ${ mode } . Valid modes are: "set", "get", and "describe "`
628767 ) ;
629768 }
630769 } catch ( error ) {
0 commit comments