-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurrent.go
More file actions
81 lines (68 loc) · 2.26 KB
/
current.go
File metadata and controls
81 lines (68 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cmd
import (
"encoding/json"
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/techishthoughts/gitshift/internal/config"
)
// currentCmd represents the current command
var currentCmd = &cobra.Command{
Use: "current",
Short: "👤 Show the current active Git account",
Long: `Display the currently active Git platform account configuration.
This command shows which account is currently active in gitshift, including
its alias, name, email, and platform.
Works with all supported platforms:
- GitHub (github.com and GitHub Enterprise)
- GitLab (gitlab.com and self-hosted)
- Bitbucket (coming soon)
- Custom Git platforms`,
Aliases: []string{"c", "whoami"},
RunE: runCurrentCommand,
}
// runCurrentCommand executes the current command
func runCurrentCommand(cmd *cobra.Command, args []string) error {
// Get the current account alias
alias, err := getCurrentAccount()
if err != nil {
return fmt.Errorf("failed to get current account: %w", err)
}
// Load the configuration
configManager := config.NewManager()
// Get the account details
account, err := configManager.GetAccount(alias)
if err != nil {
return fmt.Errorf("failed to get account details: %w", err)
}
// Check if we should output JSON
jsonOutput, _ := cmd.Flags().GetBool("json")
if jsonOutput {
// Output in JSON format
encoder := json.NewEncoder(os.Stdout)
encoder.SetIndent("", " ")
if err := encoder.Encode(account); err != nil {
return fmt.Errorf("failed to encode account as JSON: %w", err)
}
return nil
}
// Display the current account information in a human-readable format
fmt.Println("\n🤖 Current Active Account")
fmt.Println("───────────────────────")
fmt.Printf("👤 \033[1mAlias:\033[0m %s\n", account.Alias)
fmt.Printf("👤 \033[1mName:\033[0m %s\n", account.Name)
fmt.Printf("📧 \033[1mEmail:\033[0m %s\n", account.Email)
if account.GitHubUsername != "" {
fmt.Printf("🐙 \033[1mGitHub:\033[0m @%s\n", account.GitHubUsername)
}
if account.SSHKeyPath != "" {
fmt.Printf("🔑 \033[1mSSH Key:\033[0m %s\n", account.SSHKeyPath)
}
fmt.Println()
return nil
}
func init() {
// Add the --json flag
currentCmd.Flags().BoolP("json", "j", false, "Output in JSON format")
rootCmd.AddCommand(currentCmd)
}