forked from khuyentran1401/Data-science
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dbc7060
commit 535a2fc
Showing
7 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import argparse | ||
|
||
def greeting(name: str): | ||
print(f'Hello {name}!') | ||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser('Greet users') | ||
parser.add_argument('name', type=str) | ||
args = parser.parse_args() | ||
|
||
if args.name: | ||
greeting(args.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typer | ||
|
||
def greeting(name: str = typer.Argument('Khuyen', help='Name of user')): | ||
"""Say hello to users""" | ||
|
||
print(f'Hello {name}!') | ||
|
||
|
||
if __name__ == '__main__': | ||
typer.run(greeting) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import typer | ||
|
||
app = typer.Typer() | ||
|
||
@app.command() | ||
def greeting(name: str): | ||
"""Say hello to users""" | ||
|
||
print(f'Hello {name}!') | ||
|
||
@app.command() | ||
def say_bye(name: str): | ||
"""Say bye to users""" | ||
|
||
print(f'Good bye {name}') | ||
|
||
if __name__ == '__main__': | ||
app() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import typer | ||
|
||
def greeting(name: str): | ||
"""Function to say hello to users""" | ||
|
||
print(f'Hello {name}!') | ||
|
||
if __name__ == '__main__': | ||
typer.run(greeting) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import typer | ||
|
||
def greeting(name: str = typer.Argument(..., help='Username'), | ||
is_user: bool = typer.Option(..., help='Whether user has signed up')): | ||
"""Say hello to users""" | ||
if is_user: | ||
print(f'Hello {name}!') | ||
else: | ||
print(f"You haven't signed up yet. Please sign up to continue.") | ||
|
||
|
||
if __name__ == '__main__': | ||
typer.run(greeting) |
13 changes: 13 additions & 0 deletions
13
terminal/typer_examples/option_example_no_default_value.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import typer | ||
|
||
def greeting(name: str = typer.Argument(..., help='Username'), | ||
is_user: bool = typer.Option(..., help='Whether user has signed up')): | ||
"""Say hello to users""" | ||
if is_user: | ||
print(f'Hello {name}!') | ||
else: | ||
print(f"You haven't signed up yet. Please sign up to continue.") | ||
|
||
|
||
if __name__ == '__main__': | ||
typer.run(greeting) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import typer | ||
|
||
def greeting(name: str = typer.Argument('Khuyen', help='Name of user')): | ||
"""Say hello to users""" | ||
|
||
print(f'Hello {name}!') | ||
|
||
|
||
if __name__ == '__main__': | ||
typer.run(greeting) |