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

Final changes for v1.1.0 #16

Merged
merged 8 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@

github.com
.idea/codeStyles/codeStyleConfig.xml

build
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/general/General.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func HexTo2Places(h string) string {
// about Lux

// BuildName is the name of the build
const BuildName = "v1.0.0"
const BuildName = "v1.1.0"
// BuildNo is the build number
const BuildNo = 0
const BuildNo = 1
// GHRepo is the repo url
const GHRepo = "https://github.com/bandev/lux"
// License is the license
Expand Down
29 changes: 18 additions & 11 deletions commands/devices/Entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
package devices

import (
"flag"
"github.com/bandev/lux/api/general"
"github.com/bandev/lux/api/keymanager"
"github.com/fatih/color"
"os"
)

// Entry function is the entry point for
Expand All @@ -32,9 +33,17 @@ func Entry(args []string) {
// If lux is not setup, throw an error
if !keymanager.PrintLuxHasAPIKey() { return }

// Determine the command the user wants
var command string
if len(args) > 2 { command = args[2] } else { command = "simple" }
// Use flags package to parse flags
// provided to the sub command
devicesCmd := flag.NewFlagSet("devices",flag.ExitOnError)
expert := devicesCmd.Bool("expert", false, "show more technical device details")
limit := devicesCmd.Int("limit", 0, "add a limit to the number of devices shown")

// Parse flags & handle errors
err := devicesCmd.Parse(os.Args[2:])
if err != nil {
return
}

// Create a new connection struct
var c general.Connection
Expand All @@ -45,12 +54,10 @@ func Entry(args []string) {
var devices Devices
devices.Get(c)

// Device on the command to run
if command == "complex" {
devices.ComplexList()
}else if command == "simple" {
devices.SimpleList()
}else {
general.PrintHeading("Unknown command '" + command + "' for devices", color.FgRed)
// Decide on the command to run
if *expert {
devices.ComplexList(*limit)
} else {
devices.SimpleList(*limit)
}
}
28 changes: 24 additions & 4 deletions commands/devices/Structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,18 @@ func (d *Devices) Get(c general.Connection) {
// the terminal, the list includes the name,
// model and if the device is controllable or
// not by this app.
func (d *Devices) SimpleList() {
for i := 0; i < len(d.Data.Devices); i++ {
func (d *Devices) SimpleList(limit int) {

var iterations int
var devices = len(d.Data.Devices)

if limit != 0 && limit <= devices {
iterations = limit
} else {
iterations = devices
}

for i := 0; i < iterations; i++ {
var device = d.Data.Devices[i]
general.PrintHeading("DEVICE " + strconv.Itoa(i), color.FgWhite)
general.PrintStringParagraph("Name:", device.Name, color.FgWhite)
Expand All @@ -85,8 +95,18 @@ func (d *Devices) SimpleList() {
// nice but complex way. It pretty much dumps
// everything the app knows about their device
// to the console.
func (d *Devices) ComplexList() {
for i := 0; i < len(d.Data.Devices); i++ {
func (d *Devices) ComplexList(limit int) {

var iterations int
var devices = len(d.Data.Devices)

if limit != 0 && limit <= devices {
iterations = limit
} else {
iterations = devices
}

for i := 0; i < iterations; i++ {
var device = d.Data.Devices[i]
general.PrintHeading("DEVICE " + strconv.Itoa(i), color.FgWhite)
general.PrintStringParagraph("MAC Address:", device.MAC, color.FgWhite)
Expand Down