crytic_compile.cryticparser.cryticparser
Module handling the cli arguments
Call cryticparser.init(parser: ArgumentParser) to setup all the crytic-compile arguments in the argument parser
1""" 2Module handling the cli arguments 3 4Call cryticparser.init(parser: ArgumentParser) to setup all the crytic-compile arguments in the argument parser 5""" 6from argparse import ArgumentParser 7 8from crytic_compile.crytic_compile import get_platforms 9from crytic_compile.cryticparser import DEFAULTS_FLAG_IN_CONFIG 10 11 12def init(parser: ArgumentParser) -> None: 13 """Add crytic-compile arguments to the parser 14 15 Args: 16 parser (ArgumentParser): argparser where the cli flags are added 17 """ 18 19 group_compile = parser.add_argument_group("Compile options") 20 21 platforms = get_platforms() 22 23 group_compile.add_argument( 24 "--compile-force-framework", 25 help="Force the compile to a given framework " 26 f"({','.join([x.NAME.lower() for x in platforms])})", 27 action="store", 28 default=DEFAULTS_FLAG_IN_CONFIG["compile_force_framework"], 29 ) 30 31 group_compile.add_argument( 32 "--compile-libraries", 33 help='Libraries used for linking. Format: --compile-libraries "(name1, 0x00),(name2, 0x02)"', 34 action="store", 35 default=DEFAULTS_FLAG_IN_CONFIG["compile_libraries"], 36 ) 37 38 group_compile.add_argument( 39 "--compile-remove-metadata", 40 help="Remove the metadata from the bytecodes", 41 action="store_true", 42 default=DEFAULTS_FLAG_IN_CONFIG["compile_remove_metadata"], 43 ) 44 45 group_compile.add_argument( 46 "--compile-custom-build", 47 help="Replace platform specific build command", 48 action="store", 49 default=DEFAULTS_FLAG_IN_CONFIG["compile_custom_build"], 50 ) 51 52 group_compile.add_argument( 53 "--ignore-compile", 54 help="Do not run compile of any platform", 55 action="store_true", 56 dest="ignore_compile", 57 default=DEFAULTS_FLAG_IN_CONFIG["ignore_compile"], 58 ) 59 60 group_compile.add_argument( 61 "--skip-clean", 62 help="Do not attempt to clean before compiling with a platform", 63 action="store_true", 64 dest="skip_clean", 65 default=DEFAULTS_FLAG_IN_CONFIG["skip_clean"], 66 ) 67 68 _init_solc(parser) 69 _init_truffle(parser) 70 _init_embark(parser) 71 _init_brownie(parser) 72 _init_dapp(parser) 73 _init_etherlime(parser) 74 _init_etherscan(parser) 75 _init_waffle(parser) 76 _init_npx(parser) 77 _init_buidler(parser) 78 _init_hardhat(parser) 79 _init_foundry(parser) 80 81 82def _init_solc(parser: ArgumentParser) -> None: 83 """Init solc arguments 84 85 Args: 86 parser (ArgumentParser): argparser where the cli flags are added 87 """ 88 89 group_solc = parser.add_argument_group("Solc options") 90 group_solc.add_argument( 91 "--solc", help="solc path", action="store", default=DEFAULTS_FLAG_IN_CONFIG["solc"] 92 ) 93 94 group_solc.add_argument( 95 "--solc-remaps", 96 help="Add remapping", 97 action="store", 98 default=DEFAULTS_FLAG_IN_CONFIG["solc_remaps"], 99 ) 100 101 group_solc.add_argument( 102 "--solc-args", 103 help="Add custom solc arguments. Example: --solc-args" 104 ' "--allow-path /tmp --evm-version byzantium".', 105 action="store", 106 default=DEFAULTS_FLAG_IN_CONFIG["solc_args"], 107 ) 108 109 group_solc.add_argument( 110 "--solc-disable-warnings", 111 help="Disable solc warnings", 112 action="store_true", 113 default=DEFAULTS_FLAG_IN_CONFIG["solc_disable_warnings"], 114 ) 115 116 group_solc.add_argument( 117 "--solc-working-dir", 118 help="Change the default working directory", 119 action="store", 120 default=DEFAULTS_FLAG_IN_CONFIG["solc_working_dir"], 121 ) 122 123 group_solc.add_argument( 124 "--solc-solcs-select", 125 help="Specify different solc version to try (env config). Depends on solc-select ", 126 action="store", 127 default=DEFAULTS_FLAG_IN_CONFIG["solc_solcs_select"], 128 ) 129 130 group_solc.add_argument( 131 "--solc-solcs-bin", 132 help="Specify different solc version to try (path config)." 133 " Example: --solc-solcs-bin solc-0.4.24,solc-0.5.3", 134 action="store", 135 default=DEFAULTS_FLAG_IN_CONFIG["solc_solcs_bin"], 136 ) 137 138 group_solc.add_argument( 139 "--solc-standard-json", 140 help="Compile all specified targets in a single compilation using solc standard json", 141 action="store_true", 142 default=DEFAULTS_FLAG_IN_CONFIG["solc_standard_json"], 143 ) 144 145 group_solc.add_argument( 146 "--solc-force-legacy-json", 147 help="Force the solc compiler to use the legacy json ast format over the compact json ast format", 148 action="store_true", 149 default=DEFAULTS_FLAG_IN_CONFIG["solc_force_legacy_json"], 150 ) 151 152 153def _init_waffle(parser: ArgumentParser) -> None: 154 """Init waffle arguments 155 156 Args: 157 parser (ArgumentParser): argparser where the cli flags are added 158 """ 159 group_waffle = parser.add_argument_group("Waffle options") 160 group_waffle.add_argument( 161 "--waffle-ignore-compile", 162 help="Do not run waffle compile", 163 action="store_true", 164 dest="waffle_ignore_compile", 165 default=DEFAULTS_FLAG_IN_CONFIG["waffle_ignore_compile"], 166 ) 167 168 group_waffle.add_argument( 169 "--waffle-config-file", 170 help="Provide a waffle config file", 171 action="store", 172 default=DEFAULTS_FLAG_IN_CONFIG["waffle_config_file"], 173 ) 174 175 176def _init_truffle(parser: ArgumentParser) -> None: 177 """Init truffle arguments 178 179 Args: 180 parser (ArgumentParser): argparser where the cli flags are added 181 """ 182 group_truffle = parser.add_argument_group("Truffle options") 183 group_truffle.add_argument( 184 "--truffle-ignore-compile", 185 help="Do not run truffle compile", 186 action="store_true", 187 dest="truffle_ignore_compile", 188 default=DEFAULTS_FLAG_IN_CONFIG["truffle_ignore_compile"], 189 ) 190 191 group_truffle.add_argument( 192 "--truffle-build-directory", 193 help="Use an alternative truffle build directory", 194 action="store", 195 dest="truffle_build_directory", 196 default=DEFAULTS_FLAG_IN_CONFIG["truffle_build_directory"], 197 ) 198 199 group_truffle.add_argument( 200 "--truffle-version", 201 help="Use a local Truffle version (with npx)", 202 action="store", 203 default=DEFAULTS_FLAG_IN_CONFIG["truffle_version"], 204 ) 205 206 group_truffle.add_argument( 207 "--truffle-overwrite-config", 208 help="Use a simplified version of truffle-config.js for compilation", 209 action="store_true", 210 default=DEFAULTS_FLAG_IN_CONFIG["truffle_overwrite_config"], 211 ) 212 213 group_truffle.add_argument( 214 "--truffle-overwrite-version", 215 help="Overwrite solc version in truffle-config.js (only if --truffle-overwrite-config)", 216 action="store", 217 default=DEFAULTS_FLAG_IN_CONFIG["truffle_overwrite_version"], 218 ) 219 220 221def _init_embark(parser: ArgumentParser) -> None: 222 """Init embark arguments 223 224 Args: 225 parser (ArgumentParser): argparser where the cli flags are added 226 """ 227 group_embark = parser.add_argument_group("Embark options") 228 group_embark.add_argument( 229 "--embark-ignore-compile", 230 help="Do not run embark build", 231 action="store_true", 232 dest="embark_ignore_compile", 233 default=DEFAULTS_FLAG_IN_CONFIG["embark_ignore_compile"], 234 ) 235 236 group_embark.add_argument( 237 "--embark-overwrite-config", 238 help="Install @trailofbits/embark-contract-export and add it to embark.json", 239 action="store_true", 240 default=DEFAULTS_FLAG_IN_CONFIG["embark_overwrite_config"], 241 ) 242 243 244def _init_brownie(parser: ArgumentParser) -> None: 245 """Init brownie arguments 246 247 Args: 248 parser (ArgumentParser): argparser where the cli flags are added 249 """ 250 group_brownie = parser.add_argument_group("Brownie options") 251 group_brownie.add_argument( 252 "--brownie-ignore-compile", 253 help="Do not run brownie compile", 254 action="store_true", 255 dest="brownie_ignore_compile", 256 default=DEFAULTS_FLAG_IN_CONFIG["brownie_ignore_compile"], 257 ) 258 259 260def _init_dapp(parser: ArgumentParser) -> None: 261 """Init dapp arguments 262 263 Args: 264 parser (ArgumentParser): argparser where the cli flags are added 265 """ 266 group_dapp = parser.add_argument_group("Dapp options") 267 group_dapp.add_argument( 268 "--dapp-ignore-compile", 269 help="Do not run dapp build", 270 action="store_true", 271 dest="dapp_ignore_compile", 272 default=DEFAULTS_FLAG_IN_CONFIG["dapp_ignore_compile"], 273 ) 274 275 276def _init_etherlime(parser: ArgumentParser) -> None: 277 """Init etherlime arguments 278 279 Args: 280 parser (ArgumentParser): argparser where the cli flags are added 281 """ 282 group_etherlime = parser.add_argument_group("Etherlime options") 283 group_etherlime.add_argument( 284 "--etherlime-ignore-compile", 285 help="Do not run etherlime compile", 286 action="store_true", 287 dest="etherlime_ignore_compile", 288 default=DEFAULTS_FLAG_IN_CONFIG["etherlime_ignore_compile"], 289 ) 290 291 group_etherlime.add_argument( 292 "--etherlime-compile-arguments", 293 help="Add arbitrary arguments to etherlime compile " 294 "(note: [dir] is the the directory provided to crytic-compile)", 295 action="store_true", 296 dest="etherlime_compile_arguments", 297 default=DEFAULTS_FLAG_IN_CONFIG["etherlime_compile_arguments"], 298 ) 299 300 301def _init_etherscan(parser: ArgumentParser) -> None: 302 """Init etherscan arguments 303 304 Args: 305 parser (ArgumentParser): argparser where the cli flags are added 306 """ 307 group_etherscan = parser.add_argument_group("Etherscan options") 308 group_etherscan.add_argument( 309 "--etherscan-only-source-code", 310 help="Only compile if the source code is available.", 311 action="store_true", 312 dest="etherscan_only_source_code", 313 default=DEFAULTS_FLAG_IN_CONFIG["etherscan_only_source_code"], 314 ) 315 316 group_etherscan.add_argument( 317 "--etherscan-only-bytecode", 318 help="Only looks for bytecode.", 319 action="store_true", 320 dest="etherscan_only_bytecode", 321 default=DEFAULTS_FLAG_IN_CONFIG["etherscan_only_bytecode"], 322 ) 323 324 group_etherscan.add_argument( 325 "--etherscan-apikey", 326 help="Etherscan API key.", 327 action="store", 328 dest="etherscan_api_key", 329 default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"], 330 ) 331 332 group_etherscan.add_argument( 333 "--avax-apikey", 334 help="Etherscan API key.", 335 action="store", 336 dest="avax_api_key", 337 default=DEFAULTS_FLAG_IN_CONFIG["etherscan_api_key"], 338 ) 339 340 group_etherscan.add_argument( 341 "--etherscan-export-directory", 342 help="Directory in which to save the analyzed contracts.", 343 action="store", 344 dest="etherscan_export_dir", 345 default=DEFAULTS_FLAG_IN_CONFIG["etherscan_export_directory"], 346 ) 347 348 349def _init_npx(parser: ArgumentParser) -> None: 350 """Init npx arguments 351 352 Args: 353 parser (ArgumentParser): argparser where the cli flags are added 354 """ 355 group_npx = parser.add_argument_group("NPX options") 356 group_npx.add_argument( 357 "--npx-disable", 358 help="Do not use npx", 359 action="store_true", 360 dest="npx_disable", 361 default=DEFAULTS_FLAG_IN_CONFIG["npx_disable"], 362 ) 363 364 365def _init_buidler(parser: ArgumentParser) -> None: 366 """Init buidler arguments 367 368 Args: 369 parser (ArgumentParser): argparser where the cli flags are added 370 """ 371 group_buidler = parser.add_argument_group("Buidler options") 372 group_buidler.add_argument( 373 "--buidler-ignore-compile", 374 help="Do not run buidler compile", 375 action="store_true", 376 dest="buidler_ignore_compile", 377 default=DEFAULTS_FLAG_IN_CONFIG["buidler_ignore_compile"], 378 ) 379 380 group_buidler.add_argument( 381 "--buidler-cache-directory", 382 help="Use an alternative buidler cache directory (default ./cache)", 383 action="store", 384 dest="buidler_cache_directory", 385 default=DEFAULTS_FLAG_IN_CONFIG["buidler_cache_directory"], 386 ) 387 388 group_buidler.add_argument( 389 "--buidler-skip-directory-name-fix", 390 help="Disable directory name fix (see https://github.com/crytic/crytic-compile/issues/116)", 391 action="store_true", 392 dest="buidler_skip_directory_name_fix", 393 default=DEFAULTS_FLAG_IN_CONFIG["buidler_skip_directory_name_fix"], 394 ) 395 396 397def _init_hardhat(parser: ArgumentParser) -> None: 398 """Init hardhat arguments 399 400 Args: 401 parser (ArgumentParser): argparser where the cli flags are added 402 """ 403 group_hardhat = parser.add_argument_group("Hardhat options") 404 group_hardhat.add_argument( 405 "--hardhat-ignore-compile", 406 help="Do not run hardhat compile", 407 action="store_true", 408 dest="hardhat_ignore_compile", 409 default=DEFAULTS_FLAG_IN_CONFIG["hardhat_ignore_compile"], 410 ) 411 412 group_hardhat.add_argument( 413 "--hardhat-cache-directory", 414 help="Use an alternative hardhat cache directory (default ./cache)", 415 action="store", 416 dest="hardhat_cache_directory", 417 default=DEFAULTS_FLAG_IN_CONFIG["hardhat_cache_directory"], 418 ) 419 420 group_hardhat.add_argument( 421 "--hardhat-artifacts-directory", 422 help="Use an alternative hardhat artifacts directory (default ./artifacts)", 423 action="store", 424 dest="hardhat_artifacts_directory", 425 default=DEFAULTS_FLAG_IN_CONFIG["hardhat_artifacts_directory"], 426 ) 427 428 429def _init_foundry(parser: ArgumentParser) -> None: 430 """Init foundry arguments 431 432 Args: 433 parser (ArgumentParser): argparser where the cli flags are added 434 """ 435 group_foundry = parser.add_argument_group("Foundry options") 436 group_foundry.add_argument( 437 "--foundry-ignore-compile", 438 help="Do not run foundry compile", 439 action="store_true", 440 dest="foundry_ignore_compile", 441 default=DEFAULTS_FLAG_IN_CONFIG["foundry_ignore_compile"], 442 ) 443 444 group_foundry.add_argument( 445 "--foundry-out-directory", 446 help="Use an alternative out directory (default: out)", 447 action="store", 448 dest="foundry_out_directory", 449 default=DEFAULTS_FLAG_IN_CONFIG["foundry_out_directory"], 450 ) 451 452 group_foundry.add_argument( 453 "--foundry-compile-all", 454 help="Don't skip compiling test and script", 455 action="store_true", 456 dest="foundry_compile_all", 457 default=DEFAULTS_FLAG_IN_CONFIG["foundry_compile_all"], 458 )
def
init(parser: argparse.ArgumentParser) -> None:
13def init(parser: ArgumentParser) -> None: 14 """Add crytic-compile arguments to the parser 15 16 Args: 17 parser (ArgumentParser): argparser where the cli flags are added 18 """ 19 20 group_compile = parser.add_argument_group("Compile options") 21 22 platforms = get_platforms() 23 24 group_compile.add_argument( 25 "--compile-force-framework", 26 help="Force the compile to a given framework " 27 f"({','.join([x.NAME.lower() for x in platforms])})", 28 action="store", 29 default=DEFAULTS_FLAG_IN_CONFIG["compile_force_framework"], 30 ) 31 32 group_compile.add_argument( 33 "--compile-libraries", 34 help='Libraries used for linking. Format: --compile-libraries "(name1, 0x00),(name2, 0x02)"', 35 action="store", 36 default=DEFAULTS_FLAG_IN_CONFIG["compile_libraries"], 37 ) 38 39 group_compile.add_argument( 40 "--compile-remove-metadata", 41 help="Remove the metadata from the bytecodes", 42 action="store_true", 43 default=DEFAULTS_FLAG_IN_CONFIG["compile_remove_metadata"], 44 ) 45 46 group_compile.add_argument( 47 "--compile-custom-build", 48 help="Replace platform specific build command", 49 action="store", 50 default=DEFAULTS_FLAG_IN_CONFIG["compile_custom_build"], 51 ) 52 53 group_compile.add_argument( 54 "--ignore-compile", 55 help="Do not run compile of any platform", 56 action="store_true", 57 dest="ignore_compile", 58 default=DEFAULTS_FLAG_IN_CONFIG["ignore_compile"], 59 ) 60 61 group_compile.add_argument( 62 "--skip-clean", 63 help="Do not attempt to clean before compiling with a platform", 64 action="store_true", 65 dest="skip_clean", 66 default=DEFAULTS_FLAG_IN_CONFIG["skip_clean"], 67 ) 68 69 _init_solc(parser) 70 _init_truffle(parser) 71 _init_embark(parser) 72 _init_brownie(parser) 73 _init_dapp(parser) 74 _init_etherlime(parser) 75 _init_etherscan(parser) 76 _init_waffle(parser) 77 _init_npx(parser) 78 _init_buidler(parser) 79 _init_hardhat(parser) 80 _init_foundry(parser)
Add crytic-compile arguments to the parser
Args: parser (ArgumentParser): argparser where the cli flags are added