Conditions | 7 |
Total Lines | 96 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | # -*- coding: utf-8 -*- |
||
73 | @click.command(context_settings=dict(help_option_names=[u'-h', u'--help'])) |
||
74 | @click.version_option(__version__, u'-V', u'--version', message=version_msg()) |
||
75 | @click.argument(u'template') |
||
76 | @click.argument(u'extra_context', nargs=-1, callback=validate_extra_context) |
||
77 | @click.option( |
||
78 | u'--no-input', is_flag=True, |
||
79 | help=u'Do not prompt for parameters and only use cookiecutter.json ' |
||
80 | u'file content', |
||
81 | ) |
||
82 | @click.option( |
||
83 | u'-c', u'--checkout', |
||
84 | help=u'branch, tag or commit to checkout after git clone', |
||
85 | ) |
||
86 | @click.option( |
||
87 | '-v', '--verbose', |
||
88 | is_flag=True, help='Print debug information', default=False |
||
89 | ) |
||
90 | @click.option( |
||
91 | u'--replay', is_flag=True, |
||
92 | help=u'Do not prompt for parameters and only use information entered ' |
||
93 | u'previously', |
||
94 | ) |
||
95 | @click.option( |
||
96 | u'-f', u'--overwrite-if-exists', is_flag=True, |
||
97 | help=u'Overwrite the contents of the output directory if it already exists' |
||
98 | ) |
||
99 | @click.option( |
||
100 | u'-o', u'--output-dir', default='.', type=click.Path(), |
||
101 | help=u'Where to output the generated project dir into' |
||
102 | ) |
||
103 | @click.option( |
||
104 | u'--config-file', type=click.Path(), default=None, |
||
105 | help=u'User configuration file' |
||
106 | ) |
||
107 | @click.option( |
||
108 | u'--default-config', is_flag=True, |
||
109 | help=u'Do not load a config file. Use the defaults instead' |
||
110 | ) |
||
111 | @click.option( |
||
112 | u'--debug-file', type=click.Path(), default=None, |
||
113 | help=u'File to be used as a stream for DEBUG logging', |
||
114 | ) |
||
115 | def main( |
||
116 | template, extra_context, no_input, checkout, verbose, |
||
117 | replay, overwrite_if_exists, output_dir, config_file, |
||
118 | default_config, debug_file): |
||
119 | """Create a project from a Cookiecutter project template (TEMPLATE). |
||
120 | |||
121 | Cookiecutter is free and open source software, developed and managed by |
||
122 | volunteers. If you would like to help out or fund the project, please get |
||
123 | in touch at https://github.com/audreyr/cookiecutter. |
||
124 | """ |
||
125 | |||
126 | # If you _need_ to support a local template in a directory |
||
127 | # called 'help', use a qualified path to the directory. |
||
128 | if template == u'help': |
||
129 | click.echo(click.get_current_context().get_help()) |
||
130 | sys.exit(0) |
||
131 | if template == u'installed' or template == u'i': |
||
132 | list_installed_templates(default_config, config_file) |
||
133 | sys.exit(0) |
||
134 | |||
135 | configure_logger( |
||
136 | stream_level='DEBUG' if verbose else 'INFO', |
||
137 | debug_file=debug_file, |
||
138 | ) |
||
139 | |||
140 | try: |
||
141 | cookiecutter( |
||
142 | template, checkout, no_input, |
||
143 | extra_context=extra_context, |
||
144 | replay=replay, |
||
145 | overwrite_if_exists=overwrite_if_exists, |
||
146 | output_dir=output_dir, |
||
147 | config_file=config_file, |
||
148 | default_config=default_config, |
||
149 | ) |
||
150 | except (OutputDirExistsException, |
||
151 | InvalidModeException, |
||
152 | FailedHookException, |
||
153 | UnknownExtension, |
||
154 | RepositoryNotFound, |
||
155 | RepositoryCloneFailed) as e: |
||
156 | click.echo(e) |
||
157 | sys.exit(1) |
||
158 | except UndefinedVariableInTemplate as undefined_err: |
||
159 | click.echo('{}'.format(undefined_err.message)) |
||
160 | click.echo('Error message: {}'.format(undefined_err.error.message)) |
||
161 | |||
162 | context_str = json.dumps( |
||
163 | undefined_err.context, |
||
164 | indent=4, |
||
165 | sort_keys=True |
||
166 | ) |
||
167 | click.echo('Context: {}'.format(context_str)) |
||
168 | sys.exit(1) |
||
169 | |||
173 |