mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 05:37:05 +02:00
service auth, edit and delete now all support --service flag
If a service name is given, this will be used. If not the user is prompted to select one.
This commit is contained in:
parent
c21715d36b
commit
9449a29fb1
9 changed files with 29 additions and 51 deletions
|
@ -20,11 +20,9 @@ import (
|
|||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
)
|
||||
|
||||
func GetServiceConfigFromFlag(cmd *cobra.Command, flagName string) *config.ServiceConfig {
|
||||
func GetServiceConfigFromFlag(cmd *cobra.Command, flagName string) (config.ServiceConfig, error) {
|
||||
name := cmd.Flag(flagName).Value.String()
|
||||
config, err := config.GetService(name)
|
||||
cobra.CheckErr(err)
|
||||
return config
|
||||
return config.GetService(name)
|
||||
}
|
||||
|
||||
func getInt64FromFlag(cmd *cobra.Command, flagName string) (result int64) {
|
||||
|
|
|
@ -21,12 +21,20 @@ import (
|
|||
"slices"
|
||||
|
||||
"github.com/manifoldco/promptui"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uploadedlobster.com/scotty/internal/backends"
|
||||
"go.uploadedlobster.com/scotty/internal/config"
|
||||
"go.uploadedlobster.com/scotty/internal/i18n"
|
||||
)
|
||||
|
||||
func SelectService() (config.ServiceConfig, error) {
|
||||
func SelectService(cmd *cobra.Command) (config.ServiceConfig, error) {
|
||||
// First try to load service from command line flag
|
||||
service, err := GetServiceConfigFromFlag(cmd, "service")
|
||||
if err == nil {
|
||||
return service, nil
|
||||
}
|
||||
|
||||
// Prompt the user to select a service
|
||||
services := config.AllServicesAsList()
|
||||
if len(services) == 0 {
|
||||
err := errors.New(i18n.Tr("no existing service configurations"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue