Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
stgraber committed Aug 12, 2024
1 parent 38add68 commit 7c61442
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions cmd/incus/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (c *cmdOperationList) Command() *cobra.Command {
cmd.Short = i18n.G("List background operations")
cmd.Long = cli.FormatSection(i18n.G("Description"), i18n.G(
`List background operations
Default column layout: itdscCl
== Columns ==
Expand All @@ -132,7 +132,7 @@ Pre-defined column shorthand chars:
s - State
c - Cancelable
C - Created
l - Location(clustered only)`))
L - Location of the operation (e.g. its cluster member)`))
cmd.Flags().StringVarP(&c.flagFormat, "format", "f", "table", i18n.G("Format (csv|json|table|yaml|compact)")+"``")
cmd.Flags().BoolVar(&c.flagAllProjects, "all-projects", false, i18n.G("List operations from all projects")+"``")
cmd.Flags().StringVarP(&c.flagColumns, "columns", "c", defaultOperationColumns, i18n.G("Columns")+"``")
Expand All @@ -142,22 +142,24 @@ Pre-defined column shorthand chars:
return cmd
}

const defaultOperationColumns = "itdscCl"
const defaultOperationColumns = "itdscC"

func (c *cmdOperationList) parseColumns() ([]operationColumn, error) {
func (c *cmdOperationList) parseColumns(clustered bool) ([]operationColumn, error) {
columnsShorthandMap := map[rune]operationColumn{
'i': {i18n.G("ID"), c.operationIDcolumnData},
't': {i18n.G("TYPE"), c.typeColumnData},
'd': {i18n.G("DESCRIPTION"), c.descriptionColumnData},
's': {i18n.G("STATE"), c.stateColumnData},
'c': {i18n.G("CANCELABLE"), c.cancelableColumnData},
'C': {i18n.G("CREATED"), c.createdColumnData},
'l': {i18n.G("LOCATION"), c.locationColumnData},
'L': {i18n.G("LOCATION"), c.locationColumnData},
}

columnList := strings.Split(c.flagColumns, ",")

columns := []operationColumn{}
if c.flagColumns == defaultOperationColumns && clustered {
columnList = append(columnList, "L")
}

for _, columnEntry := range columnList {
if columnEntry == "" {
Expand Down Expand Up @@ -247,7 +249,7 @@ func (c *cmdOperationList) Run(cmd *cobra.Command, args []string) error {
}

// Parse column flags.
columns, err := c.parseColumns()
columns, err := c.parseColumns(resource.server.IsClustered())
if err != nil {
return err
}
Expand All @@ -257,14 +259,7 @@ func (c *cmdOperationList) Run(cmd *cobra.Command, args []string) error {
for _, op := range operations {
line := []string{}
for _, column := range columns {
if column.Name == i18n.G("LOCATION") {
if resource.server.IsClustered() {
line = append(line, column.Data(op))
}

} else {
line = append(line, column.Data(op))
}
line = append(line, column.Data(op))
}

data = append(data, line)
Expand All @@ -274,15 +269,7 @@ func (c *cmdOperationList) Run(cmd *cobra.Command, args []string) error {

header := []string{}
for _, column := range columns {
if column.Name == "LOCATION" {
if resource.server.IsClustered() {
header = append(header, column.Name)
}

} else {
header = append(header, column.Name)
}

header = append(header, column.Name)
}

return cli.RenderTable(c.flagFormat, header, data, operations)
Expand Down

0 comments on commit 7c61442

Please sign in to comment.