Skip to content

Commit 624dc96

Browse files
committed
Add CLI spec for IntEtc
1 parent 3fb8cf5 commit 624dc96

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/julia/options.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,26 @@ def __init__(self, name, *, etc={}):
4949
def __set__(self, instance, value):
5050
if instance is None:
5151
raise AttributeError(self.name)
52-
elif value in {None, *self.default} or isinstance(value, int):
52+
elif value in self.default or isinstance(value, int):
5353
setattr(instance, self.dataname, value)
5454
else:
55-
part = f" or {self.default}" if self.default else ""
55+
if self.default:
56+
part = " or " + " ".join(map(str, self.default))
57+
else:
58+
part = ""
5659
raise ValueError(
5760
f"Option {self.name} only accepts integers{part}. Got: {value}"
5861
)
5962

6063
def _domain(self):
6164
return {int, *self.default}
6265

66+
def cli_argument_spec(self):
67+
return dict(
68+
super(IntEtc, self).cli_argument_spec(),
69+
choices=list(self.default) + ["1", "2", "3", "..."],
70+
)
71+
6372

6473
class Choices(OptionDescriptor):
6574
def __init__(self, name, choicemap, default=None):

0 commit comments

Comments
 (0)