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

Better Eol Handling && Install Functionality && Partial Rework of Readme #12

Merged
merged 8 commits into from
May 22, 2024
Prev Previous commit
Next Next commit
Added non functional install command.
WyvernIXTL committed May 22, 2024
commit a43f8252168b24d6e1e9687e076217cb1ee0dfe9
35 changes: 29 additions & 6 deletions installation_instruction/__main__.py
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@

from sys import exit
from os.path import isfile
from subprocess import run

import click

@@ -50,8 +51,20 @@ def get_command(self, ctx, config_file: str) -> click.Command|None:

def callback(**kwargs):
inst = instruction.validate_and_render(kwargs)
click.echo(_make_pretty_print_line_breaks(inst[0]))
exit(0 if not inst[1] else 1)
if inst[1]:
click.echo("Error: " + inst[1])
exit(1)
if ctx.obj["MODE"] == "show":
if ctx.obj["RAW"]:
click.echo(inst[0])
else:
click.echo(_make_pretty_print_line_breaks(inst[0]))
elif ctx.obj["MODE"] == "install":
click.echo("Installation not implemented yet.")


exit(0)


return click.Command(
name=config_file,
@@ -61,14 +74,24 @@ def callback(**kwargs):


@click.command(cls=ConfigReadCommand, help="Shows installation instructions for your specified config file and parameters.")
def show():
pass
@click.option("--raw", is_flag=True, help="Show installation instructions without pretty print.", default=False)
@click.pass_context
def show(ctx, raw):
ctx.obj['MODE'] = "show"
ctx.obj['RAW'] = raw

@click.command(cls=ConfigReadCommand, help="Installs with config and parameters given.")
@click.pass_context
def install(ctx):
ctx.obj['MODE'] = "install"

@click.group()
def main():
pass
@click.pass_context
def main(ctx):
ctx.ensure_object(dict)

main.add_command(show)
main.add_command(install)

if __name__ == "__main__":
main()
8 changes: 8 additions & 0 deletions installation_instruction/helpers.py
Original file line number Diff line number Diff line change
@@ -17,6 +17,14 @@


def _make_pretty_print_line_breaks(string: str) -> str:
"""
Replaces `&& ` with a newline character.

:param string: String to be processed.
:type string: str
:return: String with `&& ` replaced with newline character.
:rtype: str
"""
return re.sub(r"\s?&&\s?", "\n", string, 0, re.S)

def _get_error_message_from_string(string: str) -> str | None: