import { IPicGo , IPlugin , Undefinable , ICLIConfigs , IStringKeyMap } from '../../types' ; const use = { handle : async ( ctx ) => { const cmd = ctx . cmd ; cmd . program . command ( 'use' ) . arguments ( '[module]' ) . description ( 'use modules of picgo' ) . action ( ( module ) => { ( async ( ) => { try { let prompts = [ ] ; const config = { uploader : { type : 'list' , name : 'uploader' , message : 'Use an uploader' , choices : ctx . helper . uploader . getIdList ( ) , default : ctx . getConfig ( 'picBed.uploader' ) || ctx . getConfig ( 'picBed.current' ) || 'smms' } , transformer : { type : 'list' , name : 'transformer' , message : 'Use a transformer' , choices : ctx . helper . transformer . getIdList ( ) , default : ctx . getConfig < Undefinable < string > > ( 'picBed.transformer' ) || 'path' } , plugins : { type : 'checkbox' , name : 'plugins' , message : 'Use plugins' , choices : ctx . pluginLoader . getFullList ( ) , default : Object . keys ( ctx . getConfig ( 'picgoPlugins' ) ) . filter ( ( item ) => ctx . getConfig ( `picgoPlugins.${ item }` ) ) } } ; if ( module ) { if ( config [ module ] ) { prompts . push ( config [ module ] ) ; } else { ctx . log . warn ( `No module named ${ module }` ) ; return ctx . log . warn ( 'Available modules are uploader|transformer|plugins' ) ; } } else { prompts = Object . keys ( config ) . map ( ( item ) => config [ item ] ) ; } const answer = await cmd . inquirer . prompt < any > ( prompts ) ; if ( answer . plugins ) { const plugins = ctx . getConfig < IStringKeyMap < boolean > > ( 'picgoPlugins' ) ; Object . keys ( plugins ) . map ( ( item ) => { if ( answer . plugins . includes ( item ) ) { plugins [ item ] = true ; } else { plugins [ item ] = false ; } } ) ; ctx . saveConfig ( { picgoPlugins : plugins } ) ; } ctx . saveConfig ( { 'picBed.current' : answer . uploader || ctx . getConfig < string > ( 'picBed.current' ) , 'picBed.uploader' : answer . uploader || ctx . getConfig < string > ( 'picBed.current' ) , 'picBed.transformer' : answer . transformer || 'path' } ) ; ctx . log . success ( 'Configure config successfully!' ) ; } catch ( e ) { ctx . log . error ( e ) ; if ( process . argv . includes ( '--debug' ) ) { throw e ; } } } ) ( ) . catch ( ( e ) => { ctx . log . error ( e ) ; } ) ; } ) ; } } ; export default use ;