status

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Command = &cobra.Command{
	Use:   "status",
	Short: "Show CLI configuration, auth source, account, and quota status",
	Args:  cobra.NoArgs,
	Run: func(cmd *cobra.Command, args []string) {
		if !slices.Contains(formats, flags.format) {
			timber.FatalMsg("invalid output format", timber.A("value", flags.format), timber.A("valid", strings.Join(formats, "|")))
		}

		config, err := conf.Read()
		if err != nil {
			app.Fatal(err, "failed to read configuration file")
		}
		defaults := synthient.NewClient("")
		baseAPI := defaults.BaseAPI.String()
		baseFeeds := defaults.BaseFeeds.String()
		if config.BaseApiURL != nil {
			baseAPI = config.BaseApiURL.String()
		}
		if config.BaseFeedsURL != nil {
			baseFeeds = config.BaseFeedsURL.String()
		}

		result := Result{
			ConfigPath:   config.Path,
			Profile:      config.Profile,
			AuthSource:   auth.ReadCredentialsStatus().Source,
			BaseAPI:      baseAPI,
			BaseFeeds:    baseFeeds,
			BaseGRPC:     config.GRPCEndpoint(synthient.DefaultGRPCEndpoint),
			AccountError: "",
		}

		client, err := auth.SynthientClient(config)
		if err == nil {
			config.ApplyToClient(&client)
			account, accountErr := client.GetAccount(nil)
			if accountErr == nil {
				result.Authenticated = true
				result.AccountReachable = true
				result.AccountEmail = account.Email
				result.Organization = account.Organization.Name
				result.LookupCredits = account.LookupQuota.Credits
				result.QuotaResetsIn = account.LookupQuota.ResetsIn
				result.Scopes = account.Scopes
			} else {
				result.AccountError = app.Explain(accountErr)
				if result.AccountError == "" {
					result.AccountError = accountErr.Error()
				}
			}
		} else {
			result.AccountError = app.Explain(err)
		}

		out, closeOut := output.Open(flags.output)
		defer closeOut()
		switch flags.format {
		case "text":
			writeText(out, result)
		case "json":
			output.JSON(out, result)
		case "csv":
			writer := csv.NewWriter(out)
			err := writer.Write([]string{"config_path", "profile", "base_api", "base_feeds", "base_grpc", "auth_source", "authenticated", "account_email", "organization", "lookup_credits", "quota_resets_in", "scopes", "account_reachable", "account_error"})
			if err != nil {
				app.Fatal(err, "failed to write csv header")
			}
			err = writer.Write([]string{
				result.ConfigPath,
				result.Profile,
				result.BaseAPI,
				result.BaseFeeds,
				result.BaseGRPC,
				result.AuthSource,
				strconv.FormatBool(result.Authenticated),
				result.AccountEmail,
				result.Organization,
				strconv.Itoa(result.LookupCredits),
				strconv.Itoa(result.QuotaResetsIn),
				strings.Join(result.Scopes, "|"),
				strconv.FormatBool(result.AccountReachable),
				result.AccountError,
			})
			if err != nil {
				app.Fatal(err, "failed to write csv row")
			}
			writer.Flush()
		}
	},
}

Functions

This section is empty.

Types

type Result

type Result struct {
	ConfigPath       string   `json:"config_path"`
	Profile          string   `json:"profile"`
	BaseAPI          string   `json:"base_api"`
	BaseFeeds        string   `json:"base_feeds"`
	BaseGRPC         string   `json:"base_grpc"`
	AuthSource       string   `json:"auth_source"`
	Authenticated    bool     `json:"authenticated"`
	AccountEmail     string   `json:"account_email"`
	Organization     string   `json:"organization"`
	LookupCredits    int      `json:"lookup_credits"`
	QuotaResetsIn    int      `json:"quota_resets_in"`
	Scopes           []string `json:"scopes"`
	AccountReachable bool     `json:"account_reachable"`
	AccountError     string   `json:"account_error"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL