mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37:05 +02:00
Use config.ServiceConfig across API
This commit is contained in:
parent
091b3c2f49
commit
9c363cc06d
27 changed files with 137 additions and 99 deletions
|
@ -16,23 +16,15 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
)
|
||||
|
||||
func GetConfigFromFlag(cmd *cobra.Command, flagName string) (string, *viper.Viper) {
|
||||
configName := cmd.Flag(flagName).Value.String()
|
||||
var config *viper.Viper
|
||||
servicesConfig := viper.Sub("service")
|
||||
if servicesConfig != nil {
|
||||
config = servicesConfig.Sub(configName)
|
||||
}
|
||||
if config == nil {
|
||||
cobra.CheckErr(fmt.Sprintf("invalid configuration \"%s\"", configName))
|
||||
}
|
||||
return configName, config
|
||||
func GetServiceConfigFromFlag(cmd *cobra.Command, flagName string) *config.ServiceConfig {
|
||||
name := cmd.Flag(flagName).Value.String()
|
||||
config, err := config.GetService(name)
|
||||
cobra.CheckErr(err)
|
||||
return config
|
||||
}
|
||||
|
||||
func getInt64FromFlag(cmd *cobra.Command, flagName string) (result int64) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue