11import click
22from 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 ("\n Data 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
3759def _item_or_items (count ):
0 commit comments