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

Add help messages and simplify 'dev' option #128

Merged
merged 1 commit into from
Dec 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions robyn/argument_parser.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
import argparse


class ArgumentParser(argparse.ArgumentParser):
def __init__(self):
self.parser = argparse.ArgumentParser(description="Robyn, a fast async web framework with a rust runtime.")
self.parser.add_argument('--processes', type=int, default=1, required=False)
self.parser.add_argument('--workers', type=int, default=1, required=False)
self.parser.add_argument('--dev', default=False, type=lambda x: (str(x).lower() == 'true'))
self.parser = argparse.ArgumentParser(
description="Robyn, a fast async web framework with a rust runtime."
)
self.parser.add_argument(
"--processes",
type=int,
default=1,
required=False,
help="Choose the number of processes. [Default: 1]",
)
self.parser.add_argument(
"--workers",
type=int,
default=1,
required=False,
help="Choose the number of workers. [Default: 1]",
)
self.parser.add_argument(
"--dev",
dest="dev",
action="store_true",
Comment on lines +25 to +26
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for contributing. But can you tell me what these flags do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! So, the change here is removing the dev in the arguments and add in the options. The reason is that no one will ever do --dev=false as it's the default.

This change just makes --dev standalone possible. The action argument on the highlighted above makes it store a True value on the dev variable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, alright. Makes sense. Thank you! :D

default=False,
help="Development mode. It restarts the server based on file changes.",
)

self.args = self.parser.parse_args()

def num_processes(self):
return self.args.processes

Expand All @@ -16,7 +38,6 @@ def workers(self):

def is_dev(self):
_is_dev = self.args.dev
if _is_dev and ( self.num_processes() != 1 or self.workers() != 1 ):
if _is_dev and (self.num_processes() != 1 or self.workers() != 1):
raise Exception("--processes and --workers shouldn't be used with --dev")
return _is_dev