Skip to content

Commit 1e429d1

Browse files
committed
start on MULTI_ parameters
These will be the parameters typically used for direct access in files (no shortcuts or anything)
1 parent 6e7c091 commit 1e429d1

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

paths_cli/parameters.py

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def clicked(self, required=False):
1515
# we'll use tests of the -h option in the .travis.yml to ensure that the
1616
# .clicked methods work
1717

18+
HELP_MULTIPLE = "; may be used more than once"
19+
1820
class Option(AbstractParameter):
1921
def clicked(self, required=False): # no-cov
2022
return click.option(*self.args, **self.kwargs, required=required)
@@ -56,12 +58,23 @@ def get(self, name):
5658

5759

5860
class OPSStorageLoadNames(AbstractLoader):
61+
"""Simple loader that expects its input to be a name or index.
62+
"""
5963
def __init__(self, param, store):
6064
super(OPSStorageLoadNames, self).__init__(param)
6165
self.store = store
6266

6367
def get(self, storage, names):
64-
return [getattr(storage, self.store)[name] for name in names]
68+
int_corrected = []
69+
for name in names:
70+
try:
71+
name = int(name)
72+
except ValueError:
73+
pass
74+
int_corrected.append(name)
75+
76+
return [getattr(storage, self.store)[name]
77+
for name in int_corrected]
6578

6679

6780
class OPSStorageLoadSingle(AbstractLoader):
@@ -181,16 +194,47 @@ def init_snap_fallback(parameter, storage, name):
181194

182195
CVS = OPSStorageLoadNames(
183196
param=Option('--cv', type=str, multiple=True,
184-
help='name of CV; may select more than once'),
197+
help='name of CV' + HELP_MULTIPLE),
185198
store='cvs'
186199
)
187200

201+
MULTI_VOLUME = OPSStorageLoadNames(
202+
param=Option('--volume', type=str, multiple=True,
203+
help='name or index of volume' + HELP_MULTIPLE),
204+
store='volumes'
205+
) #TODO:unit tests
206+
207+
MULTI_ENGINE = OPSStorageLoadNames(
208+
param=Option('--engine', type=str, multiple=True,
209+
help='name or index of engine' + HELP_MULTIPLE),
210+
store='engines'
211+
)
212+
213+
188214
STATES = OPSStorageLoadNames(
189-
param=Option('-s', '--state', multiple=True,
190-
help='name of state; may select more than once'),
215+
param=Option('-s', '--state', type=str, multiple=True,
216+
help='name of state' + HELP_MULTIPLE),
191217
store='volumes'
192218
)
193219

220+
MULTI_TAG = OPSStorageLoadNames(
221+
param=Option('--tag', type=str, multiple=True,
222+
help='tag for object' + HELP_MULTIPLE),
223+
store='tags'
224+
) # TODO: unit testsA
225+
226+
MULTI_NETWORK = OPSStorageLoadNames(
227+
param=Option('--network', type=str, multiple=True,
228+
help='name or index of network' + HELP_MULTIPLE),
229+
store='networks'
230+
) # TODO: unit tests
231+
232+
MULTI_SCHEME = OPSStorageLoadNames(
233+
param=Option('--scheme', type=str, multiple=True,
234+
help='name or index of move scheme' + HELP_MULTIPLE),
235+
store='schemes'
236+
) # TODO: unit tests
237+
194238
INPUT_FILE = StorageLoader(
195239
param=Argument('input_file',
196240
type=click.Path(exists=True, readable=True)),

0 commit comments

Comments
 (0)