Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TOML Config File Feature #13

Closed
wants to merge 9 commits into from
Closed
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions convertTxtToHtml/configFeature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import argparse
import toml

def parse_command_line_args():
parser = argparse.ArgumentParser(description="CLI Application with TOML Config File Support")
parser.add_argument("-c", "--config", help="Path to the TOML configuration file")
return parser.parse_args()

def load_config_file(config_file_path):
try:
with open(config_file_path, "r") as file:
config_data = toml.load(file)
return config_data
except FileNotFoundError:
print(f"Config file '{config_file_path}' not found.")
exit(1)
except toml.TomlDecodeError:
print(f"Error parsing TOML in '{config_file_path}'. Make sure it's valid TOML.")
exit(1)

def main():
args = parse_command_line_args()
config_data = load_config_file(args.config) if args.config else {}

default_config = {
"output": "./build",
"stylesheet": "https://cdn.jsdelivr.net/npm/water.css@2/out/water.css",
"lang": "en",
}

config = {**default_config, **config_data}

output_dir = config["output"]
stylesheet_url = config["stylesheet"]
lang = config["lang"]

print(f"Output Directory: {output_dir}")
print(f"Stylesheet URL: {stylesheet_url}")
print(f"Language: {lang}")

if __name__ == "__main__":
main()