mirror of
https://github.com/Slug-Boi/cocommit.git
synced 2026-05-13 12:45:47 +00:00
refactor(cmd): reformat the command to match other commands
This commit is contained in:
+53
-39
@@ -4,56 +4,70 @@ Copyright © 2025 NAME HERE <EMAIL ADDRESS>
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/Slug-Boi/cocommit/src/cmd/tui"
|
"github.com/Slug-Boi/cocommit/src/cmd/tui"
|
||||||
"github.com/Slug-Boi/cocommit/src/cmd/utils"
|
"github.com/Slug-Boi/cocommit/src/cmd/utils"
|
||||||
|
//"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ghProfileCmd represents the ghProfile command
|
// ghProfileCmd represents the ghProfile command
|
||||||
var ghCmd = &cobra.Command{
|
func GHCmd () *cobra.Command {
|
||||||
Use: "gh <github username>",
|
return &cobra.Command{
|
||||||
Short: "This command will create add a github profile to your author list for use in commits",
|
Use: "gh <github username>",
|
||||||
Long: `This command will create add a github profile to your author list.
|
Short: "This command will create add a github profile to your author list for use in commits",
|
||||||
You just have to run the command with a username of the github profile you want to add.
|
Long: `This command will create add a github profile to your author list.
|
||||||
The email will be added manually by following the TUI or adding the email flag to the command.`,
|
You just have to run the command with a username of the github profile you want to add.
|
||||||
Args: cobra.ExactArgs(1),
|
The email will be added manually by following the TUI or adding the email flag to the command.`,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Args: cobra.ExactArgs(1),
|
||||||
email, _ := cmd.Flags().GetString("email")
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
shortname, _ := cmd.Flags().GetString("shortname")
|
email, _ := cmd.Flags().GetString("email")
|
||||||
longname, _ := cmd.Flags().GetString("longname")
|
shortname, _ := cmd.Flags().GetString("shortname")
|
||||||
username, _ := cmd.Flags().GetString("username")
|
longname, _ := cmd.Flags().GetString("longname")
|
||||||
groups, _ := cmd.Flags().GetStringSlice("groups")
|
username, _ := cmd.Flags().GetString("username")
|
||||||
exclude, _ := cmd.Flags().GetBool("exclude")
|
groups, _ := cmd.Flags().GetStringSlice("groups")
|
||||||
|
exclude, _ := cmd.Flags().GetBool("exclude")
|
||||||
|
|
||||||
user := utils.FetchGithubProfile(args[0])
|
user := utils.FetchGithubProfile(args[0])
|
||||||
|
|
||||||
// Update values if flags are set
|
// Update values if flags are set
|
||||||
if shortname != "" {
|
if shortname != "" {
|
||||||
user.Shortname = shortname
|
user.Shortname = shortname
|
||||||
}
|
}
|
||||||
if longname != "" {
|
if longname != "" {
|
||||||
user.Longname = longname
|
user.Longname = longname
|
||||||
}
|
}
|
||||||
if username != "" {
|
if username != "" {
|
||||||
user.Username = username
|
user.Username = username
|
||||||
}
|
}
|
||||||
if len(groups) > 0 {
|
if len(groups) > 0 {
|
||||||
user.Groups = groups
|
user.Groups = groups
|
||||||
}
|
}
|
||||||
if exclude {
|
if exclude {
|
||||||
user.Ex = true
|
user.Ex = true
|
||||||
}
|
}
|
||||||
|
|
||||||
if email != "" {
|
if email != "" {
|
||||||
user.Email = email
|
user.Email = email
|
||||||
} else {
|
if utils.CheckUserFields(user) {
|
||||||
// run the TUI to get the email
|
utils.CreateAuthor(user)
|
||||||
tui.EntryGHAuthorModel(user)
|
// print sucess message
|
||||||
}
|
//fmt.Print(lipgloss.NewStyle().Foreground(lipgloss.Color("170")).Render("Author added successfully"))
|
||||||
},
|
fmt.Print("Author added successfully\n")
|
||||||
|
} else {
|
||||||
|
panic("Invalid author data")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// run the TUI to get the email
|
||||||
|
tui.EntryGHAuthorModel(user)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
ghCmd := GHCmd()
|
||||||
rootCmd.AddCommand(ghCmd)
|
rootCmd.AddCommand(ghCmd)
|
||||||
ghCmd.Flags().StringP("email", "@", "", "Email to be used for the author")
|
ghCmd.Flags().StringP("email", "@", "", "Email to be used for the author")
|
||||||
ghCmd.Flags().StringP("longname", "n", "", "Name to be used for the author")
|
ghCmd.Flags().StringP("longname", "n", "", "Name to be used for the author")
|
||||||
|
|||||||
Reference in New Issue
Block a user