Skip to content
Snippets Groups Projects

refactor: Reorganize into user and group commands

Merged yyvf22 requested to merge refactor into main
14 files
+ 267
168
Compare changes
  • Side-by-side
  • Inline
Files
14
+ 48
0
 
package group
 
 
import (
 
"bufio"
 
"fmt"
 
"os"
 
"strings"
 
 
"github.com/spf13/cobra"
 
)
 
 
var CreateCmd = &cobra.Command{
 
Use: "create",
 
Short: "Create new group",
 
RunE: createGroupFunc,
 
}
 
 
func init() {
 
CreateCmd.Flags().StringP("groupname", "e", "", "Group name (use quotes for spaces)")
 
CreateCmd.Flags().BoolP("confirm", "y", false, "Skip confirmation prompt")
 
 
CreateCmd.MarkFlagRequired("groupname")
 
}
 
 
func createGroupFunc(cmd *cobra.Command, args []string) error {
 
groupName, err := cmd.Flags().GetString("groupname")
 
if err != nil {
 
return err
 
}
 
confirm, err := cmd.Flags().GetBool("confirm")
 
if err != nil {
 
return err
 
}
 
fmt.Printf("Groupname: %s\n", groupName)
 
 
if !confirm {
 
fmt.Print("Proceed with group creation? [y/N] ")
 
reader := bufio.NewReader(os.Stdin)
 
response, _ := reader.ReadString('\n')
 
if strings.TrimSpace(strings.ToLower(response)) != "y" {
 
fmt.Println("Aborted.")
 
os.Exit(1)
 
}
 
}
 
 
fmt.Println("Done!")
 
return nil
 
}
Loading