Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add disable/enable toggle for device to main menu #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 43 additions & 1 deletion Manager/Sources/RDMUICManager/CLI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,13 @@ class CLI {
4. Add Device
5. Edit Device
6. Delete Device
7. Toggle Device
0. Exit
================
"""

print(menu)
let number = askInput("Please select an option", options: [0, 1, 2, 3, 4, 5, 6])
let number = askInput("Please select an option", options: [0, 1, 2, 3, 4, 5, 6, 7])
print()
switch number {
case 1:
Expand All @@ -100,6 +101,9 @@ class CLI {
case 6:
deleteDevice()
return true
case 7:
toggleDevice()
return true
default:
return false
}
Expand Down Expand Up @@ -720,6 +724,44 @@ class CLI {
}
}

private func toggleDevice() {
clear()
let devices = Device.getAll()
print("=======================")
print("Select Device to Toggle")
print("=======================")
var i = 1
for device in devices {
print("\(i): \(device.name)")
i += 1
}
print("0: Back")
print("=====================")
let index = askInput("Please select an option", options: Array(0...devices.count))
print()
if index == 0 {
clear()
return
}
let device = devices[index - 1]
device.enabled = 1 - device.enabled

do {
try device.save()
clear()
BuildController.global.removeDevice(device: device)
let tmpQueue = Threading.getQueue(name: UUID().uuidString, type: .serial)
tmpQueue.dispatch {
Threading.sleep(seconds: 10.0)
BuildController.global.addDevice(device: device)
Threading.destroyQueue(tmpQueue)
}
print("Device toggled.\n\n")
} catch {
print("Failed to toggle device.\n\n")
}
}

// MARK: - Helper Functions

private func askInput(_ line: String) -> String {
Expand Down