mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-29 21:27:05 +02:00
Implemented service edit command
This commit is contained in:
parent
c6c0723e27
commit
58a47a43e7
15 changed files with 213 additions and 57 deletions
|
@ -17,6 +17,7 @@ package config
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"github.com/spf13/cast"
|
||||
"github.com/spf13/viper"
|
||||
|
@ -44,6 +45,10 @@ func NewServiceConfig(name string, config *viper.Viper) ServiceConfig {
|
|||
return service
|
||||
}
|
||||
|
||||
func (c ServiceConfig) String() string {
|
||||
return c.Name
|
||||
}
|
||||
|
||||
func (c *ServiceConfig) GetString(key string) string {
|
||||
return cast.ToString(c.ConfigValues[key])
|
||||
}
|
||||
|
@ -66,13 +71,27 @@ func (c *ServiceConfig) Save() error {
|
|||
return viper.WriteConfig()
|
||||
}
|
||||
|
||||
type ServiceList []ServiceConfig
|
||||
|
||||
func (l ServiceList) Len() int {
|
||||
return len(l)
|
||||
}
|
||||
|
||||
func (l ServiceList) Less(i, j int) bool {
|
||||
return l[i].Name < l[j].Name
|
||||
}
|
||||
|
||||
func (l ServiceList) Swap(i, j int) {
|
||||
l[i], l[j] = l[j], l[i]
|
||||
}
|
||||
|
||||
func AllServices() map[string]ServiceConfig {
|
||||
services := make(map[string]ServiceConfig)
|
||||
config := viper.Sub("service")
|
||||
if config != nil {
|
||||
for k, v := range config.AllSettings() {
|
||||
s, ok := v.(*viper.Viper)
|
||||
if ok {
|
||||
for k := range config.AllSettings() {
|
||||
s := config.Sub(k)
|
||||
if s != nil {
|
||||
services[k] = NewServiceConfig(k, s)
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +99,16 @@ func AllServices() map[string]ServiceConfig {
|
|||
return services
|
||||
}
|
||||
|
||||
func AllServicesAsList() ServiceList {
|
||||
services := AllServices()
|
||||
list := make(ServiceList, 0, len(services))
|
||||
for _, s := range services {
|
||||
list = append(list, s)
|
||||
}
|
||||
sort.Sort(list)
|
||||
return list
|
||||
}
|
||||
|
||||
func GetService(name string) (*ServiceConfig, error) {
|
||||
key := "service." + name
|
||||
config := viper.Sub(key)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue