Skip to content

Commit 695ed8b

Browse files
committed
Add support for --table option in contents
1 parent 7149565 commit 695ed8b

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

paths_cli/commands/contents.py

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,45 @@
11
import click
22
from paths_cli.parameters import INPUT_FILE
33

4+
UNNAMED_SECTIONS = {
5+
'Steps': lambda storage: storage.steps,
6+
'Move Changes': lambda storage: storage.movechanges,
7+
'SampleSets': lambda storage: storage.samplesets,
8+
'Trajectories': lambda storage: storage.trajectories,
9+
'Snapshots': lambda storage: storage.snapshots
10+
}
11+
412
@click.command(
513
'contents',
614
short_help="list named objects from an OPS .nc file",
715
)
816
@INPUT_FILE.clicked(required=True)
9-
def contents(input_file):
17+
@click.option('--table', type=str, required=False,
18+
help="table to show results from")
19+
def contents(input_file, table):
1020
"""List the names of named objects in an OPS .nc file.
1121
1222
This is particularly useful when getting ready to use one of simulation
1323
scripts (i.e., to identify exactly how a state or engine is named.)
1424
"""
1525
storage = INPUT_FILE.get(input_file)
1626
print(storage)
27+
if table is None:
28+
report_all_tables(storage)
29+
else:
30+
table_attr = table.lower()
31+
try:
32+
store = getattr(storage, table_attr)
33+
except AttributeError:
34+
print("This needs to raise a good error; bad table name")
35+
else:
36+
if table_attr in UNNAMED_SECTIONS:
37+
print(get_unnamed_section_string(table_attr, store))
38+
else:
39+
print(get_section_string_nameable(table_attr, store,
40+
_get_named_namedobj))
41+
42+
def report_all_tables(storage):
1743
store_section_mapping = {
1844
'CVs': storage.cvs, 'Volumes': storage.volumes,
1945
'Engines': storage.engines, 'Networks': storage.networks,
@@ -26,12 +52,8 @@ def contents(input_file):
2652
print(get_section_string_nameable('Tags', storage.tags, _get_named_tags))
2753

2854
print("\nData Objects:")
29-
unnamed_sections = {
30-
'Steps': storage.steps, 'Move Changes': storage.movechanges,
31-
'SampleSets': storage.samplesets,
32-
'Trajectories': storage.trajectories, 'Snapshots': storage.snapshots
33-
}
34-
for section, store in unnamed_sections.items():
55+
for section, store_func in UNNAMED_SECTIONS.items():
56+
store = store_func(storage)
3557
print(get_unnamed_section_string(section, store))
3658

3759
def _item_or_items(count):

0 commit comments

Comments
 (0)