diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..70d6a07 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,18 @@ +#how the project is built +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +#project's metadata +[project] +name = "githelp" +version = "0.1.0" +description = "example CLI using Click." +authors = [{ name = "Jimmy Zhang", email = "jimmy_zhang@uri.edu" }] +readme = "README.md" +requires-python = ">=3.9" +dependencies = ["click>=8.1"] + +#this creates the 'githelp' command +[project.scripts] +githelp = "githelp.cli:main" \ No newline at end of file diff --git a/src/githelp/_init_.py b/src/githelp/_init_.py new file mode 100644 index 0000000..469e977 --- /dev/null +++ b/src/githelp/_init_.py @@ -0,0 +1,2 @@ +__all__ = ["__version__"] +__version__ = "0.1.0" \ No newline at end of file diff --git a/src/githelp/cli.py b/src/githelp/cli.py new file mode 100644 index 0000000..11c6c9c --- /dev/null +++ b/src/githelp/cli.py @@ -0,0 +1,19 @@ +#import the click library for the building cli interfaces +import click +#import the inner function that actually builds the greeting text +#keynote ".greater" is a relative import not an absolute. +from .greeter import make_greeting + +#declare the click command +#the text in help show up in the githelp --help +@click.command(help="Say hello from githelp.") +#option "--name is define" and "-n" for short +#default= World if user didnt provide a name +#show default flag is set to false so it doesnt display in option +@click.option("--name", "-n", default="World", show_default=False, help="Who to greet.") +#here there is a boolean flag pair --shout/--no-shout" +@click.option("--shout/--no-shout", default=False, show_default=False, help="End with an exclamation mark.") +#click auto parse the value +def main(name: str, shout: bool) -> None: + #call the inner function to build the message, then print it to stdout + click.echo(make_greeting(name, shout)) \ No newline at end of file diff --git a/src/githelp/greeter.py b/src/githelp/greeter.py new file mode 100644 index 0000000..d4a4321 --- /dev/null +++ b/src/githelp/greeter.py @@ -0,0 +1,6 @@ +def make_greeting(name, shout = False): + if(shout): + suffix = "!" + else: + suffix = "." + return f"Hello, {name}{suffix}" \ No newline at end of file