github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/runners/auth/signup.go (about)

     1  package auth
     2  
     3  import (
     4  	"github.com/ActiveState/cli/internal/keypairs"
     5  	"github.com/ActiveState/cli/internal/locale"
     6  	"github.com/ActiveState/cli/internal/output"
     7  	"github.com/ActiveState/cli/internal/prompt"
     8  	"github.com/ActiveState/cli/internal/runbits/auth"
     9  	"github.com/ActiveState/cli/pkg/platform/authentication"
    10  )
    11  
    12  type Signup struct {
    13  	output.Outputer
    14  	prompt.Prompter
    15  	keypairs.Configurable
    16  	*authentication.Auth
    17  }
    18  
    19  type SignupParams struct {
    20  	Prompt bool
    21  }
    22  
    23  func NewSignup(prime primeable) *Signup {
    24  	return &Signup{prime.Output(), prime.Prompt(), prime.Config(), prime.Auth()}
    25  }
    26  
    27  func (s *Signup) Run(params *SignupParams) error {
    28  	if s.Auth.Authenticated() {
    29  		return locale.NewInputError("err_auth_authenticated", "You are already authenticated as: {{.V0}}. You can log out by running '[ACTIONABLE]state auth logout[/RESET]'.", s.Auth.WhoAmI())
    30  	}
    31  
    32  	return auth.SignupWithBrowser(s.Outputer, s.Auth, s.Prompter, s.Configurable)
    33  }