Skip to content

Commit

Permalink
chore(dump): Create help text example filename inline
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Mar 13, 2024
1 parent 5cd90d1 commit 2e4fbe6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 27 deletions.
18 changes: 14 additions & 4 deletions cmd/dump/description.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
package dump

import "github.com/clevyr/kubedb/internal/actions/dump"
import (
"time"

"github.com/clevyr/kubedb/internal/actions/dump"
)

func newDescription() string {
helpFilename := dump.Filename{
Namespace: "clevyr",
Ext: ".sql.gz",
Date: time.Date(2022, 1, 9, 9, 41, 0, 0, time.UTC),
}.Generate()

return `Dump a database to a sql file.
Filenames:
If a filename is provided, and it does not end with a "/", then it will be used verbatim.
Otherwise, the filename will be generated and appended to the given path.
For example, if a dump is performed in the namespace "clevyr" with no extra flags,
the generated filename might look like "` + dump.HelpFilename() + `".
the generated filename might look like "` + helpFilename + `".
Similarly, if the filename is passed as "backups/", then the generated path might look like
"backups/` + dump.HelpFilename() + `".
"backups/` + helpFilename + `".
Cloud Upload:
KubeDB will directly upload the dump to a cloud storage bucket if the output path starts with a URL scheme:
Expand All @@ -20,7 +30,7 @@ Cloud Upload:
Cloud configuration will be loaded from the environment, similarly to the official aws and gcloud tools.
Note the above section on filenames. For example, if the filename is set to "s3://clevyr-backups/dev/",
then the resulting filename might look like "s3://clevyr-backups/dev/` + dump.HelpFilename() + `".
then the resulting filename might look like "s3://clevyr-backups/dev/` + helpFilename + `".
The only exception is if a bucket name is provided without any sub-path (like "s3://backups"), then
the generated filename will be appended without requiring an ending "/".
`
Expand Down
8 changes: 0 additions & 8 deletions internal/actions/dump/generate_filename.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,3 @@ func (vars Filename) Generate() string {
result += vars.Date.Format(DateFormat) + vars.Ext
return result
}

func HelpFilename() string {
return Filename{
Namespace: "clevyr",
Ext: ".sql.gz",
Date: time.Date(2022, 1, 9, 9, 41, 0, 0, time.UTC),
}.Generate()
}
15 changes: 0 additions & 15 deletions internal/actions/dump/generate_filename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,3 @@ func TestFilename_Generate(t *testing.T) {
})
}
}

func TestHelpFilename(t *testing.T) {
tests := []struct {
name string
want string
}{
{"default", "clevyr_2022-01-09_094100.sql.gz"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := HelpFilename()
assert.Equal(t, tt.want, got)
})
}
}

0 comments on commit 2e4fbe6

Please sign in to comment.