@@ -6,20 +6,49 @@ def get_env_default(key: str, default, cast_func):
66 return cast_func (os .environ .get (f"BTB_{ key } " , default ))
77
88
9+ def str_to_bool (value ):
10+ if isinstance (value , bool ):
11+ return value
12+ return str (value ).strip ().lower () in {"1" , "true" , "yes" , "y" , "on" }
13+
14+
915def main ():
16+ gradio_parent = argparse .ArgumentParser (add_help = False )
17+ gradio_parent .add_argument (
18+ "--share" ,
19+ action = "store_true" ,
20+ default = get_env_default ("SHARE" , False , str_to_bool ),
21+ help = "Share Gradio app publicly (tunnel). Defaults to False." ,
22+ )
23+ gradio_parent .add_argument (
24+ "--server_name" ,
25+ type = str ,
26+ default = os .environ .get ("BTB_SERVER_NAME" , "127.0.0.1" ),
27+ help = 'Server name for Gradio. Defaults to env "BTB_SERVER_NAME" or 127.0.0.1.' ,
28+ )
29+ gradio_parent .add_argument (
30+ "--port" ,
31+ type = int ,
32+ default = int (
33+ os .environ .get ("BTB_PORT" , os .environ .get ("GRADIO_SERVER_PORT" , 7860 ))
34+ ),
35+ help = 'Server port for Gradio. Defaults to env "BTB_PORT"/"GRADIO_SERVER_PORT" or 7860.' ,
36+ )
37+
1038 parser = argparse .ArgumentParser (
1139 description = (
1240 "BiliTickerBuy\n \n "
1341 "Use `btb buy` to buy tickets directly in the command line."
1442 "Run `btb` without arguments to open the UI."
43+ "Run `btb buy -h` for `btb buy` detailed options."
1544 ),
1645 epilog = (
1746 "Examples:\n "
1847 " btb buy tickets.json\n "
1948 " btb buy tickets.json --interval 500\n \n "
20- "Run `btb buy -h` for detailed options."
2149 ),
2250 formatter_class = argparse .RawTextHelpFormatter ,
51+ parents = [gradio_parent ],
2352 )
2453 subparsers = parser .add_subparsers (
2554 dest = "command" ,
@@ -30,6 +59,7 @@ def main():
3059 buy_parser = subparsers .add_parser (
3160 "buy" ,
3261 help = "Buy tickets directly in the command line" ,
62+ parents = [gradio_parent ],
3363 )
3464 # ===== Buy Core =====
3565 buy_core = buy_parser .add_argument_group ("Buy Core Options" )
0 commit comments