func signup(ctx *cli.Context, subCommand bool) error {
	args := ctx.Args()
	if len(args) > 0 && len(args) != 2 {
		var text string
		if len(args) > 2 {
			text = "Too many arguments supplied."
		} else {
			text = "Too few arguments supplied."
		}
		return errs.NewUsageExitError(text, ctx)
	}

	fmt.Println("By completing sign up, you agree to our terms of use (found at https://torus.sh/terms)\nand our privacy policy (found at https://torus.sh/privacy)")
	fmt.Println("")

	name, err := FullNamePrompt()
	if err != nil {
		return err
	}

	username, err := UsernamePrompt()
	if err != nil {
		return err
	}

	defaultEmail := ""
	defaultInvite := ""
	if len(args) == 2 {
		defaultEmail = args[0]
		defaultInvite = args[1]
	}

	email, err := EmailPrompt(defaultEmail)
	if err != nil {
		return err
	}

	var inviteCode string
	if subCommand {
		inviteCode, err = InviteCodePrompt(defaultInvite)
		if err != nil {
			return err
		}
	}

	password, err := PasswordPrompt(true)
	if err != nil {
		return err
	}

	cfg, err := config.LoadConfig()
	if err != nil {
		return err
	}

	client := api.NewClient(cfg)

	signup := apitypes.Signup{
		Name:       name,
		Username:   username,
		Passphrase: password,
		Email:      email,
		InviteCode: inviteCode,
		OrgName:    ctx.String("org"),
		OrgInvite:  subCommand,
	}

	c := context.Background()

	fmt.Println("")
	user, err := client.Users.Signup(c, &signup, &progress)
	if err != nil {
		if strings.Contains(err.Error(), "resource exists") {
			return errs.NewExitError("Username or email address in use.")
		}
		return errs.NewExitError("Signup failed, please try again.")
	}

	// Log the user in
	err = performLogin(c, client, user.Body.Email, password)
	if err != nil {
		return err
	}

	// Generate keypairs, look up the user's org
	err = generateKeypairsForOrg(c, ctx, client, nil, true)
	if err != nil {
		return err
	}

	fmt.Println("")
	fmt.Println("Your account has been created!")

	if !subCommand {
		fmt.Println("")
		fmt.Println("We have emailed you a verification code.")
		fmt.Println("Please verify your email address by entering the code below.")
		fmt.Println("")

		code, err := VerificationPrompt()
		if err != nil {
			return err
		}
		fmt.Println("")

		err = verifyEmail(ctx, &code, true)
		if err != nil {
			return err
		}
	}

	return nil
}
// signup can be ran as a sub-command when an account is needed prior to running
// a particular action. the subCommand boolean signifies it is running as such
// and not as a generic signup
signup can be ran as a sub-command when an account is needed prior to running
a particular action. the subCommand boolean signifies it is running as such
and not as a generic signup
// signup can be ran as a sub - command when an account is needed prior to running // a particular action . the subCommand boolean signifies it is running as such // and not as a generic signup
func signup(ctx *cli.Context, subCommand bool) error {
	args := ctx.Args()
	if len(args) > 0 && len(args) != 2 {
		var text string
		if len(args) > 2 {
			text = "Too many arguments supplied."
		} else {
			text = "Too few arguments supplied."
		}
		return errs.NewUsageExitError(text, ctx)
	}
	fmt.Println("By completing sign up, you agree to our terms of use (found at https://torus.sh/terms)\nand our privacy policy (found at https://torus.sh/privacy)")
	fmt.Println("")
	name, err := FullNamePrompt()
	if err != nil {
		return err
	}
	username, err := UsernamePrompt()
	if err != nil {
		return err
	}
	defaultEmail := ""
	defaultInvite := ""
	if len(args) == 2 {
		defaultEmail = args[0]
		defaultInvite = args[1]
	}
	email, err := EmailPrompt(defaultEmail)
	if err != nil {
		return err
	}
	var inviteCode string
	if subCommand {
		inviteCode, err = InviteCodePrompt(defaultInvite)
		if err != nil {
			return err
		}
	}
	password, err := PasswordPrompt(true)
	if err != nil {
		return err
	}
	cfg, err := config.LoadConfig()
	if err != nil {
		return err
	}
	client := api.NewClient(cfg)
	signup := apitypes.Signup{
		Name:       name,
		Username:   username,
		Passphrase: password,
		Email:      email,
		InviteCode: inviteCode,
		OrgName:    ctx.String("org"),
		OrgInvite:  subCommand,
	}
	c := context.Background()
	fmt.Println("")
	user, err := client.Users.Signup(c, &signup, &progress)
	if err != nil {
		if strings.Contains(err.Error(), "resource exists") {
			return errs.NewExitError("Username or email address in use.")
		}
		return errs.NewExitError("Signup failed, please try again.")
	}
	err = performLogin(c, client, user.Body.Email, password)
	if err != nil {
		return err
	}
	err = generateKeypairsForOrg(c, ctx, client, nil, true)
	if err != nil {
		return err
	}
	fmt.Println("")
	fmt.Println("Your account has been created!")
	if !subCommand {
		fmt.Println("")
		fmt.Println("We have emailed you a verification code.")
		fmt.Println("Please verify your email address by entering the code below.")
		fmt.Println("")
		code, err := VerificationPrompt()
		if err != nil {
			return err
		}
		fmt.Println("")
		err = verifyEmail(ctx, &code, true)
		if err != nil {
			return err
		}
	}
	return nil
}
func signup ( ctx * cli . Context , subCommand bool ) error { args := ctx . Args ( ) if len ( args ) > 0 && len ( args ) != 2 { var text string if len ( args ) > 2 { text = " " } else { text = " " } return errs . NewUsageExitError ( text , ctx ) } fmt . Println ( " \n " ) fmt . Println ( " " ) name , err := FullNamePrompt ( ) if err != nil { return err } username , err := UsernamePrompt ( ) if err != nil { return err } defaultEmail := " " defaultInvite := " " if len ( args ) == 2 { defaultEmail = args [ 0 ] defaultInvite = args [ 1 ] } email , err := EmailPrompt ( defaultEmail ) if err != nil { return err } var inviteCode string if subCommand { inviteCode , err = InviteCodePrompt ( defaultInvite ) if err != nil { return err } } password , err := PasswordPrompt ( true ) if err != nil { return err } cfg , err := config . LoadConfig ( ) if err != nil { return err } client := api . NewClient ( cfg ) signup := apitypes . Signup { Name : name , Username : username , Passphrase : password , Email : email , InviteCode : inviteCode , OrgName : ctx . String ( " " ) , OrgInvite : subCommand , } c := context . Background ( ) fmt . Println ( " " ) user , err := client . Users . Signup ( c , & signup , & progress ) if err != nil { if strings . Contains ( err . Error ( ) , " " ) { return errs . NewExitError ( " " ) } return errs . NewExitError ( " " ) } err = performLogin ( c , client , user . Body . Email , password ) if err != nil { return err } err = generateKeypairsForOrg ( c , ctx , client , nil , true ) if err != nil { return err } fmt . Println ( " " ) fmt . Println ( " " ) if ! subCommand { fmt . Println ( " " ) fmt . Println ( " " ) fmt . Println ( " " ) fmt . Println ( " " ) code , err := VerificationPrompt ( ) if err != nil { return err } fmt . Println ( " " ) err = verifyEmail ( ctx , & code , true ) if err != nil { return err } } return nil }
signup can be ran as a sub-command when an account is needed prior to running
a particular action.
signup can be ran as a sub - command when an account is needed prior to running a particular action .
// Log the user in // Generate keypairs, look up the user's org