<commit_before>package cmd

import (
	"fmt"
	"os"

	"strings"
	"time"

	"github.com/getcarina/carina/client"
	"github.com/getcarina/carina/common"
	"github.com/getcarina/carina/version"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var cxt *context

var rootCmd = &cobra.Command{
	Use:   "carina",
	Short: "Create and interact with clusters on both Rackspace Public and Private Cloud",
	Long:  "Create and interact with clusters on both Rackspace Public and Private Cloud",
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		err := cxt.initialize()
		if err != nil {
			return err
		}

		return checkIsLatest()
	},
}

// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
	if err := rootCmd.Execute(); err != nil {
		os.Exit(-1)
	}
}

func init() {
	cxt = &context{}

	authHelp := `Authentication:
The user credentials are used to automatically detect the cloud with which the cli should communicate. First, it looks for the Rackspace Public Cloud environment variables, such as CARINA_USERNAME/CARINA_APIKEY or RS_USERNAME/RS_API_KEY. Then it looks for Rackspace Private Cloud environment variables, such as OS_USERNAME/OS_PASSWORD. Use --cloud flag to explicitly select a cloud.

In the following example, the detected cloud is 'private' because --password is specified:
    carina --username bob --password <PASSWORD> --project admin --auth-endpoint http://example.com/auth/v3 ls

In the following example, the detected cloud is 'public' because --apikey is specified:
    carina --username bob --apikey abc123 ls

In the following example, 'private' is used, even though the Rackspace Public Cloud environment variables are present, because the --cloud is specified:
    carina --cloud private ls

Profiles:
Credentials can be saved under a profile name in CARINA_HOME/config then used with the --profile flag. If --profile is not specified, and the config file contains a profile named 'default', it will be used when no other credential flags are provided.

Below is a sample config file:

    [default]
    cloud=public
    username=bob
    apikey=abc123

    [dev]
    cloud=private
    username=bob
    password-var=<PASSWORD>
    project=admin
    auth-endpoint=http://example.com/auth/v3

In the following example, the default profile is used to authenticate because no other credentials were provided:
    carina ls

In the following example, the dev profile is used to authenticate:
    carina --profile dev ls

See https://github.com/getcarina/carina for additional documentation, FAQ and examples
`

	baseDir, err := client.GetCredentialsDir()
	if err != nil {
		panic(err)
	}
	envHelp := fmt.Sprintf(`Environment Variables:<commit_msg>Fix sample config in --help text<commit_after>package cmd

import (
	"fmt"
	"os"

	"strings"
	"time"

	"github.com/getcarina/carina/client"
	"github.com/getcarina/carina/common"
	"github.com/getcarina/carina/version"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

var cxt *context

var rootCmd = &cobra.Command{
	Use:   "carina",
	Short: "Create and interact with clusters on both Rackspace Public and Private Cloud",
	Long:  "Create and interact with clusters on both Rackspace Public and Private Cloud",
	PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
		err := cxt.initialize()
		if err != nil {
			return err
		}

		return checkIsLatest()
	},
}

// Execute adds all child commands to the root command sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
	if err := rootCmd.Execute(); err != nil {
		os.Exit(-1)
	}
}

func init() {
	cxt = &context{}

	authHelp := `Authentication:
The user credentials are used to automatically detect the cloud with which the cli should communicate. First, it looks for the Rackspace Public Cloud environment variables, such as CARINA_USERNAME/CARINA_APIKEY or RS_USERNAME/RS_API_KEY. Then it looks for Rackspace Private Cloud environment variables, such as OS_USERNAME/OS_PASSWORD. Use --cloud flag to explicitly select a cloud.

In the following example, the detected cloud is 'private' because --password is specified:
    carina --username bob --password <PASSWORD> --project admin --auth-endpoint http://example.com/auth/v3 ls

In the following example, the detected cloud is 'public' because --apikey is specified:
    carina --username bob --apikey abc123 ls

In the following example, 'private' is used, even though the Rackspace Public Cloud environment variables are present, because the --cloud is specified:
    carina --cloud private ls

Profiles:
Credentials can be saved under a profile name in CARINA_HOME/config then used with the --profile flag. If --profile is not specified, and the config file contains a profile named 'default', it will be used when no other credential flags are provided.

Below is a sample config file:

    [default]
    cloud="public"
    username="alicia"
    apikey="abc123"

    [dev]
    cloud="private"
    username-var="OS_USERNAME"
    password-var="<PASSWORD>"
    auth-endpoint-var="OS_AUTH_URL"
    tenant-var="OS_TENANT_NAME"
    project-var="OS_PROJECT_NAME"
    domain-var="OS_PROJECT_DOMAIN_NAME"

In the following example, the default profile is used to authenticate because no other credentials were explicitly provided:
    carina ls

In the following example, the dev profile is used to authenticate:
    carina --profile dev ls

See https://github.com/getcarina/carina for additional documentation, FAQ and examples
`

	baseDir, err := client.GetCredentialsDir()
	if err != nil {
		panic(err)
	}
	envHelp := fmt.Sprintf(`Environment Variables:
{'fraction_non_alphanumeric': 0.08832752613240417, 'fraction_numerical': 0.004355400696864111, 'mean_word_length': 3.987836663770634, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2581095', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1675, 'n_words': 667}