11"""Definition of non-processing subcommands."""
22
33from __future__ import annotations
4+ from dataclasses import fields
45from itertools import zip_longest
56from math import ceil
67from shutil import get_terminal_size
78from textwrap import indent , TextWrapper
8- import sys
99import typing
1010
1111import loam .tools
1212import pandas
1313
1414from . import conf , phyvars , __version__
1515from . import stagyydata
16- from .config import CONFIG_FILE , CONFIG_LOCAL
16+ from .config import CONFIG_FILE
1717from ._helpers import baredoc
1818
1919if typing .TYPE_CHECKING :
2020 from typing import (Sequence , Tuple , Optional , Mapping , Callable , Union ,
21- Iterable , Any )
22- from pathlib import Path
21+ Iterable )
22+ from loam . base import Section
2323 from .datatypes import Varf , Varr , Vart
2424
2525
@@ -131,7 +131,8 @@ def var_cmd() -> None:
131131 See :mod:`stagpy.phyvars` where the lists of variables organized by command
132132 are defined.
133133 """
134- print_all = not any (val for _ , val in conf .var .opt_vals_ ())
134+ print_all = not any (getattr (conf .var , fld .name )
135+ for fld in fields (conf .var ))
135136 if print_all or conf .var .field :
136137 print ('field:' )
137138 _layout (phyvars .FIELD , phyvars .FIELD_EXTRA )
@@ -162,22 +163,6 @@ def version_cmd() -> None:
162163 print (f'stagpy version: { __version__ } ' )
163164
164165
165- def report_parsing_problems (
166- parsing_out : Tuple [Any , Sequence [Path ], Sequence [Path ]]) -> None :
167- """Output message about potential parsing problems."""
168- _ , empty , faulty = parsing_out
169- if CONFIG_FILE in empty or CONFIG_FILE in faulty :
170- print ('Unable to read global config file' , CONFIG_FILE ,
171- file = sys .stderr )
172- print ('Please run stagpy config --create' ,
173- sep = '\n ' , end = '\n \n ' , file = sys .stderr )
174- if CONFIG_LOCAL in faulty :
175- print ('Unable to read local config file' , CONFIG_LOCAL ,
176- file = sys .stderr )
177- print ('Please run stagpy config --create_local' ,
178- sep = '\n ' , end = '\n \n ' , file = sys .stderr )
179-
180-
181166def config_pp (subs : Iterable [str ]) -> None :
182167 """Pretty print of configuration options.
183168
@@ -187,11 +172,14 @@ def config_pp(subs: Iterable[str]) -> None:
187172 print ('(c|f): available only as CLI argument/in the config file' ,
188173 end = '\n \n ' )
189174 for sub in subs :
175+ section : Section = getattr (conf , sub )
190176 hlp_lst = []
191- for opt , meta in conf [sub ].defaults_ ():
192- if meta .cmd_arg ^ meta .conf_arg :
193- opt += ' (c)' if meta .cmd_arg else ' (f)'
194- hlp_lst .append ((opt , meta .help ))
177+ for fld in fields (section ):
178+ opt = fld .name
179+ entry = section .meta_ (opt ).entry
180+ if entry .in_cli ^ entry .in_file :
181+ opt += ' (c)' if entry .in_cli else ' (f)'
182+ hlp_lst .append ((opt , entry .doc ))
195183 if hlp_lst :
196184 print (f'{ sub } :' )
197185 _pretty_print (hlp_lst , sep = ' -- ' ,
@@ -206,7 +194,6 @@ def config_cmd() -> None:
206194 conf.config
207195 """
208196 if not (conf .common .config or conf .config .create or
209- conf .config .create_local or conf .config .update or
210- conf .config .edit ):
211- config_pp (conf .sections_ ())
212- loam .tools .config_cmd_handler (conf )
197+ conf .config .update or conf .config .edit ):
198+ config_pp (sec .name for sec in fields (conf ))
199+ loam .tools .config_cmd_handler (conf , conf .config , CONFIG_FILE )
0 commit comments