-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reuse
prepend_text
and append_text
in `verdi computer/code duplic…
…ate` (#3788) This required adding a new `ContextualDefaultOption` class to get a default callable that also receives the context. Moreover, a bug was fixed in the function that prompts for the `prepend/append_text`, as if the file was not touched/modified, instead of reusing the text provided in input, an empty text was used instead. Co-authored-by: ConradJohnston <40352432+ConradJohnston@users.noreply.github.com>
- Loading branch information
1 parent
67d4504
commit d44dcbd
Showing
7 changed files
with
48 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# -*- coding: utf-8 -*- | ||
########################################################################### | ||
# Copyright (c), The AiiDA team. All rights reserved. # | ||
# This file is part of the AiiDA code. # | ||
# # | ||
# The code is hosted on GitHub at /~https://github.com/aiidateam/aiida-core # | ||
# For further information on the license, see the LICENSE.txt file # | ||
# For further information please visit http://www.aiida.net # | ||
########################################################################### | ||
""" | ||
.. py:module::contextualdefault | ||
:synopsis: Tools for options which allow for a default callable that needs | ||
also the context ctx | ||
""" | ||
|
||
import click | ||
|
||
|
||
class ContextualDefaultOption(click.Option): | ||
"""A class that extends click.Option allowing to define a default callable | ||
that also get the context ctx as a parameter. | ||
""" | ||
|
||
def __init__(self, *args, contextual_default=None, **kwargs): | ||
self._contextual_default = contextual_default | ||
super().__init__(*args, **kwargs) | ||
|
||
def get_default(self, ctx): | ||
"""If a contextual default is defined, use it, otherwise behave normally.""" | ||
if self._contextual_default is None: | ||
return super().get_default(ctx) | ||
return self._contextual_default(ctx) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters