]> git.proxmox.com Git - ceph.git/blob - ceph/src/arrow/dev/archery/archery/utils/cli.py
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / dev / archery / archery / utils / cli.py
1 # Licensed to the Apache Software Foundation (ASF) under one
2 # or more contributor license agreements. See the NOTICE file
3 # distributed with this work for additional information
4 # regarding copyright ownership. The ASF licenses this file
5 # to you under the Apache License, Version 2.0 (the
6 # "License"); you may not use this file except in compliance
7 # with the License. You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing,
12 # software distributed under the License is distributed on an
13 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 # KIND, either express or implied. See the License for the
15 # specific language governing permissions and limitations
16 # under the License.
17
18 import importlib
19
20 import click
21
22 from .source import ArrowSources, InvalidArrowSource
23
24
25 class ArrowBool(click.types.BoolParamType):
26 """
27 ArrowBool supports the 'ON' and 'OFF' values on top of the values
28 supported by BoolParamType. This is convenient to port script which exports
29 CMake options variables.
30 """
31 name = "boolean"
32
33 def convert(self, value, param, ctx):
34 if isinstance(value, str):
35 lowered = value.lower()
36 if lowered == "on":
37 return True
38 elif lowered == "off":
39 return False
40
41 return super().convert(value, param, ctx)
42
43
44 def validate_arrow_sources(ctx, param, src):
45 """
46 Ensure a directory contains Arrow cpp sources.
47 """
48 try:
49 return ArrowSources.find(src)
50 except InvalidArrowSource as e:
51 raise click.BadParameter(str(e))
52
53
54 def add_optional_command(name, module, function, parent):
55 try:
56 module = importlib.import_module(module, package="archery")
57 command = getattr(module, function)
58 except ImportError as exc:
59 error_message = exc.name
60
61 @parent.command(
62 name,
63 context_settings={
64 "allow_extra_args": True,
65 "ignore_unknown_options": True,
66 }
67 )
68 def command():
69 raise click.ClickException(
70 f"Couldn't import command `{name}` due to {error_message}"
71 )
72 else:
73 parent.add_command(command)