feat(projects): 新增Click综合案例示例代码及素材
This commit is contained in:
25
projects/click-cli/basic/echo.py
Normal file
25
projects/click-cli/basic/echo.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import argparse
|
||||
|
||||
|
||||
def echo(name=None):
|
||||
print(f"Hello, {name}!")
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="the argparse usage example",
|
||||
)
|
||||
parser.add_argument(
|
||||
"-n",
|
||||
"--name",
|
||||
dest="name",
|
||||
help="the name pass to echo",
|
||||
default="World",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
echo(name=args.name)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in New Issue
Block a user