mirror of
https://github.com/MichaelMure/git-bug.git
synced 2024-12-16 11:00:42 +03:00
864d3ed335
- init() only the importer or exporter as required - assign a "default user" user Id to credentials at creation if no user has been set - "bridge auth": also display the user - "bridge auth show": adapt to a potential "default user" user Id - "bridge configure": allow to run without a user set - "bridge pull": allow to run without a user set - "user adopt": replace "default user" by the actual user id when run
61 lines
1.2 KiB
Go
61 lines
1.2 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/MichaelMure/git-bug/bridge/core/auth"
|
|
"github.com/MichaelMure/git-bug/cache"
|
|
"github.com/MichaelMure/git-bug/identity"
|
|
"github.com/MichaelMure/git-bug/util/interrupt"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func runUserAdopt(cmd *cobra.Command, args []string) error {
|
|
backend, err := cache.NewRepoCache(repo)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer backend.Close()
|
|
interrupt.RegisterCleaner(backend.Close)
|
|
|
|
prefix := args[0]
|
|
|
|
i, err := backend.ResolveIdentityPrefix(prefix)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, err = backend.GetUserIdentity()
|
|
if err == identity.ErrNoIdentitySet {
|
|
err = auth.ReplaceDefaultUser(repo, i.Id())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
} else if err != nil {
|
|
return err
|
|
}
|
|
|
|
err = backend.SetUserIdentity(i)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
_, _ = fmt.Fprintf(os.Stderr, "Your identity is now: %s\n", i.DisplayName())
|
|
|
|
return nil
|
|
}
|
|
|
|
var userAdoptCmd = &cobra.Command{
|
|
Use: "adopt <user-id>",
|
|
Short: "Adopt an existing identity as your own.",
|
|
PreRunE: loadRepo,
|
|
RunE: runUserAdopt,
|
|
Args: cobra.ExactArgs(1),
|
|
}
|
|
|
|
func init() {
|
|
userCmd.AddCommand(userAdoptCmd)
|
|
userAdoptCmd.Flags().SortFlags = false
|
|
}
|