@@ -4,6 +4,7 @@ import { EOL } from 'os'
44// Our files - FIXME path import
55import { FLAGS , FORMATS , PROJECTS } from '../utils/commands/export/constants'
66import ExportUi from '../utils/commands/export/ui'
7+ import ExportUtils from '../utils/commands/export/utils'
78import ExportValidator from '../utils/commands/export/validators'
89
910export default class Export extends Command {
@@ -25,36 +26,33 @@ export default class Export extends Command {
2526 * Entrypoint of the `twe export` command
2627 */
2728 async run ( ) {
28- let { flags } = this . parse ( Export )
29- const availableFlags = this . availableFlags ( FLAGS )
30- const missingFlags = availableFlags . filter ( el => ! ( el in flags ) )
31- const availableFlagsValues = {
32- formats : FORMATS ,
33- projects : PROJECTS
34- }
29+ const utils = new ExportUtils ( )
3530 const validator = new ExportValidator ( )
3631
3732 // Step 1 - check requirements
3833 const invalidRequirements = validator . checkRequirements ( )
3934 if ( invalidRequirements . length !== 0 ) {
40- const plural = ( invalidRequirements . length > 1 ) ? 's' : ''
41- let errorMessage = `missing requirement${ plural } ${ EOL } `
42- errorMessage += invalidRequirements . map ( ( error : any ) => {
43- return `• ${ error } `
44- } ) . join ( EOL )
45- this . error ( errorMessage , { exit : 2 } )
35+ this . error (
36+ utils . errorMessage ( 'missing requirement' , invalidRequirements ) ,
37+ { exit : 2 }
38+ )
4639 }
4740
41+ // Prepare information
42+ let { flags } = this . parse ( Export )
43+ const availableFlags = utils . availableFlags ( FLAGS )
44+ const missingFlags = availableFlags . filter ( el => ! ( el in flags ) )
45+ const availableFlagsValues = { formats : FORMATS , projects : PROJECTS }
46+
4847 // Step 2 - check flags values (or exit)
4948 if ( missingFlags . length !== 0 ) {
50- if ( flags . interactive ) {
51- const missingFlagsData = await new ExportUi ( ) . askMissingFlags (
52- missingFlags , availableFlagsValues
53- )
54- flags = { ...flags , ...missingFlagsData }
55- } else {
49+ if ( ! flags . interactive ) {
5650 this . error ( 'Missing parameters' , { exit : 3 } )
5751 }
52+ const missingFlagsData = await new ExportUi ( ) . askMissingFlags (
53+ missingFlags , availableFlagsValues
54+ )
55+ flags = { ...flags , ...missingFlagsData }
5856 }
5957
6058 // Step 2.1 - remove 'interactive' flag
@@ -63,26 +61,15 @@ export default class Export extends Command {
6361 // Step 3 - Verify params
6462 const invalidParams = validator . checkParams ( params , availableFlagsValues )
6563 if ( invalidParams . length !== 0 ) {
66- const plural = ( invalidParams . length > 1 ) ? 's' : ''
67- let errorMessage = `invalid param${ plural } ${ EOL } `
68- errorMessage += invalidParams . map ( ( invalidParam : string ) => {
69- return `• ${ invalidParam } `
70- } ) . join ( EOL )
71- this . error ( errorMessage , { exit : 2 } )
64+ this . error (
65+ utils . errorMessage ( 'invalid param' , invalidParams ) ,
66+ { exit : 2 }
67+ )
7268 }
7369
7470 // (FIXME) Step 4 - Extract data
7571 // (FIXME) Step 5 - Filter data
7672 // (FIXME) Step 6 - Aggregate data
7773 // (FIXME) Step 7 - Save data
7874 }
79-
80- /**
81- * CLI flags of 'export' commands
82- */
83- private availableFlags ( flags : any ) {
84- return Object . keys ( flags ) . filter ( ( el , _index , _array ) => {
85- return el !== 'help'
86- } )
87- }
8875}
0 commit comments