Compare commits

...

7 Commits

9 changed files with 95 additions and 8 deletions

1
.lumerc.sample Normal file
View File

@ -0,0 +1 @@
AccessToken = "token"

15
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "${workspaceFolder}/cmd/lume"
}
]
}

23
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,23 @@
{
"version": "2.0.0",
"type": "shell",
"command": "go",
"cwd": "${workspaceFolder}",
"tasks": [
{
"label": "install",
"args": ["install", "-v", "./..."],
"group": "build",
},
{
"label": "run",
"args": ["run", "${file}"],
"group": "build",
},
{
"label": "test",
"args": ["test", "-v", "./..."],
"group": "test",
},
],
}

View File

@ -17,7 +17,7 @@ func init() {
RegisterCommand(cmdName, Command{ RegisterCommand(cmdName, Command{
Func: LsCmd, Func: LsCmd,
Flags: fs, Flags: fs,
Use: "[--selector=<selector>", Use: "[--selector=<selector>]",
Short: "List the lights", Short: "List the lights",
}) })
} }

BIN
cmd/lume/__debug_bin Normal file

Binary file not shown.

View File

@ -6,18 +6,27 @@ import (
"os" "os"
"path" "path"
"git.kill0.net/chill9/lume" lifx "git.kill0.net/chill9/lume"
lumecmd "git.kill0.net/chill9/lume/cmd" lumecmd "git.kill0.net/chill9/lume/cmd"
"github.com/BurntSushi/toml" "github.com/BurntSushi/toml"
"golang.org/x/sys/windows"
) )
const lumercFile = ".lumerc" const lumercFile = ".lumerc"
func main() { func main() {
var originalMode uint32
stdout := windows.Handle(os.Stdout.Fd())
windows.GetConsoleMode(stdout, &originalMode)
windows.SetConsoleMode(stdout, originalMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
defer windows.SetConsoleMode(stdout, originalMode)
var config lumecmd.Config var config lumecmd.Config
homeDir, err := os.UserHomeDir() config = loadConfig()
_, err = toml.DecodeFile(path.Join(homeDir, lumercFile), &config)
if os.IsNotExist(err) { if config.AccessToken == "" {
config.AccessToken = os.Getenv("LIFX_ACCESS_TOKEN") config.AccessToken = os.Getenv("LIFX_ACCESS_TOKEN")
} }
@ -39,7 +48,7 @@ func main() {
cmd, ok := lumecmd.GetCommand(command) cmd, ok := lumecmd.GetCommand(command)
if !ok { if !ok {
fmt.Printf("lume: '%s' is not lume command. See 'lume' --help.'\n", command) fmt.Printf("lume: '%s' is not lume command. See 'lume help'\n", command)
os.Exit(1) os.Exit(1)
} }
fs := cmd.Flags fs := cmd.Flags
@ -52,3 +61,30 @@ func main() {
} }
os.Exit(exitCode) os.Exit(exitCode)
} }
func loadConfig() lumecmd.Config {
var config lumecmd.Config
var tryPath, configPath string
homeDir, err := os.UserHomeDir()
if err == nil {
tryPath = path.Join(homeDir, lumercFile)
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
configPath = tryPath
}
}
cwd, err := os.Getwd()
if err == nil {
tryPath = path.Join(cwd, lumercFile)
if _, err := os.Stat(tryPath); !os.IsNotExist(err) {
configPath = tryPath
}
}
if configPath != "" {
toml.DecodeFile(configPath, &config)
}
return config
}

8
go.mod Normal file
View File

@ -0,0 +1,8 @@
module git.kill0.net/chill9/lume
go 1.15
require (
github.com/BurntSushi/toml v0.3.1
golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061
)

4
go.sum Normal file
View File

@ -0,0 +1,4 @@
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061 h1:DQmQoKxQWtyybCtX/3dIuDBcAhFszqq8YiNeS6sNu1c=
golang.org/x/sys v0.0.0-20210110051926-789bb1bd4061/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

View File

@ -79,8 +79,8 @@ type (
} }
States struct { States struct {
States []StateWithSelector `json:"states",omitempty` States []StateWithSelector `json:"states,omitempty"`
Defaults State `json:"defaults",omitempty` Defaults State `json:"defaults,omitempty"`
} }
Toggle struct { Toggle struct {