當前位置: 首頁>>代碼示例>>Golang>>正文


Golang columnize.DefaultConfig函數代碼示例

本文整理匯總了Golang中github.com/ryanuber/columnize.DefaultConfig函數的典型用法代碼示例。如果您正苦於以下問題:Golang DefaultConfig函數的具體用法?Golang DefaultConfig怎麽用?Golang DefaultConfig使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了DefaultConfig函數的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: OutputList

func (t TableFormatter) OutputList(ui cli.Ui, secret *api.Secret, list []interface{}) error {
	config := columnize.DefaultConfig()
	config.Delim = "♨"
	config.Glue = "\t"
	config.Prefix = ""

	input := make([]string, 0, 5)

	input = append(input, "Keys")

	keys := make([]string, 0, len(list))
	for _, k := range list {
		keys = append(keys, k.(string))
	}
	sort.Strings(keys)

	for _, k := range keys {
		input = append(input, fmt.Sprintf("%s", k))
	}

	if len(secret.Warnings) != 0 {
		input = append(input, "")
		input = append(input, "The following warnings were returned from the Vault server:")
		for _, warning := range secret.Warnings {
			input = append(input, fmt.Sprintf("* %s", warning))
		}
	}

	ui.Output(columnize.Format(input, config))
	return nil
}
開發者ID:faradayio,項目名稱:vault-1,代碼行數:31,代碼來源:format.go

示例2: outputFormatTableList

func outputFormatTableList(ui cli.Ui, s *api.Secret) int {
	config := columnize.DefaultConfig()
	config.Delim = "♨"
	config.Glue = "\t"
	config.Prefix = ""

	input := make([]string, 0, 5)

	input = append(input, "Keys")

	keys := make([]string, 0, len(s.Data["keys"].([]interface{})))
	for _, k := range s.Data["keys"].([]interface{}) {
		keys = append(keys, k.(string))
	}
	sort.Strings(keys)

	for _, k := range keys {
		input = append(input, fmt.Sprintf("%s", k))
	}

	if len(s.Warnings) != 0 {
		input = append(input, "")
		for _, warning := range s.Warnings {
			input = append(input, fmt.Sprintf("* %s", warning))
		}
	}

	ui.Output(columnize.Format(input, config))
	return 0
}
開發者ID:thomaso-mirodin,項目名稱:vault,代碼行數:30,代碼來源:format.go

示例3: outputFormatTable

func outputFormatTable(ui cli.Ui, s *api.Secret, whitespace bool) int {
	config := columnize.DefaultConfig()
	config.Delim = "♨"
	config.Glue = "\t"
	config.Prefix = ""

	input := make([]string, 0, 5)
	input = append(input, fmt.Sprintf("Key %s Value", config.Delim))

	if s.LeaseID != "" && s.LeaseDuration > 0 {
		input = append(input, fmt.Sprintf("lease_id %s %s", config.Delim, s.LeaseID))
		input = append(input, fmt.Sprintf(
			"lease_duration %s %d", config.Delim, s.LeaseDuration))
		input = append(input, fmt.Sprintf(
			"lease_renewable %s %s", config.Delim, strconv.FormatBool(s.Renewable)))
	}

	if s.Auth != nil {
		input = append(input, fmt.Sprintf("token %s %s", config.Delim, s.Auth.ClientToken))
		input = append(input, fmt.Sprintf("token_duration %s %d", config.Delim, s.Auth.LeaseDuration))
		input = append(input, fmt.Sprintf("token_renewable %s %v", config.Delim, s.Auth.Renewable))
		input = append(input, fmt.Sprintf("token_policies %s %v", config.Delim, s.Auth.Policies))
		for k, v := range s.Auth.Metadata {
			input = append(input, fmt.Sprintf("token_meta_%s %s %#v", k, config.Delim, v))
		}
	}

	for k, v := range s.Data {
		input = append(input, fmt.Sprintf("%s %s %v", k, config.Delim, v))
	}

	ui.Output(columnize.Format(input, config))
	return 0
}
開發者ID:worldspawn,項目名稱:vault,代碼行數:34,代碼來源:format.go

示例4: Run

func (c *StateShowCommand) Run(args []string) int {
	args = c.Meta.process(args, true)

	cmdFlags := c.Meta.flagSet("state show")
	cmdFlags.StringVar(&c.Meta.statePath, "state", DefaultStateFilename, "path")
	if err := cmdFlags.Parse(args); err != nil {
		return cli.RunResultHelp
	}
	args = cmdFlags.Args()

	state, err := c.Meta.State()
	if err != nil {
		c.Ui.Error(fmt.Sprintf(errStateLoadingState, err))
		return cli.RunResultHelp
	}

	stateReal := state.State()
	if stateReal == nil {
		c.Ui.Error(fmt.Sprintf(errStateNotFound))
		return 1
	}

	filter := &terraform.StateFilter{State: stateReal}
	results, err := filter.Filter(args...)
	if err != nil {
		c.Ui.Error(fmt.Sprintf(errStateFilter, err))
		return 1
	}

	instance, err := c.filterInstance(results)
	if err != nil {
		c.Ui.Error(err.Error())
		return 1
	}
	is := instance.Value.(*terraform.InstanceState)

	// Sort the keys
	keys := make([]string, 0, len(is.Attributes))
	for k, _ := range is.Attributes {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	// Build the output
	output := make([]string, 0, len(is.Attributes)+1)
	output = append(output, fmt.Sprintf("id | %s", is.ID))
	for _, k := range keys {
		if k != "id" {
			output = append(output, fmt.Sprintf("%s | %s", k, is.Attributes[k]))
		}
	}

	// Output
	config := columnize.DefaultConfig()
	config.Glue = " = "
	c.Ui.Output(columnize.Format(output, config))
	return 0
}
開發者ID:RezaDKhan,項目名稱:terraform,代碼行數:58,代碼來源:state_show.go

示例5: OutputSecret

func (t TableFormatter) OutputSecret(ui cli.Ui, secret, s *api.Secret) error {
	config := columnize.DefaultConfig()
	config.Delim = "♨"
	config.Glue = "\t"
	config.Prefix = ""

	input := make([]string, 0, 5)

	input = append(input, fmt.Sprintf("Key %s Value", config.Delim))

	if s.LeaseDuration > 0 {
		if s.LeaseID != "" {
			input = append(input, fmt.Sprintf("lease_id %s %s", config.Delim, s.LeaseID))
		}
		input = append(input, fmt.Sprintf(
			"lease_duration %s %d", config.Delim, s.LeaseDuration))
		if s.LeaseID != "" {
			input = append(input, fmt.Sprintf(
				"lease_renewable %s %s", config.Delim, strconv.FormatBool(s.Renewable)))
		}
	}

	if s.Auth != nil {
		input = append(input, fmt.Sprintf("token %s %s", config.Delim, s.Auth.ClientToken))
		input = append(input, fmt.Sprintf("token_accessor %s %s", config.Delim, s.Auth.Accessor))
		input = append(input, fmt.Sprintf("token_duration %s %d", config.Delim, s.Auth.LeaseDuration))
		input = append(input, fmt.Sprintf("token_renewable %s %v", config.Delim, s.Auth.Renewable))
		input = append(input, fmt.Sprintf("token_policies %s %v", config.Delim, s.Auth.Policies))
		for k, v := range s.Auth.Metadata {
			input = append(input, fmt.Sprintf("token_meta_%s %s %#v", k, config.Delim, v))
		}
	}

	keys := make([]string, 0, len(s.Data))
	for k := range s.Data {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	for _, k := range keys {
		input = append(input, fmt.Sprintf("%s %s %v", k, config.Delim, s.Data[k]))
	}

	if len(s.Warnings) != 0 {
		input = append(input, "")
		input = append(input, "The following warnings were returned from the Vault server:")
		for _, warning := range s.Warnings {
			input = append(input, fmt.Sprintf("* %s", warning))
		}
	}

	ui.Output(columnize.Format(input, config))
	return nil
}
開發者ID:hashbrowncipher,項目名稱:vault,代碼行數:54,代碼來源:format.go

示例6: OutputList

func (t TableFormatter) OutputList(ui cli.Ui, secret *api.Secret, list []interface{}) error {
	config := columnize.DefaultConfig()
	config.Delim = "♨"
	config.Glue = "\t"
	config.Prefix = ""

	input := make([]string, 0, 5)

	if len(list) > 0 {
		input = append(input, "Keys")
		input = append(input, "----")

		keys := make([]string, 0, len(list))
		for _, k := range list {
			keys = append(keys, k.(string))
		}
		sort.Strings(keys)

		for _, k := range keys {
			input = append(input, fmt.Sprintf("%s", k))
		}
	}

	tableOutputStr := columnize.Format(input, config)

	// Print the warning separately because the length of first
	// column in the output will be increased by the length of
	// the longest warning string making the output look bad.
	warningsInput := make([]string, 0, 5)
	if len(secret.Warnings) != 0 {
		warningsInput = append(warningsInput, "")
		warningsInput = append(warningsInput, "The following warnings were returned from the Vault server:")
		for _, warning := range secret.Warnings {
			warningsInput = append(warningsInput, fmt.Sprintf("* %s", warning))
		}
	}

	warningsOutputStr := columnize.Format(warningsInput, config)

	ui.Output(fmt.Sprintf("%s\n%s", tableOutputStr, warningsOutputStr))

	return nil
}
開發者ID:quixoten,項目名稱:vault,代碼行數:43,代碼來源:format.go

示例7: formatKV

// formatKV takes a set of strings and formats them into properly
// aligned k = v pairs using the columnize library.
func formatKV(in []string) string {
	columnConf := columnize.DefaultConfig()
	columnConf.Empty = "<none>"
	columnConf.Glue = " = "
	return columnize.Format(in, columnConf)
}
開發者ID:bastiaanb,項目名稱:nomad,代碼行數:8,代碼來源:helpers.go

示例8: formatListWithSpaces

// formatListWithSpaces takes a set of strings and formats them into properly
// aligned output. It should be used sparingly since it doesn't replace empty
// values and hence not awk/sed friendly
func formatListWithSpaces(in []string) string {
	columnConf := columnize.DefaultConfig()
	return columnize.Format(in, columnConf)
}
開發者ID:achanda,項目名稱:nomad,代碼行數:7,代碼來源:helpers.go

示例9: OutputSecret

func (t TableFormatter) OutputSecret(ui cli.Ui, secret, s *api.Secret) error {
	config := columnize.DefaultConfig()
	config.Delim = "♨"
	config.Glue = "\t"
	config.Prefix = ""

	input := make([]string, 0, 5)

	input = append(input, fmt.Sprintf("Key %s Value", config.Delim))

	input = append(input, fmt.Sprintf("--- %s -----", config.Delim))

	if s.LeaseDuration > 0 {
		if s.LeaseID != "" {
			input = append(input, fmt.Sprintf("lease_id %s %s", config.Delim, s.LeaseID))
			input = append(input, fmt.Sprintf(
				"lease_duration %s %d", config.Delim, s.LeaseDuration))
		} else {
			input = append(input, fmt.Sprintf(
				"refresh_interval %s %d", config.Delim, s.LeaseDuration))
		}
		if s.LeaseID != "" {
			input = append(input, fmt.Sprintf(
				"lease_renewable %s %s", config.Delim, strconv.FormatBool(s.Renewable)))
		}
	}

	if s.Auth != nil {
		input = append(input, fmt.Sprintf("token %s %s", config.Delim, s.Auth.ClientToken))
		input = append(input, fmt.Sprintf("token_accessor %s %s", config.Delim, s.Auth.Accessor))
		input = append(input, fmt.Sprintf("token_duration %s %d", config.Delim, s.Auth.LeaseDuration))
		input = append(input, fmt.Sprintf("token_renewable %s %v", config.Delim, s.Auth.Renewable))
		input = append(input, fmt.Sprintf("token_policies %s %v", config.Delim, s.Auth.Policies))
		for k, v := range s.Auth.Metadata {
			input = append(input, fmt.Sprintf("token_meta_%s %s %#v", k, config.Delim, v))
		}
	}

	if s.WrapInfo != nil {
		input = append(input, fmt.Sprintf("wrapping_token: %s %s", config.Delim, s.WrapInfo.Token))
		input = append(input, fmt.Sprintf("wrapping_token_ttl: %s %d", config.Delim, s.WrapInfo.TTL))
		input = append(input, fmt.Sprintf("wrapping_token_creation_time: %s %s", config.Delim, s.WrapInfo.CreationTime.String()))
		if s.WrapInfo.WrappedAccessor != "" {
			input = append(input, fmt.Sprintf("wrapped_accessor: %s %s", config.Delim, s.WrapInfo.WrappedAccessor))
		}
	}

	keys := make([]string, 0, len(s.Data))
	for k := range s.Data {
		keys = append(keys, k)
	}
	sort.Strings(keys)

	for _, k := range keys {
		input = append(input, fmt.Sprintf("%s %s %v", k, config.Delim, s.Data[k]))
	}

	tableOutputStr := columnize.Format(input, config)

	// Print the warning separately because the length of first
	// column in the output will be increased by the length of
	// the longest warning string making the output look bad.
	warningsInput := make([]string, 0, 5)
	if len(s.Warnings) != 0 {
		warningsInput = append(warningsInput, "")
		warningsInput = append(warningsInput, "The following warnings were returned from the Vault server:")
		for _, warning := range s.Warnings {
			warningsInput = append(warningsInput, fmt.Sprintf("* %s", warning))
		}
	}

	warningsOutputStr := columnize.Format(warningsInput, config)

	ui.Output(fmt.Sprintf("%s\n%s", tableOutputStr, warningsOutputStr))

	return nil
}
開發者ID:faradayio,項目名稱:vault-1,代碼行數:77,代碼來源:format.go


注:本文中的github.com/ryanuber/columnize.DefaultConfig函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。