Fix plan list command

The aim of this PS to fix current issue we have when we have
new plan created with description width more than 40 char.
Added condition if width is more than specified in command
so the command execution will not break and just crop
exceeding description length.
Eg: e351b2bc43/pkg/print/table/columndefs.go (L71)

Change-Id: Icc353ec688b2fbb563add39f8d38004008093895
This commit is contained in:
Pallav Gupta 2021-04-14 16:45:28 -07:00
parent 3d26a7fec3
commit 10e75b5580
3 changed files with 38 additions and 11 deletions

View File

@ -166,7 +166,7 @@ type PlanListCommand struct {
Writer io.Writer
}
// RunE runs a phase plan command
// RunE runs a plan list command
func (c *PlanListCommand) RunE() error {
cfg, err := c.Factory()
if err != nil {
@ -192,7 +192,7 @@ func (c *PlanListCommand) RunE() error {
descriptionCol := table.ColumnDef{
ColumnName: "description",
ColumnHeader: "DESCRIPTION",
ColumnWidth: 40,
ColumnWidth: 200,
PrintResourceFunc: func(w io.Writer, width int, r table.Resource) (int, error) {
rs := r.ResourceStatus()
if rs == nil {
@ -203,7 +203,12 @@ func (c *PlanListCommand) RunE() error {
if err != nil {
return 0, err
}
return fmt.Fprint(w, plan.Description)
txt := plan.Description
if len(txt) > width {
txt = txt[:width]
}
_, err = fmt.Fprint(w, txt)
return len(txt), err
},
}
printer.Columns = append(printer.Columns, descriptionCol)

View File

@ -111,9 +111,11 @@ func TestRunCommand(t *testing.T) {
func TestListCommand(t *testing.T) {
outputString1 := "NAMESPACE RESOURCE CLUSTER " +
"NAME EXECUTOR DOC ENTRYPOINT "
"NAME EXECUTOR DOC ENTRYPOINT " +
" "
outputString2 := " Phase/phase ephemeral" +
"-cluster KubernetesApply ephemeral/phase "
"-cluster KubernetesApply ephemeral/phase " +
" "
yamlOutput := `---
- apiVersion: airshipit.org/v1alpha1
config:
@ -348,8 +350,13 @@ func TestPlanListCommand(t *testing.T) {
return conf, nil
},
expectedOut: [][]byte{
[]byte("NAMESPACE RESOURCE DESCRIPTION "),
[]byte(" PhasePlan/phasePlan Default phase plan "),
[]byte("NAMESPACE RESOURCE DESCRIPTION " +
" " +
" "),
[]byte(" PhasePlan/phasePlan Default phase plan" +
" " +
" " +
" "),
{},
},
},

View File

@ -44,7 +44,12 @@ func PrintPhaseListTable(w io.Writer, phases []*v1alpha1.Phase) error {
if err != nil {
return 0, nil
}
return fmt.Fprintf(w, phase.ClusterName)
txt := phase.ClusterName
if len(txt) > width {
txt = txt[:width]
}
_, err = fmt.Fprintf(w, txt)
return len(txt), err
},
}
executorrefkindCol := table.ColumnDef{
@ -57,20 +62,30 @@ func PrintPhaseListTable(w io.Writer, phases []*v1alpha1.Phase) error {
if err != nil {
return 0, nil
}
return fmt.Fprintf(w, phase.Config.ExecutorRef.Kind)
txt := phase.Config.ExecutorRef.Kind
if len(txt) > width {
txt = txt[:width]
}
_, err = fmt.Fprintf(w, txt)
return len(txt), err
},
}
docentrypointCol := table.ColumnDef{
ColumnName: "docentrypoint",
ColumnHeader: "DOC ENTRYPOINT",
ColumnWidth: 40,
ColumnWidth: 100,
PrintResourceFunc: func(w io.Writer, width int, r table.Resource) (int,
error) {
phase, err := phaseFromResource(r)
if err != nil {
return 0, nil
}
return fmt.Fprintf(w, phase.Config.DocumentEntryPoint)
txt := phase.Config.DocumentEntryPoint
if len(txt) > width {
txt = txt[:width]
}
_, err = fmt.Fprintf(w, txt)
return len(txt), err
},
}
printer.Columns = append(printer.Columns, clusternameCol, executorrefkindCol, docentrypointCol)