MCPcopy Create free account
hub / github.com/Scalingo/cli / GetDatabaseFromArgs

Function GetDatabaseFromArgs

detect/app.go:55–72  ·  view source on GitHub ↗

GetDatabaseFromArgs resolves the database name and addon ID from command arguments. If no positional argument is provided, it uses the --database flag. If one positional argument is provided, it uses it as the database name. Returns ErrTooManyArguments if more than one argument is provided.

(ctx context.Context, c *cli.Command)

Source from the content-addressed store, hash-verified

53// If one positional argument is provided, it uses it as the database name.
54// Returns ErrTooManyArguments if more than one argument is provided.
55func GetDatabaseFromArgs(ctx context.Context, c *cli.Command) (string, string, error) {
56 switch c.Args().Len() {
57 case 0:
58 // No positional arg, database from --database flag
59 databaseName, addonID := GetCurrentDatabase(ctx, c)
60 return databaseName, addonID, nil
61 case 1:
62 // database-name provided as positional arg
63 databaseName := c.Args().First()
64 addonID, err := GetAddonIDFromDatabase(ctx, databaseName)
65 if err != nil {
66 return "", "", errors.Wrapf(ctx, err, "fail to resolve addon ID for database %s", databaseName)
67 }
68 return databaseName, addonID, nil
69 default:
70 return "", "", ErrTooManyArguments
71 }
72}
73
74// GetCurrentDatabase is a helper to get the current database name and UUID.
75func GetCurrentDatabase(ctx context.Context, c *cli.Command) (string, string) {

Callers 1

firewall_rules.goFile · 0.92

Calls 2

GetCurrentDatabaseFunction · 0.85
GetAddonIDFromDatabaseFunction · 0.85

Tested by

no test coverage detected