mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-26 22:27:56 +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
|
@ -46,8 +46,8 @@ var serviceAddCmd = &cobra.Command{
|
|||
Label: i18n.Tr("Service name"),
|
||||
Default: backend,
|
||||
Validate: func(s string) error {
|
||||
srv, _ := config.GetService(s)
|
||||
if srv != nil {
|
||||
_, err := config.GetService(s)
|
||||
if err == nil {
|
||||
return errors.New(i18n.Tr("a service with this name already exists"))
|
||||
}
|
||||
return config.ValidateKey(s)
|
||||
|
|
|
@ -17,7 +17,6 @@ Scotty. If not, see <https://www.gnu.org/licenses/>.
|
|||
package cmd
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
|
@ -42,11 +41,8 @@ var serviceAuthCmd = &cobra.Command{
|
|||
Authentication is always done per configured service. That means you can have
|
||||
multiple services using the same backend but different authentication.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
serviceConfig := cli.GetServiceConfigFromFlag(cmd, "service")
|
||||
if serviceConfig == nil {
|
||||
err := errors.New(i18n.Tr("failed loading service configuration"))
|
||||
cobra.CheckErr(err)
|
||||
}
|
||||
serviceConfig, err := cli.SelectService(cmd)
|
||||
cobra.CheckErr(err)
|
||||
backend, err := backends.ResolveBackend[models.OAuth2Authenticator](serviceConfig)
|
||||
cobra.CheckErr(err)
|
||||
|
||||
|
@ -97,7 +93,5 @@ multiple services using the same backend but different authentication.`,
|
|||
|
||||
func init() {
|
||||
serviceCmd.AddCommand(serviceAuthCmd)
|
||||
|
||||
serviceAuthCmd.Flags().StringP("service", "s", "", "service configuration (required)")
|
||||
serviceAuthCmd.MarkFlagRequired("service")
|
||||
serviceAuthCmd.Flags().StringP("service", "s", "", "service configuration")
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ var serviceDeleteCmd = &cobra.Command{
|
|||
Short: "Delete existing service configuration",
|
||||
Long: `Delete an existing service from the configuration file.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
service, err := cli.SelectService()
|
||||
service, err := cli.SelectService(cmd)
|
||||
cobra.CheckErr(err)
|
||||
|
||||
// Prompt for deletion
|
||||
|
@ -58,14 +58,5 @@ var serviceDeleteCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
serviceCmd.AddCommand(serviceDeleteCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// serviceDeleteCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// serviceDeleteCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
serviceDeleteCmd.Flags().StringP("service", "s", "", "service configuration")
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ var serviceEditCmd = &cobra.Command{
|
|||
Short: "Edit existing service configuration",
|
||||
Long: `Edit an existing service in the configuration file.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
service, err := cli.SelectService()
|
||||
service, err := cli.SelectService(cmd)
|
||||
cobra.CheckErr(err)
|
||||
|
||||
// Select backend
|
||||
|
@ -55,14 +55,5 @@ var serviceEditCmd = &cobra.Command{
|
|||
|
||||
func init() {
|
||||
serviceCmd.AddCommand(serviceEditCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// serviceEditCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// serviceEditCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
serviceEditCmd.Flags().StringP("service", "s", "", "service configuration")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue