|
| 1 | +import os |
| 2 | + |
| 3 | +from click.exceptions import ClickException |
| 4 | +from cookiecutter.config import DEFAULT_CONFIG |
| 5 | +from cookiecutter.utils import rmtree |
| 6 | +from interrogatio import dialogus |
| 7 | +from interrogatio.validators.builtins import RequiredValidator |
| 8 | + |
| 9 | + |
| 10 | +def _purge_cookiecutters_dir(): |
| 11 | + # Avoid asking rewrite clone boilerplate project |
| 12 | + cookie_dir = DEFAULT_CONFIG['cookiecutters_dir'] |
| 13 | + if os.path.isdir(cookie_dir): |
| 14 | + rmtree(cookie_dir) |
| 15 | + |
| 16 | + |
| 17 | +def _general_questions(idx, total): |
| 18 | + questions = [ |
| 19 | + { |
| 20 | + 'name': 'project_name', |
| 21 | + 'type': 'input', |
| 22 | + 'message': 'Extension project name: ', |
| 23 | + 'default': 'My Awesome Project', |
| 24 | + 'validators': (RequiredValidator(message='Please, provide a project name.'),), |
| 25 | + }, |
| 26 | + { |
| 27 | + 'name': 'description', |
| 28 | + 'type': 'input', |
| 29 | + 'message': 'Extension project description: ', |
| 30 | + 'default': 'Project description', |
| 31 | + 'validators': (RequiredValidator(message='Please, provide a description.'),), |
| 32 | + }, |
| 33 | + { |
| 34 | + 'name': 'package_name', |
| 35 | + 'type': 'input', |
| 36 | + 'message': 'Extension project package name: ', |
| 37 | + 'default': 'connect_ext', |
| 38 | + 'validators': (RequiredValidator(message='Please, provide a package name.'),), |
| 39 | + }, |
| 40 | + { |
| 41 | + 'name': 'author', |
| 42 | + 'type': 'input', |
| 43 | + 'message': 'Extension project author: ', |
| 44 | + 'default': 'Globex Corporation', |
| 45 | + 'validators': (RequiredValidator(message='Please, provide an author name.'),), |
| 46 | + }, |
| 47 | + { |
| 48 | + 'name': 'version', |
| 49 | + 'type': 'input', |
| 50 | + 'message': 'Extension project version: ', |
| 51 | + 'default': '0.1.0', |
| 52 | + 'validators': (RequiredValidator(message='Please, provide a version.'),), |
| 53 | + }, |
| 54 | + { |
| 55 | + 'name': 'license', |
| 56 | + 'type': 'selectone', |
| 57 | + 'description': 'Extension project license: ', |
| 58 | + 'values': [ |
| 59 | + ('Apache Software License 2.0', 'Apache Software License 2.0'), |
| 60 | + ('MIT', 'MIT'), |
| 61 | + ('BSD', 'BSD'), |
| 62 | + ], |
| 63 | + }, |
| 64 | + { |
| 65 | + 'name': 'use_github_actions', |
| 66 | + 'type': 'selectone', |
| 67 | + 'description': 'Do you want to use Github actions? ', |
| 68 | + 'values': [ |
| 69 | + ('n', 'No'), |
| 70 | + ('y', 'Yes'), |
| 71 | + ], |
| 72 | + }, |
| 73 | + { |
| 74 | + 'name': 'use_asyncio', |
| 75 | + 'type': 'selectone', |
| 76 | + 'description': 'Do you want to use asynchronous libraries? ', |
| 77 | + 'values': [ |
| 78 | + ('n', 'No'), |
| 79 | + ('y', 'Yes'), |
| 80 | + ], |
| 81 | + }, |
| 82 | + ] |
| 83 | + answers = _show_dialog(questions, idx, total) |
| 84 | + return answers |
| 85 | + |
| 86 | + |
| 87 | +def _asset_process_capabilities(idx, total): |
| 88 | + questions = [ |
| 89 | + { |
| 90 | + 'name': 'asset_processing', |
| 91 | + 'type': 'selectmany', |
| 92 | + 'description': 'Asset processing capabilities', |
| 93 | + 'values': [ |
| 94 | + ('subscription_process_capabilities_1of6', 'Purchase Request'), |
| 95 | + ('subscription_process_capabilities_2of6', 'Change Request'), |
| 96 | + ('subscription_process_capabilities_3of6', 'Suspend Request'), |
| 97 | + ('subscription_process_capabilities_4of6', 'Resume Request'), |
| 98 | + ('subscription_process_capabilities_5of6', 'Cancel Request'), |
| 99 | + ('subscription_process_capabilities_6of6', 'Adjustment Request'), |
| 100 | + ], |
| 101 | + }, |
| 102 | + ] |
| 103 | + answers = _show_dialog(questions, idx, total) |
| 104 | + return _gen_cookie_capabilities(answers['asset_processing']) |
| 105 | + |
| 106 | + |
| 107 | +def _asset_validation_capabilities(idx, total): |
| 108 | + questions = [ |
| 109 | + { |
| 110 | + 'name': 'asset_validation', |
| 111 | + 'type': 'selectmany', |
| 112 | + 'description': 'Asset validation capabilities', |
| 113 | + 'values': [ |
| 114 | + ('subscription_validation_capabilities_1of2', 'Purchase Request'), |
| 115 | + ('subscription_validation_capabilities_2of2', 'Change Request'), |
| 116 | + ], |
| 117 | + }, |
| 118 | + ] |
| 119 | + answers = _show_dialog(questions, idx, total) |
| 120 | + return _gen_cookie_capabilities(answers['asset_validation']) |
| 121 | + |
| 122 | + |
| 123 | +def _tier_config_capabilities(idx, total): |
| 124 | + questions = [ |
| 125 | + { |
| 126 | + 'name': 'tierconfig', |
| 127 | + 'type': 'selectmany', |
| 128 | + 'description': 'Tier configuration capabilities', |
| 129 | + 'values': [ |
| 130 | + ('tier_config_process_capabilities_1of2', 'Setup Request Processing'), |
| 131 | + ('tier_config_process_capabilities_2of2', 'Change Request Processing'), |
| 132 | + ('tier_config_validation_capabilities_1of2', 'Setup Request Validation'), |
| 133 | + ('tier_config_validation_capabilities_1of2', 'Change Request Validation'), |
| 134 | + ], |
| 135 | + }, |
| 136 | + ] |
| 137 | + answers = _show_dialog(questions, idx, total) |
| 138 | + return _gen_cookie_capabilities(answers['tierconfig']) |
| 139 | + |
| 140 | + |
| 141 | +def _product_capabilities(idx, total): |
| 142 | + questions = [ |
| 143 | + { |
| 144 | + 'name': 'product', |
| 145 | + 'type': 'selectmany', |
| 146 | + 'description': 'Product capabilities', |
| 147 | + 'values': [ |
| 148 | + ('product_capabilities_1of2', 'Product Action Execution'), |
| 149 | + ('product_capabilities_2of2', 'Product Custom Event'), |
| 150 | + ], |
| 151 | + }, |
| 152 | + ] |
| 153 | + answers = _show_dialog(questions, idx, total) |
| 154 | + return _gen_cookie_capabilities(answers['product']) |
| 155 | + |
| 156 | + |
| 157 | +def _show_dialog(questions, idx, total): |
| 158 | + answers = dialogus( |
| 159 | + questions, |
| 160 | + title=f'Extension Project Configuration ({idx}/{total})', |
| 161 | + confirm='Next', |
| 162 | + ) |
| 163 | + if not answers: |
| 164 | + raise ClickException('Aborted by user input') |
| 165 | + return answers |
| 166 | + |
| 167 | + |
| 168 | +def _gen_cookie_capabilities(answers): |
| 169 | + cookicutter_answers = {} |
| 170 | + if answers: |
| 171 | + for capability in answers: |
| 172 | + cookicutter_answers[capability] = 'y' |
| 173 | + |
| 174 | + return cookicutter_answers |
0 commit comments