Compare commits
5 Commits
0.1.0
...
73123d0806
Author | SHA1 | Date | |
---|---|---|---|
73123d0806 | |||
4275e6740b | |||
667b1cf288 | |||
ed02821b39 | |||
ea8864375b |
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@
|
|||||||
# Dependency directories (remove the comment below to include it)
|
# Dependency directories (remove the comment below to include it)
|
||||||
# vendor/
|
# vendor/
|
||||||
|
|
||||||
|
.lumerc
|
||||||
|
Binary file not shown.
19
cmd/lume/init_windows.go
Normal file
19
cmd/lume/init_windows.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// +build windows
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/52579002
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"golang.org/x/sys/windows"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
stdout := windows.Handle(os.Stdout.Fd())
|
||||||
|
var originalMode uint32
|
||||||
|
|
||||||
|
windows.GetConsoleMode(stdout, &originalMode)
|
||||||
|
windows.SetConsoleMode(stdout, originalMode|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING)
|
||||||
|
}
|
@ -9,25 +9,23 @@ import (
|
|||||||
lifx "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 string = ".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
|
||||||
config = loadConfig()
|
|
||||||
|
|
||||||
if config.AccessToken == "" {
|
configPath := getConfigPath()
|
||||||
config.AccessToken = os.Getenv("LIFX_ACCESS_TOKEN")
|
if _, err := toml.DecodeFile(configPath, &config); err != nil {
|
||||||
|
fmt.Printf("fatal: failed to parse %s\n", configPath)
|
||||||
|
fmt.Println(err)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
envAccessToken := os.Getenv("LIFX_ACCESS_TOKEN")
|
||||||
|
if envAccessToken != "" {
|
||||||
|
config.AccessToken = envAccessToken
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.AccessToken == "" {
|
if config.AccessToken == "" {
|
||||||
@ -54,7 +52,7 @@ func main() {
|
|||||||
fs := cmd.Flags
|
fs := cmd.Flags
|
||||||
fs.Parse(os.Args[2:])
|
fs.Parse(os.Args[2:])
|
||||||
|
|
||||||
cmdArgs.Flags = lumecmd.Flags{fs}
|
cmdArgs.Flags = lumecmd.Flags{FlagSet: fs}
|
||||||
exitCode, err := cmd.Func(cmdArgs)
|
exitCode, err := cmd.Func(cmdArgs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "fatal: %s\n", err)
|
fmt.Fprintf(os.Stderr, "fatal: %s\n", err)
|
||||||
@ -62,10 +60,10 @@ func main() {
|
|||||||
os.Exit(exitCode)
|
os.Exit(exitCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConfig() lumecmd.Config {
|
func getConfigPath() string {
|
||||||
var config lumecmd.Config
|
|
||||||
var tryPath, configPath string
|
var tryPath, configPath string
|
||||||
|
|
||||||
|
// ~/.lumerc
|
||||||
homeDir, err := os.UserHomeDir()
|
homeDir, err := os.UserHomeDir()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tryPath = path.Join(homeDir, lumercFile)
|
tryPath = path.Join(homeDir, lumercFile)
|
||||||
@ -74,6 +72,7 @@ func loadConfig() lumecmd.Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ./.lumerc
|
||||||
cwd, err := os.Getwd()
|
cwd, err := os.Getwd()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tryPath = path.Join(cwd, lumercFile)
|
tryPath = path.Join(cwd, lumercFile)
|
||||||
@ -82,9 +81,5 @@ func loadConfig() lumecmd.Config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if configPath != "" {
|
return configPath
|
||||||
toml.DecodeFile(configPath, &config)
|
|
||||||
}
|
|
||||||
|
|
||||||
return config
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user