fix
This commit is contained in:
@@ -26,12 +26,12 @@ type Controller struct {
|
||||
|
||||
// Config represents the entire tellstick.conf structure
|
||||
type Config struct {
|
||||
User string `json:"user,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
DevicePath string `json:"devicePath,omitempty"`
|
||||
IgnoreControllerConfirmation int `json:"ignoreControllerConfirmation,omitempty"`
|
||||
Controllers []Controller `json:"controllers"`
|
||||
Devices []Device `json:"devices"`
|
||||
User string `json:"user,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
DevicePath string `json:"devicePath,omitempty"`
|
||||
IgnoreControllerConfirmation int `json:"ignoreControllerConfirmation,omitempty"`
|
||||
Controllers []Controller `json:"controllers"`
|
||||
Devices []Device `json:"devices"`
|
||||
}
|
||||
|
||||
// Parser handles parsing and writing tellstick.conf files
|
||||
@@ -64,7 +64,7 @@ func (p *Parser) Parse() (*Config, error) {
|
||||
|
||||
for scanner.Scan() {
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
|
||||
|
||||
// Skip empty lines and comments
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
@@ -101,12 +101,12 @@ func (p *Parser) Parse() (*Config, error) {
|
||||
}
|
||||
|
||||
// Section detection
|
||||
if strings.HasPrefix(line, "controller") {
|
||||
if strings.HasPrefix(line, "controller {") || strings.HasPrefix(line, "controller{") {
|
||||
currentSection = "controller"
|
||||
currentController = &Controller{}
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(line, "device") {
|
||||
if strings.HasPrefix(line, "device {") || strings.HasPrefix(line, "device{") {
|
||||
currentSection = "device"
|
||||
currentDevice = &Device{
|
||||
Parameters: make(map[string]string),
|
||||
@@ -134,7 +134,7 @@ func (p *Parser) Parse() (*Config, error) {
|
||||
if len(parts) == 2 {
|
||||
key := strings.TrimSpace(parts[0])
|
||||
value := strings.Trim(strings.TrimSpace(parts[1]), "\"")
|
||||
|
||||
|
||||
switch key {
|
||||
case "id":
|
||||
fmt.Sscanf(value, "%d", ¤tDevice.ID)
|
||||
@@ -149,13 +149,13 @@ func (p *Parser) Parse() (*Config, error) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if currentSection == "controller" && currentController != nil {
|
||||
parts := strings.SplitN(line, "=", 2)
|
||||
if len(parts) == 2 {
|
||||
key := strings.TrimSpace(parts[0])
|
||||
value := strings.Trim(strings.TrimSpace(parts[1]), "\"")
|
||||
|
||||
|
||||
switch key {
|
||||
case "id":
|
||||
fmt.Sscanf(value, "%d", ¤tController.ID)
|
||||
@@ -200,7 +200,7 @@ func (p *Parser) Write(config *Config) error {
|
||||
if config.IgnoreControllerConfirmation > 0 {
|
||||
fmt.Fprintf(w, "ignoreControllerConfirmation = %d\n", config.IgnoreControllerConfirmation)
|
||||
}
|
||||
|
||||
|
||||
w.WriteString("\n")
|
||||
|
||||
// Write controllers
|
||||
@@ -228,12 +228,12 @@ func (p *Parser) Write(config *Config) error {
|
||||
if dev.Model != "" {
|
||||
fmt.Fprintf(w, " model = \"%s\"\n", dev.Model)
|
||||
}
|
||||
|
||||
|
||||
// Write parameters
|
||||
for key, value := range dev.Parameters {
|
||||
fmt.Fprintf(w, " %s = \"%s\"\n", key, value)
|
||||
}
|
||||
|
||||
|
||||
w.WriteString("}\n\n")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user