Skip to content

Add argument and option#

Open your command file scli/commands/your_command.py and paste below code.

# scli/commands/your_command.py

from scli.commands.base import BaseCommand
from scli.utils import argument
from scli.utils import option


class Command(BaseCommand):
    name = "your_command"
    description = "A simple description"
    help = """
    A useful help message
    """

    arguments = [
        argument(
            name="name",
            description="Argument name",
        ),
    ]

    options = [
        option(
            long_name="create",
            short_name="c",
            description="Check option",
            flag=True,
        )
    ]

    def handle(self):
        name = self.argument("name")
        check = self.option("create")
        if check:
            self.comment("User with name {} created.".format(name))
        else:
            self.comment("User with name {} doesn't created.".format(name))

Command

python -m scli your_command ozcan --create
# or
python -m scli your_command ozcan -c

Output

User with name ozcan created.
Back to top