Add argparse
This commit is contained in:
parent
eb3dc4338f
commit
ee442e01b2
1 changed files with 15 additions and 2 deletions
17
main.py
17
main.py
|
@ -1,6 +1,9 @@
|
|||
import argparse
|
||||
import sys
|
||||
|
||||
import bluetooth
|
||||
import bluetooth #PyBluez
|
||||
|
||||
version = '0.0.0'
|
||||
|
||||
def bluetooth_scan():
|
||||
print('Discovering Bluetooth Devices...')
|
||||
|
@ -12,7 +15,17 @@ def bluetooth_scan():
|
|||
print(f'{device[0]}\t{device[1]}')
|
||||
|
||||
def main():
|
||||
bluetooth_scan()
|
||||
argparser = argparse.ArgumentParser(description='CarPI CLI.')
|
||||
|
||||
# Create actions
|
||||
actions = argparser.add_subparsers(title='actions', required=True)
|
||||
action_list = actions.add_parser('list', help='list nearby bluetooth devices')
|
||||
action_list.set_defaults(func=bluetooth_scan)
|
||||
action_connect = actions.add_parser('connect', help='connect to a bluetooth device')
|
||||
|
||||
args = argparser.parse_args()
|
||||
print(args)
|
||||
args.func()
|
||||
|
||||
if (__name__ == "__main__"):
|
||||
sys.exit(main())
|
Loading…
Add table
Reference in a new issue