cli.ts
1 import * as chalk from 'chalk'; 2 import { Format, Mode, ALL_CONTRACTS } from './types'; 3 4 export const FORMAT_OPT = { 5 name: 'format', 6 alias: 'o', 7 type: String, 8 defaultValue: Format.Stylish, 9 typeLabel: '{underline string}', 10 description: 11 'Output format. Options: text, stylish, compact, table, html, json (default: stylish).', 12 group: 'options' 13 }; 14 15 export const CLI_OPTS = [ 16 // tslint:disable-next-line: max-line-length 17 { 18 name: 'mode', 19 alias: 'm', 20 type: String, 21 defaultValue: Mode.Quick, 22 typeLabel: '{underline string}', 23 description: 24 'Analysis mode. Options: quick, standard, deep (default: quick).', 25 group: 'options' 26 }, 27 FORMAT_OPT, 28 { 29 name: 'no-cache-lookup', 30 alias: 'c', 31 type: Boolean, 32 defaultValue: false, 33 description: 'Deactivate MythX cache lookups (default: false).', 34 group: 'options' 35 }, 36 { 37 name: 'debug', 38 alias: 'd', 39 type: Boolean, 40 defaultValue: false, 41 description: 'Print MythX API request and response.', 42 group: 'options' 43 }, 44 { 45 name: 'limit', 46 alias: 'l', 47 type: Number, 48 defaultValue: 10, 49 description: 'Maximum number of concurrent analyses (default: 10).', 50 group: 'options' 51 }, 52 { 53 name: 'contracts', 54 type: String, 55 multiple: true, 56 defaultValue: ALL_CONTRACTS, 57 defaultOption: true, 58 description: 'List of contracts to submit for analysis (default: all).', 59 group: 'options' 60 }, 61 { 62 name: 'timeout', 63 alias: 't', 64 type: Number, 65 description: 66 'Timeout in secs to wait for analysis to finish (default: smart default based on mode).', 67 group: 'options' 68 }, 69 70 // deprecated 71 { 72 name: 'initial-delay', 73 alias: 'i', 74 type: Number, 75 defaultValue: 0, 76 description: 77 '[DEPRECATED] Time in seconds before first analysis status check (default: 0).', 78 group: 'deprecated' 79 }, 80 // obsolete 81 { 82 name: 'full', 83 alias: 'f', 84 type: Boolean, 85 description: 86 '[OBSOLETE] Perform full instead of quick analysis (not available on free MythX tier).', 87 group: 'obsolete' 88 } 89 ]; 90 91 export const CLI_COMMANDS = [ 92 { 93 name: 'verify', 94 typeLabel: '{italic <options> [contracts]}', 95 description: 96 'Runs MythX verification. If array of contracts are specified, only those contracts will be analysed.' 97 }, 98 { 99 name: 'verify report', 100 type: String, 101 typeLabel: '{italic [--format] uuid}', 102 description: 'Get the report of a completed analysis.' 103 }, 104 { 105 name: 'verify status', 106 type: String, 107 typeLabel: '{italic uuid}', 108 description: 'Get the status of an already submitted analysis.' 109 }, 110 { 111 name: 'verify list', 112 description: 'Displays a list of the last 20 submitted analyses in a table.' 113 }, 114 { 115 name: 'verify help', 116 type: Boolean, 117 defaultValue: false, 118 description: 'Display this usage guide.' 119 } 120 ]; 121 122 export const header = 123 'Smart contract security analysis with MythX\n\n' + 124 // tslint:disable: no-trailing-whitespace 125 chalk.blueBright(` ::::::: \` :::::::\` \`\`\` \`\`\` \`\` \`\` \`\`\` 126 +++++++\` +++++++\` ...\` \`... .\` .. \`.\` \`.\` 127 \`\`\`:+++///: -///+++/\`\`\` ..\`. .\`.. \`\` \`\` \`\`..\`\` ..\`\`\`\` \`.. \`.\` 128 -++++++/ :++++++: .. .\`. .. \`.\` .\` \`.\` ..\` \`.. ... 129 /++/ :+++ .. ..\` .. .. .. .\` .. \`. \`...\` 130 \`\`\`\`////\`\`\`:///.\`\`\` .. .. .\` .\` .\` .. \`. \`.\` \`.\` 131 -+++\` \`+++- +++: .. .. \`... ..\`\` .. \`. \`.\` \`.. 132 .:::\` \`:::. :::. \`\` \`\` ..\` \`\`\`\` \`\` \`\` \`\` \`\`\` 133 \`\`.. 134 \` 135 `); 136 // tslint:enable: no-trailing-whitespace 137 138 export const CLI_USAGE = [ 139 { 140 header: 'embark-mythx', 141 content: header, 142 raw: true 143 }, 144 { 145 header: 'Available Commands', 146 content: Array.from(new Set(CLI_COMMANDS.values())).map(command => { 147 return { 148 name: `${command.name} ${command.typeLabel || ''}`, 149 summary: command.description 150 }; 151 }) 152 }, 153 { 154 header: 'Examples', 155 content: [ 156 { 157 name: 'verify --mode full SimpleStorage ERC20', 158 summary: 159 'Runs a full MythX verification for the SimpleStorage and ERC20 contracts only.' 160 }, 161 { 162 name: 'verify status 0d60d6b3-e226-4192-b9c6-66b45eca3746', 163 summary: 164 'Gets the status of the MythX analysis with the specified uuid.' 165 }, 166 { 167 name: 168 'verify report --format stylish 0d60d6b3-e226-4192-b9c6-66b45eca3746', 169 summary: 170 'Gets the status of the MythX analysis with the specified uuid.' 171 } 172 ] 173 }, 174 { 175 header: 'Verify options', 176 hide: ['contracts'], 177 optionList: CLI_OPTS, 178 group: ['options'] 179 } 180 ];