diff --git a/cmd/dev.go b/cmd/dev.go index c86e0b9..8dff64e 100644 --- a/cmd/dev.go +++ b/cmd/dev.go @@ -104,14 +104,12 @@ func getMetadataUpdateBehavior() common.MetadataUpdateEnum { } // HandleSuccess prints a success message according to the configured format (styled table or JSON) -func HandleSuccess(command *cobra.Command, id string, t table.Model, policyObject interface{}, joinable ...table.Model) { +func HandleSuccess(command *cobra.Command, id string, t table.Model, policyObject interface{}) { c := cli.New(command, []string{}) if OtdfctlCfg.Output.Format == config.OutputJSON || configFlagOverrides.OutputFormatJSON { c.ExitWithJSON(policyObject) } - tables := []table.Model{t} - tables = append(tables, joinable...) - cli.PrintSuccessTable(command, id, tables...) + cli.PrintSuccessTable(command, id, t) } // Adds reusable create/update label flags to a Policy command and the optional force-replace-labels flag for updates only diff --git a/cmd/policy-attributes.go b/cmd/policy-attributes.go index 2dde47e..8a3dfc7 100644 --- a/cmd/policy-attributes.go +++ b/cmd/policy-attributes.go @@ -126,9 +126,8 @@ func policy_listAttributes(cmd *cobra.Command, args []string) { })) } t = t.WithRows(rows) - footer := cli.WithListPaginationFooter(t, page) - HandleSuccess(cmd, "", t, attrs, footer) - // cli.WithListPaginationFooter(t, page) + t = cli.WithListPaginationFooter(t, page) + HandleSuccess(cmd, "", t, attrs) } func policy_deactivateAttribute(cmd *cobra.Command, args []string) { diff --git a/pkg/cli/table.go b/pkg/cli/table.go index bfb58d4..7564bf9 100644 --- a/pkg/cli/table.go +++ b/pkg/cli/table.go @@ -39,43 +39,8 @@ func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model info = append(info, fmt.Sprintf("Next Offset: %d", p.GetNextOffset())) } - columns := []table.Column{} - for _, c := range info { - columns = append(columns, table.NewFlexColumn(c, c, FlexColumnWidthOne)) - } - content := strings.Join(info, " | ") - // content := table.New(columns). - // WithBaseStyle(styleTable). - // BorderRounded(). - // WithTargetWidth(len(info) * 20). - // WithNoPagination().View() leftAligned := lipgloss.NewStyle().Align(lipgloss.Left) return t.WithStaticFooter(content).WithBaseStyle(leftAligned) } - -// func WithListPaginationFooter(t table.Model, p *policy.PageResponse) table.Model { -// info := []string{ -// fmt.Sprintf("Total: %d", p.GetTotal()), -// fmt.Sprintf("Current Offset: %d", p.GetCurrentOffset()), -// } -// if p.GetNextOffset() > 0 { -// info = append(info, fmt.Sprintf("Next Offset: %d", p.GetNextOffset())) -// } - -// columns := []table.Column{} -// for _, c := range info { -// columns = append(columns, table.NewFlexColumn(c, c, FlexColumnWidthOne)) -// } - -// // content := strings.Join(info, " | ") -// content := table.New(columns). -// WithBaseStyle(styleTable). -// BorderRounded(). -// WithTargetWidth(len(info) * 20). -// WithNoPagination() - -// // fmt.Println(lipgloss.JoinVertical(lipgloss.Left, t.View(), content.View())) -// return content -// } diff --git a/pkg/cli/tabular.go b/pkg/cli/tabular.go index 7038573..9a9343c 100644 --- a/pkg/cli/tabular.go +++ b/pkg/cli/tabular.go @@ -47,7 +47,7 @@ func getJSONHelper(command string) string { return fmt.Sprintf("Use '%s --json' to see all properties", command) } -func PrintSuccessTable(cmd *cobra.Command, id string, joinableTables ...table.Model) { +func PrintSuccessTable(cmd *cobra.Command, id string, t table.Model) { parent := cmd.Parent() resourceShort := parent.Use resource := parent.Use @@ -88,18 +88,11 @@ func PrintSuccessTable(cmd *cobra.Command, id string, joinableTables ...table.Mo successMessage := SuccessMessage(msg.verb) jsonDirections := FooterMessage(msg.helper) - if len(joinableTables) == 0 { + ts := t.View() + if ts == "" { fmt.Println(lipgloss.JoinVertical(lipgloss.Top, successMessage, jsonDirections)) return } - printable := []string{ - successMessage, - } - for _, t := range joinableTables { - printable = append(printable, t.View()) - } - printable = append(printable, jsonDirections) - - fmt.Println(lipgloss.JoinVertical(lipgloss.Top, printable...)) + fmt.Println(lipgloss.JoinVertical(lipgloss.Top, successMessage, ts, jsonDirections)) }