Skip to content

Commit

Permalink
feat: noop type
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Sep 18, 2024
1 parent ab771a5 commit bc93eb3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/ape/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
skip_confirmation_option,
verbosity_option,
)
from ape.cli.paramtype import JSON, Path
from ape.cli.paramtype import JSON, Noop, Path

__all__ = [
"account_option",
Expand All @@ -45,6 +45,7 @@
"network_option",
"NetworkChoice",
"NetworkOption",
"Noop",
"non_existing_alias_argument",
"output_format_choice",
"output_format_option",
Expand Down
4 changes: 2 additions & 2 deletions src/ape/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
output_format_choice,
)
from ape.cli.commands import ConnectedProviderCommand
from ape.cli.paramtype import JSON
from ape.cli.paramtype import JSON, Noop
from ape.exceptions import Abort, ProjectError
from ape.logging import DEFAULT_LOG_LEVEL, ApeLogger, LogLevel, logger
from ape.utils.basemodel import ManagerAccessMixin
Expand Down Expand Up @@ -88,7 +88,7 @@ def set_level(ctx, param, value):
"expose_value": False,
"help": f"One of {names_str}",
"is_eager": True,
"type": lambda x: x, # Ignores weird typing-issues
"type": Noop(),
}


Expand Down
12 changes: 12 additions & 0 deletions src/ape/cli/paramtype.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from pathlib import Path as PathLibPath
from typing import Any

import click

Expand Down Expand Up @@ -34,3 +35,14 @@ def convert(self, value, param, ctx):
self.fail(f"Invalid JSON string: {err}", param, ctx)

return value # Good already.


class Noop(click.ParamType):
"""
A param-type for ignoring param-types.
Good to use when the multi-type handling
happens already in a callback or in the command itself.
"""

def convert(self, value: Any, param, ctx) -> Any:
return value

0 comments on commit bc93eb3

Please sign in to comment.