@@ -14,55 +14,57 @@ def toggle_value(args):
1414def main ():
1515 parser = build_cli_parser ("Send control messages to device" )
1616 parser .add_argument ("-d" , "--device_id" , type = int , required = True , help = "The ID of the device to be controlled" )
17- subparsers = parser .add_subparsers (required = True , dest = "command" , help = "Device command help" )
17+ subparsers = parser .add_subparsers (dest = "command" , help = "Device command help" )
1818
1919 bgscan_p = subparsers .add_parser ("background_scan" , help = "Set background scanning status" )
2020 toggle = bgscan_p .add_mutually_exclusive_group (required = True )
21- group .add_argument ("--on" , action = "store_true" , help = "Turn background scanning on" )
22- group .add_argument ("--off" , action = "store_true" , help = "Turn background scanning off" )
21+ toggle .add_argument ("--on" , action = "store_true" , help = "Turn background scanning on" )
22+ toggle .add_argument ("--off" , action = "store_true" , help = "Turn background scanning off" )
2323
2424 bypass_p = subparsers .add_parser ("bypass" , help = "Set bypass mode" )
2525 toggle = bypass_p .add_mutually_exclusive_group (required = True )
26- group .add_argument ("--on" , action = "store_true" , help = "Enable bypass mode" )
27- group .add_argument ("--off" , action = "store_true" , help = "Disable bypass mode" )
26+ toggle .add_argument ("--on" , action = "store_true" , help = "Enable bypass mode" )
27+ toggle .add_argument ("--off" , action = "store_true" , help = "Disable bypass mode" )
2828
2929 subparsers .add_parser ("delete" , help = "Delete sensor" )
3030 subparsers .add_parser ("uninstall" , help = "Uninstall sensor" )
3131
3232 quarantine_p = subparsers .add_parser ("quarantine" , help = "Set quarantine mode" )
3333 toggle = quarantine_p .add_mutually_exclusive_group (required = True )
34- group .add_argument ("--on" , action = "store_true" , help = "Enable quarantine mode" )
35- group .add_argument ("--off" , action = "store_true" , help = "Disable quarantine mode" )
34+ toggle .add_argument ("--on" , action = "store_true" , help = "Enable quarantine mode" )
35+ toggle .add_argument ("--off" , action = "store_true" , help = "Disable quarantine mode" )
3636
3737 policy_p = subparsers .add_parser ("policy" , help = "Update policy for node" )
3838 policy_p .add_argument ("-p" , "--policy_id" , type = int , required = True , help = "New policy ID to set for node" )
3939
40- sensorv_p = subparses_parser ("sensor_version" , help = "Update sensor version for node" )
40+ sensorv_p = subparsers . add_parser ("sensor_version" , help = "Update sensor version for node" )
4141 sensorv_p .add_argument ("-o" , "--os" , required = True , help = "Operating system for sensor" )
4242 sensorv_p .add_argument ("-V" , "--version" , required = True , help = "Version number of sensor" )
4343
4444 args = parser .parse_args ()
4545 cb = get_cb_psc_object (args )
4646 dev = cb .get_device (args .device_id )
4747
48- if args .command == "background_scan" :
49- dev .background_scan (toggle_value (args ))
50- elif args .command == "bypass" :
51- dev .bypass (toggle_value (args ))
52- elif args .command == "delete" :
53- dev .delete_sensor ()
54- elif args .command == "uninstall" :
55- dev .uninstall_sensor ()
56- elif args .command == "quarantine" :
57- dev .quarantine (toggle_value (args ))
58- elif args .command == "policy" :
59- dev .update_policy (args .policy_id )
60- elif args .command == "sensor_version" :
61- dev .update_sensor_version ({args .os : args .version })
48+ if args .command :
49+ if args .command == "background_scan" :
50+ dev .background_scan (toggle_value (args ))
51+ elif args .command == "bypass" :
52+ dev .bypass (toggle_value (args ))
53+ elif args .command == "delete" :
54+ dev .delete_sensor ()
55+ elif args .command == "uninstall" :
56+ dev .uninstall_sensor ()
57+ elif args .command == "quarantine" :
58+ dev .quarantine (toggle_value (args ))
59+ elif args .command == "policy" :
60+ dev .update_policy (args .policy_id )
61+ elif args .command == "sensor_version" :
62+ dev .update_sensor_version ({args .os : args .version })
63+ else :
64+ raise NotImplementedError ("Unknown command" )
65+ print ("OK" )
6266 else :
63- raise NotImplementedError ("Unknown command" )
64- print ("OK" )
65-
67+ print (dev )
6668
6769if __name__ == "__main__" :
6870 sys .exit (main ())
0 commit comments