rsapi/rsapi.go
func FromCommandLine(cmdLine *cmd.CommandLine) (*API, error) {
	var client *API
	ss := strings.HasPrefix(cmdLine.Command, "ss")
	if cmdLine.RL10 {
		var err error
		if client, err = NewRL10(); err != nil {
			return nil, err
		}
	} else if cmdLine.OAuthToken != "" {
		auth := NewOAuthAuthenticator(cmdLine.OAuthToken, cmdLine.Account)
		if ss {
			auth = NewSSAuthenticator(auth, cmdLine.Account)
		}
		client = New(cmdLine.Host, auth)
	} else if cmdLine.OAuthAccessToken != "" {
		auth := NewTokenAuthenticator(cmdLine.OAuthAccessToken, cmdLine.Account)
		if ss {
			auth = NewSSAuthenticator(auth, cmdLine.Account)
		}
		client = New(cmdLine.Host, auth)
	} else if cmdLine.APIToken != "" {
		auth := NewInstanceAuthenticator(cmdLine.APIToken, cmdLine.Account)
		if ss {
			auth = NewSSAuthenticator(auth, cmdLine.Account)
		}
		client = New(cmdLine.Host, auth)
	} else if cmdLine.Username != "" && cmdLine.Password != "" {
		auth := NewBasicAuthenticator(cmdLine.Username, cmdLine.Password, cmdLine.Account)
		if ss {
			auth = NewSSAuthenticator(auth, cmdLine.Account)
		}
		client = New(cmdLine.Host, auth)
	} else {
		// No auth, used by tests
		client = New(cmdLine.Host, nil)
		httpclient.Insecure = true
	}
	if !cmdLine.ShowHelp && !cmdLine.NoAuth {
		if cmdLine.OAuthToken == "" && cmdLine.OAuthAccessToken == "" && cmdLine.APIToken == "" && cmdLine.Username == "" && !cmdLine.RL10 {
			return nil, fmt.Errorf("Missing authentication information, use '--email EMAIL --password PWD', '--token TOKEN' or 'setup'")
		}
		if cmdLine.Verbose || cmdLine.Dump == "debug" {
			httpclient.DumpFormat = httpclient.Debug
		}
		if cmdLine.Dump == "json" {
			httpclient.DumpFormat = httpclient.JSON
		}
		if cmdLine.Dump == "record" {
			httpclient.DumpFormat = httpclient.JSON | httpclient.Record
		}
		if cmdLine.Verbose {
			httpclient.DumpFormat |= httpclient.Verbose
		}
		client.FetchLocationResource = cmdLine.FetchResource
	}
	return client, nil
}
func FromCommandLine(cmdLine *cmd.CommandLine) (*API, error) {
	var client *API
	ss := strings.HasPrefix(cmdLine.Command, "ss")
	if cmdLine.RL10 {
		var err error
		if client, err = NewRL10(); err != nil {
			return nil, err
		}
	} else if cmdLine.OAuthToken != "" {
		auth := NewOAuthAuthenticator(cmdLine.OAuthToken, cmdLine.Account)
		if ss {
			auth = NewSSAuthenticator(auth, cmdLine.Account)
		}
		client = New(cmdLine.Host, auth)
	} else if cmdLine.OAuthAccessToken != "" {
		auth := NewTokenAuthenticator(cmdLine.OAuthAccessToken, cmdLine.Account)
		if ss {
			auth = NewSSAuthenticator(auth, cmdLine.Account)
		}
		client = New(cmdLine.Host, auth)
	} else if cmdLine.APIToken != "" {
		auth := NewInstanceAuthenticator(cmdLine.APIToken, cmdLine.Account)
		if ss {
			auth = NewSSAuthenticator(auth, cmdLine.Account)
		}
		client = New(cmdLine.Host, auth)
	} else if cmdLine.Username != "" && cmdLine.Password != "" {
		auth := NewBasicAuthenticator(cmdLine.Username, cmdLine.Password, cmdLine.Account)
		if ss {
			auth = NewSSAuthenticator(auth, cmdLine.Account)
		}
		client = New(cmdLine.Host, auth)
	} else {
		// No auth, used by tests
		client = New(cmdLine.Host, nil)
		httpclient.Insecure = true
	}
	if !cmdLine.ShowHelp && !cmdLine.NoAuth {
		if cmdLine.OAuthToken == "" && cmdLine.OAuthAccessToken == "" && cmdLine.APIToken == "" && cmdLine.Username == "" && !cmdLine.RL10 {
			return nil, fmt.Errorf("Missing authentication information, use '--email EMAIL --password PWD', '--token TOKEN' or 'setup'")
		}
		if cmdLine.Verbose || cmdLine.Dump == "debug" {
			httpclient.DumpFormat = httpclient.Debug
		}
		if cmdLine.Dump == "json" {
			httpclient.DumpFormat = httpclient.JSON
		}
		if cmdLine.Dump == "record" {
			httpclient.DumpFormat = httpclient.JSON | httpclient.Record
		}
		if cmdLine.Verbose {
			httpclient.DumpFormat |= httpclient.Verbose
		}
		client.FetchLocationResource = cmdLine.FetchResource
	}
	return client, nil
}
// FromCommandLine builds an API client from the command line.