Compare commits
7 Commits
1397fbe4a3
...
7e09d3b3e6
Author | SHA1 | Date | |
---|---|---|---|
7e09d3b3e6 | |||
80036ca8ac | |||
629e5566ae | |||
6dbb8295b6 | |||
94b7c38396 | |||
3d75dbbbbd | |||
4f20ff02a5 |
1
.lumerc.sample
Normal file
1
.lumerc.sample
Normal file
@ -0,0 +1 @@
|
||||
AccessToken = "token"
|
15
.vscode/launch.json
vendored
Normal file
15
.vscode/launch.json
vendored
Normal 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
23
.vscode/tasks.json
vendored
Normal 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",
|
||||
},
|
||||
],
|
||||
}
|
@ -17,7 +17,7 @@ func init() {
|
||||
RegisterCommand(cmdName, Command{
|
||||
Func: LsCmd,
|
||||
Flags: fs,
|
||||
Use: "[--selector=<selector>",
|
||||
Use: "[--selector=<selector>]",
|
||||
Short: "List the lights",
|
||||
})
|
||||
}
|
||||
|
BIN
cmd/lume/__debug_bin
Normal file
BIN
cmd/lume/__debug_bin
Normal file
Binary file not shown.
@ -6,18 +6,27 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"git.kill0.net/chill9/lume"
|
||||
lifx "git.kill0.net/chill9/lume"
|
||||
lumecmd "git.kill0.net/chill9/lume/cmd"
|
||||
"github.com/BurntSushi/toml"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
const lumercFile = ".lumerc"
|
||||
|
||||
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
|
||||
homeDir, err := os.UserHomeDir()
|
||||
_, err = toml.DecodeFile(path.Join(homeDir, lumercFile), &config)
|
||||
if os.IsNotExist(err) {
|
||||
config = loadConfig()
|
||||
|
||||
if config.AccessToken == "" {
|
||||
config.AccessToken = os.Getenv("LIFX_ACCESS_TOKEN")
|
||||
}
|
||||
|
||||
@ -39,7 +48,7 @@ func main() {
|
||||
|
||||
cmd, ok := lumecmd.GetCommand(command)
|
||||
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)
|
||||
}
|
||||
fs := cmd.Flags
|
||||
@ -52,3 +61,30 @@ func main() {
|
||||
}
|
||||
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
8
go.mod
Normal 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
4
go.sum
Normal 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=
|
Loading…
Reference in New Issue
Block a user