Skip to content

Commit

Permalink
✨ implement tempset command, remove signingKey attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Shieldine committed Jun 23, 2024
1 parent 303ddc2 commit d68d027
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 7 deletions.
5 changes: 0 additions & 5 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ func addRun(cmd *cobra.Command, args []string) {
email = strings.TrimSpace(email)
}

fmt.Print("Signing key (enter to skip): ")
signingKey, _ := reader.ReadString('\n')
signingKey = strings.TrimSpace(signingKey)

currentOrigin, _ := internal.GetRepoOrigin()
newOrigin := ""

Expand All @@ -85,7 +81,6 @@ func addRun(cmd *cobra.Command, args []string) {
ProfileName: profileName,
Name: name,
Email: email,
SigningKey: signingKey,
Origin: newOrigin,
}

Expand Down
1 change: 0 additions & 1 deletion cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ You can manually type in new profiles by using the following scheme:
profile_name = ""
name = ""
email = ""
signing_key = ""
origin = ""
`,
Run: func(cmd *cobra.Command, args []string) {
Expand Down
76 changes: 76 additions & 0 deletions cmd/tempset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright © 2024 Shieldine <74987363+Shieldine@users.noreply.github.com>
*/
package cmd

import (
"bufio"
"fmt"
"os"
"strings"

"github.com/Shieldine/git-profile/internal"
"github.com/spf13/cobra"
)

var tempsetCmd = &cobra.Command{
Use: "tempset",
Short: "Set credentials without defining a profile",
Long: `Set git credentials for the current repository without saving them in a profile.
The credentials can be passed as flags right away.
If you don't pass them, you will be asked to provide a name, email and signing key (optional).
`,
Run: func(cmd *cobra.Command, args []string) {
reader := bufio.NewReader(os.Stdin)

if name == "" {
currentName, err := internal.GetUserName()

if err != nil {
fmt.Println(err)
os.Exit(1)
}

fmt.Printf("Name (enter to keep %s): ", currentName)
name, _ = reader.ReadString('\n')
name = strings.TrimSpace(name)

if name != "" {
err = internal.SetUserName(name)
if err != nil {
fmt.Printf("Error setting user name: %s\n", err)
os.Exit(1)
}
}
}

if email == "" {
currentEmail, err := internal.GetUserEmail()

if err != nil {
fmt.Println(err)
os.Exit(1)
}

fmt.Printf("E-mail (enter to keep %s): ", currentEmail)
email, _ = reader.ReadString('\n')
email = strings.TrimSpace(email)

if email != "" {
err = internal.SetUserEmail(email)
if err != nil {
fmt.Printf("Error setting user email: %s\n", err)
os.Exit(1)
}
}
}

fmt.Println("Credentials set successfully")
},
}

func init() {
rootCmd.AddCommand(tempsetCmd)
tempsetCmd.Flags().StringVarP(&name, "name", "n", "", "Pass the name directly")
tempsetCmd.Flags().StringVarP(&email, "email", "e", "", "Pass the email directly")
}
1 change: 0 additions & 1 deletion models/profile_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ type ProfileConfig struct {
ProfileName string `toml:"profile_name"`
Name string `toml:"name"`
Email string `toml:"email"`
SigningKey string `toml:"signing_key"`
Origin string `toml:"origin"`
}

0 comments on commit d68d027

Please sign in to comment.