Skip to content

Commit

Permalink
fix: correct format fields
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickMenoti committed Jul 12, 2024
1 parent 01e3de9 commit 7580f36
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 69 deletions.
26 changes: 18 additions & 8 deletions pkg/cmd/list/cache_setting/cache_setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,29 @@ func PrintTable(cmd *cobra.Command, f *cmdutil.Factory, opts *contracts.ListOpti
listOut.Out = f.IOStreams.Out
listOut.Flags = f.Flags

if cmd.Flags().Changed("details") {
if opts.Details {
listOut.Columns = []string{"ID", "NAME", "BROWSER CACHE SETTINGS", "CDN CACHE SETTINGS", "CACHE BY COOKIES", "ENABLE CACHING FOR POST"}
}

for _, v := range cache.Results {
ln := []string{
fmt.Sprintf("%d", v.Id),
v.Name,
v.BrowserCacheSettings,
v.CdnCacheSettings,
v.CacheByCookies,
fmt.Sprintf("%v", v.EnableCachingForPost),
ln := []string{}
if opts.Details {
ln = []string{
fmt.Sprintf("%d", v.Id),
v.Name,
v.BrowserCacheSettings,
v.CdnCacheSettings,
v.CacheByCookies,
fmt.Sprintf("%v", v.EnableCachingForPost),
}
} else {
ln = []string{
fmt.Sprintf("%d", v.Id),
v.Name,
v.BrowserCacheSettings,
}
}

listOut.Lines = append(listOut.Lines, ln)
}

Expand Down
27 changes: 18 additions & 9 deletions pkg/cmd/list/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,25 @@ func PrintTable(cmd *cobra.Command, f *cmdutil.Factory, opts *contracts.ListOpti
}

for _, v := range resp.Results {
ln := []string{
fmt.Sprintf("%d", v.GetId()),
utils.TruncateString(v.GetName()),
v.GetDomainName(),
fmt.Sprintf("%d", v.GetDigitalCertificateId()),
fmt.Sprintf("%d", v.GetDigitalCertificateId()),
fmt.Sprintf("%v", v.GetCnameAccessOnly()),
fmt.Sprintf("%v", v.GetCnames()),
fmt.Sprintf("%v", v.GetIsActive()),
ln := []string{}
if opts.Details {
ln = []string{
fmt.Sprintf("%d", v.GetId()),
utils.TruncateString(v.GetName()),
v.GetDomainName(),
fmt.Sprintf("%d", v.GetDigitalCertificateId()),
fmt.Sprintf("%d", v.GetDigitalCertificateId()),
fmt.Sprintf("%v", v.GetCnameAccessOnly()),
fmt.Sprintf("%v", v.GetCnames()),
fmt.Sprintf("%v", v.GetIsActive()),
}
} else {
ln = []string{
fmt.Sprintf("%d", v.GetId()),
utils.TruncateString(v.GetName()),
}
}

listOut.Lines = append(listOut.Lines, ln)
}

Expand Down
24 changes: 17 additions & 7 deletions pkg/cmd/list/edge_applications/edge_applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,24 @@ func PrintTable(cmd *cobra.Command, client *api.Client, f *cmdutil.Factory, opts
}

for _, v := range resp.Results {
ln := []string{
fmt.Sprintf("%d", v.Id),
utils.TruncateString(v.Name),
fmt.Sprintf("%v", v.Active),
v.LastEditor,
v.LastModified,
fmt.Sprintf("%v", v.DebugRules),
ln := []string{}
if opts.Details {
ln = []string{
fmt.Sprintf("%d", v.Id),
utils.TruncateString(v.Name),
fmt.Sprintf("%v", v.Active),
v.LastEditor,
v.LastModified,
fmt.Sprintf("%v", v.DebugRules),
}
} else {
ln = []string{
fmt.Sprintf("%d", v.Id),
utils.TruncateString(v.Name),
fmt.Sprintf("%v", v.Active),
}
}

listOut.Lines = append(listOut.Lines, ln)
}

Expand Down
28 changes: 19 additions & 9 deletions pkg/cmd/list/edge_function/edge_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,25 @@ func PrintTable(cmd *cobra.Command, f *cmdutil.Factory, opts *contracts.ListOpti
}

for _, v := range functions.Results {
ln := []string{
fmt.Sprintf("%d", v.GetId()),
v.GetName(),
v.GetLanguage(),
fmt.Sprintf("%v", v.GetActive()),
v.GetLastEditor(),
v.GetModified(),
fmt.Sprintf("%d", v.GetReferenceCount()),
v.GetInitiatorType(),
ln := []string{}
if opts.Details {
ln = []string{
fmt.Sprintf("%d", v.GetId()),
v.GetName(),
v.GetLanguage(),
fmt.Sprintf("%v", v.GetActive()),
v.GetLastEditor(),
v.GetModified(),
fmt.Sprintf("%d", v.GetReferenceCount()),
v.GetInitiatorType(),
}
} else {
ln = []string{
fmt.Sprintf("%d", v.GetId()),
v.GetName(),
v.GetLanguage(),
fmt.Sprintf("%v", v.GetActive()),
}
}
listOut.Lines = append(listOut.Lines, ln)
}
Expand Down
18 changes: 13 additions & 5 deletions pkg/cmd/list/edge_storage/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,19 @@ func (b *Objects) PrintTable(client *api.Client) error {
}

for _, v := range resp.Results {
ln := []string{
v.GetKey(),
fmt.Sprintf("%v", v.GetLastModified()),
fmt.Sprintf("%v", v.GetSize()),
v.GetEtag(),
ln := []string{}
if b.Options.Details {
ln = []string{
v.GetKey(),
fmt.Sprintf("%v", v.GetLastModified()),
fmt.Sprintf("%v", v.GetSize()),
v.GetEtag(),
}
} else {
ln = []string{
v.GetKey(),
fmt.Sprintf("%v", v.GetLastModified()),
}
}
listOut.Lines = append(listOut.Lines, ln)
}
Expand Down
24 changes: 16 additions & 8 deletions pkg/cmd/list/origin/origin.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,22 @@ func PrintTable(client *api.Client, f *cmdutil.Factory, opts *contracts.ListOpti
}

for _, v := range resp.Results {
ln := []string{
*v.OriginKey,
utils.TruncateString(v.Name),
fmt.Sprintf("%d", *v.OriginId),
*v.OriginType,
*v.OriginPath,
fmt.Sprintf("%v", v.Addresses),
fmt.Sprintf("%d", *v.ConnectionTimeout),
ln := []string{}
if opts.Details {
ln = []string{
*v.OriginKey,
utils.TruncateString(v.Name),
fmt.Sprintf("%d", *v.OriginId),
*v.OriginType,
*v.OriginPath,
fmt.Sprintf("%v", v.Addresses),
fmt.Sprintf("%d", *v.ConnectionTimeout),
}
} else {
ln = []string{
*v.OriginKey,
utils.TruncateString(v.Name),
}
}
listOut.Lines = append(listOut.Lines, ln)
}
Expand Down
29 changes: 19 additions & 10 deletions pkg/cmd/list/personal_token/personal_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,26 @@ func PrintTable(client *api.Client, f *cmdutil.Factory, details bool) error {
}

for _, v := range resp {
var description string
if v.Description.Get() != nil {
description = *v.Description.Get()
}

ln := []string{
*v.Uuid,
utils.TruncateString(*v.Name),
v.ExpiresAt.Format(constants.FORMAT_DATE),
fmt.Sprintf("%v", *v.Created),
utils.TruncateString(description),
ln := []string{}
if details {
var description string
if v.Description.Get() != nil {
description = *v.Description.Get()
}
ln = []string{
*v.Uuid,
utils.TruncateString(*v.Name),
v.ExpiresAt.Format(constants.FORMAT_DATE),
fmt.Sprintf("%v", *v.Created),
utils.TruncateString(description),
}
} else {
ln = []string{
*v.Uuid,
utils.TruncateString(*v.Name),
v.ExpiresAt.Format(constants.FORMAT_DATE),
}
}
listOut.Lines = append(listOut.Lines, ln)
}
Expand Down
22 changes: 15 additions & 7 deletions pkg/cmd/list/rule_engine/rule_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,25 @@ func PrintTable(cmd *cobra.Command, f *cmdutil.Factory, opts *contracts.ListOpti
listOut.Out = f.IOStreams.Out
listOut.Flags = f.Flags

if cmd.Flags().Changed("details") {
if opts.Details {
listOut.Columns = []string{"ID", "NAME", "ORDER", "PHASE", "ACTIVE"}
}

for _, v := range rules.Results {
ln := []string{
fmt.Sprintf("%d", v.Id),
v.Name,
fmt.Sprintf("%d", v.Order),
v.Phase,
fmt.Sprintf("%v", v.IsActive),
ln := []string{}
if opts.Details {
ln = []string{
fmt.Sprintf("%d", v.Id),
v.Name,
fmt.Sprintf("%d", v.Order),
v.Phase,
fmt.Sprintf("%v", v.IsActive),
}
} else {
ln = []string{
fmt.Sprintf("%d", v.Id),
v.Name,
}
}
listOut.Lines = append(listOut.Lines, ln)
}
Expand Down
21 changes: 15 additions & 6 deletions pkg/cmd/list/variables/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,21 @@ func listAllVariables(client *api.Client, f *cmdutil.Factory, opts *contracts.Li
}

for _, v := range resp {
ln := []string{
v.GetUuid(),
v.GetKey(),
utils.TruncateString(v.GetValue()),
fmt.Sprintf("%v", v.GetSecret()),
v.GetLastEditor(),
ln := []string{}
if opts.Details {
ln = []string{
v.GetUuid(),
v.GetKey(),
utils.TruncateString(v.GetValue()),
fmt.Sprintf("%v", v.GetSecret()),
v.GetLastEditor(),
}
} else {
ln = []string{
v.GetUuid(),
v.GetKey(),
utils.TruncateString(v.GetValue()),
}
}

listOut.Lines = append(listOut.Lines, ln)
Expand Down

0 comments on commit 7580f36

Please sign in to comment.