Skip to content

Commit

Permalink
♻️ refactor: move parse_arguments definition after its calling
Browse files Browse the repository at this point in the history
  • Loading branch information
welpo committed Jan 28, 2024
1 parent 24c4756 commit 4cbb4bd
Showing 1 changed file with 27 additions and 28 deletions.
55 changes: 27 additions & 28 deletions doteki/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,33 @@ def main() -> None:
insert_credits(config, args.input)


def parse_arguments() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="dōteki: A tool to update README sections with plugins defined in a TOML configuration",
add_help=False,
epilog="Example: doteki -c config.toml -i README.md",
)
parser.add_argument(
"-h",
"--help",
action="help",
help="Show this help message and exit.",
)
parser.add_argument(
"-c",
"--config",
default="doteki.toml",
help="Path to the TOML configuration file. Default: doteki.toml",
)
parser.add_argument(
"-i",
"--input",
default="README.md",
help="Path to the README file. Default: README.md",
)
return parser.parse_args()


def exit_if_file_missing(file_path: str) -> None:
if not os.path.exists(file_path):
logging.error(f"File not found: {file_path}")
Expand Down Expand Up @@ -217,34 +244,6 @@ def write_file_content(filepath: str, content: str) -> None:
logging.error(f"An error occurred while writing to {filepath}: {e}")


def parse_arguments() -> argparse.Namespace:
parser = argparse.ArgumentParser(
description="dōteki: A tool to update README sections with plugins defined in a TOML configuration",
add_help=False,
epilog="Example: doteki -c config.toml -i README.md",
)
parser.add_argument(
"-h",
"--help",
action="help",
default=argparse.SUPPRESS,
help="Show this help message and exit.",
)
parser.add_argument(
"-c",
"--config",
default="doteki.toml",
help="Path to the TOML configuration file. Default: doteki.toml",
)
parser.add_argument(
"-i",
"--input",
default="README.md",
help="Path to the README file. Default: README.md",
)
return parser.parse_args()


def insert_credits(config: dict[str, Any], readme_path: str) -> None:
credits = config.get("credits", DEFAULT_CREDITS)
readme_content = read_file_content(readme_path)
Expand Down

0 comments on commit 4cbb4bd

Please sign in to comment.