-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #982 from Scalingo/feat/968/maintenance-listing
Add maintenance listing
- Loading branch information
Showing
4 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/urfave/cli/v2" | ||
|
||
"github.com/Scalingo/cli/db/maintenance" | ||
"github.com/Scalingo/cli/detect" | ||
"github.com/Scalingo/cli/utils" | ||
scalingo "github.com/Scalingo/go-scalingo/v6" | ||
) | ||
|
||
var databaseMaintenanceList = cli.Command{ | ||
Name: "database-maintenance-list", | ||
Category: "Addons Maintenance", | ||
Usage: "List the past and future maintenance on the given database", | ||
Flags: []cli.Flag{ | ||
&appFlag, | ||
&addonFlag, | ||
&cli.IntFlag{Name: "page", Usage: "Page to display", Value: 1}, | ||
&cli.IntFlag{Name: "per-page", Usage: "Number of deployments to display", Value: 20}, | ||
}, | ||
Description: CommandDescription{ | ||
Description: "List database maintenance", | ||
Examples: []string{ | ||
"scalingo --app my-app --addon addon-uuid database-maintenance-list", | ||
"scalingo --app my-app --addon addon-uuid database-maintenance-list --per-page 20 --page 5", | ||
}, | ||
}.Render(), | ||
|
||
Action: func(c *cli.Context) error { | ||
currentApp := detect.CurrentApp(c) | ||
utils.CheckForConsent(c.Context, currentApp, utils.ConsentTypeDBs) | ||
addonName := addonUUIDFromFlags(c, currentApp, true) | ||
|
||
err := maintenance.List(c.Context, currentApp, addonName, scalingo.PaginationOpts{ | ||
Page: c.Int("page"), | ||
PerPage: c.Int("per-page"), | ||
}) | ||
if err != nil { | ||
errorQuit(err) | ||
} | ||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package maintenance | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/olekukonko/tablewriter" | ||
|
||
"github.com/Scalingo/cli/config" | ||
"github.com/Scalingo/cli/io" | ||
"github.com/Scalingo/cli/utils" | ||
"github.com/Scalingo/go-scalingo/v6" | ||
"github.com/Scalingo/go-utils/errors/v2" | ||
) | ||
|
||
func List(ctx context.Context, app string, addonName string, paginationOpts scalingo.PaginationOpts) error { | ||
c, err := config.ScalingoClient(ctx) | ||
if err != nil { | ||
return errors.Notef(ctx, err, "get Scalingo client") | ||
} | ||
|
||
response, err := c.DatabaseListMaintenance(ctx, app, addonName, paginationOpts) | ||
if err != nil { | ||
return errors.Notef(ctx, err, "list the database maintenance") | ||
} | ||
|
||
t := tablewriter.NewWriter(os.Stdout) | ||
t.SetHeader([]string{"ID", "Type", "Started At", "Ended At", "Status"}) | ||
|
||
for _, maintenance := range response.Maintenance { | ||
startedAt := "Not started" | ||
if maintenance.StartedAt != nil { | ||
startedAt = maintenance.StartedAt.Local().Format(utils.TimeFormat) | ||
} | ||
|
||
endedAt := "" | ||
if maintenance.EndedAt != nil { | ||
endedAt = maintenance.EndedAt.Local().Format(utils.TimeFormat) | ||
} | ||
|
||
t.Append([]string{ | ||
maintenance.ID, | ||
string(maintenance.Type), | ||
startedAt, | ||
endedAt, | ||
string(maintenance.Status), | ||
}) | ||
} | ||
t.Render() | ||
fmt.Fprintln(os.Stderr, io.Gray(fmt.Sprintf("Page: %d, Last Page: %d", response.Meta.CurrentPage, response.Meta.TotalPages))) | ||
return nil | ||
} |