feat: add __main__ function with generic config retrieval
This commit is contained in:
30
src/komconfig/__main__.py
Normal file
30
src/komconfig/__main__.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import argparse
|
||||
from src.komconfig import KomConfig
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Retrieve configuration values.")
|
||||
parser.add_argument("key", type=str, help="The configuration key to retrieve.")
|
||||
args = parser.parse_args()
|
||||
|
||||
config = KomConfig()
|
||||
|
||||
try:
|
||||
config_dict = config.dict()
|
||||
if isinstance(config_dict, dict):
|
||||
value = config_dict.get(args.key, None)
|
||||
if value is None:
|
||||
print(f"Key '{args.key}' not found in the configuration.")
|
||||
else:
|
||||
try:
|
||||
print(str(value))
|
||||
except Exception:
|
||||
print(repr(value))
|
||||
else:
|
||||
print("Configuration data is not in dictionary format.")
|
||||
except Exception as e:
|
||||
print(f"Error retrieving key '{args.key}': {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user