Skip to content

Reference

sample_project

__main__

cli

main(input_str=None, capitalize=False)

Entry point for the application script.

Parameters:

Name Type Description Default
input_str str | None

string to reverse

None
capitalize bool

if true, capitalize letters of input_str

False
Source code in src/sample_project/cli.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@click.group(invoke_without_command=True)
@click.version_option(message="%(version)s", package_name="sample-project")
@click.argument("input_str", required=False)
@click.option("--capitalize", is_flag=True, required=False, help="Capitalize string")
def main(input_str: str | None = None, capitalize: bool = False):
    """Entry point for the application script.

    Args:
        input_str: string to reverse
        capitalize: if true, capitalize letters of input_str
    """
    if input_str is None:
        click.echo("Hello, Sample Project!")
        return

    from .simple import reverse

    result = reverse(input_str)
    if capitalize:
        result = result.upper()

    click.echo(f"{input_str} --reverse{'+capitalize' if capitalize else ''}-> {result}")

simple

reverse(s)

Reverse a given string.

Parameters:

Name Type Description Default
s str

string to reverse.

required

Returns:

Type Description
str

A copy of the given string with characters in reverse order.

Source code in src/sample_project/simple.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
def reverse(s: str) -> str:
    """Reverse a given string.

    Args:
        s: string to reverse.

    Returns:
        A copy of the given string with characters in reverse order.
    """
    return s[::-1]