From 9b8e6e0c1550d6041490f0c26260ffcf88a589c0 Mon Sep 17 00:00:00 2001 From: Lorenzo Setale Date: Sun, 15 Nov 2020 18:39:45 +0100 Subject: [PATCH] renames Backpack{} to Pack{} Signed-off-by: Lorenzo Setale --- cmd/create.go | 4 ++-- cmd/pack.go | 4 ++-- cmd/plan.go | 2 +- cmd/run.go | 2 +- cmd/unpack.go | 4 ++-- cmd/unpack_docs.go | 2 +- cmd/unpack_values.go | 2 +- cmd/utils.go | 12 ++++++------ pkg/{backpack.go => pack.go} | 8 ++++---- pkg/{backpack_file.go => pack_file.go} | 17 +++++++++-------- ...{backpack_file_test.go => pack_file_test.go} | 6 +++--- pkg/{backpack_pack.go => pack_pack.go} | 8 ++++---- ...{backpack_pack_test.go => pack_pack_test.go} | 4 ++-- pkg/{backpack_unpack.go => pack_unpack.go} | 4 ++-- ...kpack_unpack_test.go => pack_unpack_test.go} | 6 +++--- templating/build.go | 6 +++--- templating/build_test.go | 2 +- test_files/backpack/README.md | 2 +- 18 files changed, 48 insertions(+), 47 deletions(-) rename pkg/{backpack.go => pack.go} (93%) rename pkg/{backpack_file.go => pack_file.go} (71%) rename pkg/{backpack_file_test.go => pack_file_test.go} (77%) rename pkg/{backpack_pack.go => pack_pack.go} (87%) rename pkg/{backpack_pack_test.go => pack_pack_test.go} (87%) rename pkg/{backpack_unpack.go => pack_unpack.go} (84%) rename pkg/{backpack_unpack_test.go => pack_unpack_test.go} (88%) diff --git a/cmd/create.go b/cmd/create.go index a8dcf00..b8a6167 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -35,7 +35,7 @@ func init() { func createRun(cmd *cobra.Command, args []string) { name := args[0] - b := pkg.Backpack{ + b := pkg.Pack{ Name: name, Version: "0.1.0", Dependencies: map[string]string{"TODO": "http://backpack.qm64.com/example.backpack"}, @@ -111,7 +111,7 @@ Have fun! 😄 } } - err = pkg.UnpackBackpackInDirectory(&b, directory) + err = pkg.UnpackInDirectory(&b, directory) if err != nil { log.Fatalf("Error unpacking: %s", err) } diff --git a/cmd/pack.go b/cmd/pack.go index 523c75d..bee05c0 100644 --- a/cmd/pack.go +++ b/cmd/pack.go @@ -40,7 +40,7 @@ func packRun(cmd *cobra.Command, args []string) { log.Fatal(err) } - b, err := pkg.GetBackpackFromDirectory(args[0]) + b, err := pkg.GetPackFromDirectory(args[0]) if err != nil { log.Fatalf("Error generating the backpack from the directory: %s", err) } @@ -51,7 +51,7 @@ func packRun(cmd *cobra.Command, args []string) { writeTo = fileFlag } - err = pkg.WriteBackpackToFile(*b, writeTo) + err = pkg.WritePackToFile(*b, writeTo) if err != nil { log.Fatalf("Error writing to file: %s", err) } diff --git a/cmd/plan.go b/cmd/plan.go index 3a9833a..2d0f41c 100644 --- a/cmd/plan.go +++ b/cmd/plan.go @@ -38,7 +38,7 @@ func init() { // This is the actual command.. func planRun(cmd *cobra.Command, args []string) { - b := getBackpackFromCLIInput(cmd, args) + b := getPackFromCLIInput(cmd, args) var err error client, err := conn.NewClient() diff --git a/cmd/run.go b/cmd/run.go index a39162c..ae37312 100644 --- a/cmd/run.go +++ b/cmd/run.go @@ -33,7 +33,7 @@ func init() { // This is the actual command.. func runRun(cmd *cobra.Command, args []string) { - b := getBackpackFromCLIInput(cmd, args) + b := getPackFromCLIInput(cmd, args) var err error client, err := conn.NewClient() diff --git a/cmd/unpack.go b/cmd/unpack.go index c13ba8f..2a0ddb7 100644 --- a/cmd/unpack.go +++ b/cmd/unpack.go @@ -43,7 +43,7 @@ func init() { func unpackRun(cmd *cobra.Command, args []string) { // get a file from URL or Path p := getAUsablePathOfFile(args[0]) - b, err := pkg.GetBackpackFromFile(p) + b, err := pkg.GetPackFromFile(p) if err != nil { log.Fatalf("Error parsing the backpack: %s", err) } @@ -64,7 +64,7 @@ func unpackRun(cmd *cobra.Command, args []string) { } } - err = pkg.UnpackBackpackInDirectory(&b, directory) + err = pkg.UnpackInDirectory(&b, directory) if err != nil { log.Fatalf("Error unpacking: %s", err) } diff --git a/cmd/unpack_docs.go b/cmd/unpack_docs.go index eb678c2..651ca9c 100644 --- a/cmd/unpack_docs.go +++ b/cmd/unpack_docs.go @@ -36,7 +36,7 @@ func unpackDocsRun(cmd *cobra.Command, args []string) { // get a file from URL or Path p := getAUsablePathOfFile(args[0]) - b, err := pkg.GetBackpackFromFile(p) + b, err := pkg.GetPackFromFile(p) if err != nil { log.Fatalf("Error parsing the backpack: %s", err) } diff --git a/cmd/unpack_values.go b/cmd/unpack_values.go index 524e65f..83ad35a 100644 --- a/cmd/unpack_values.go +++ b/cmd/unpack_values.go @@ -31,7 +31,7 @@ func unpackValuesRun(cmd *cobra.Command, args []string) { // get a file from URL or Path p := getAUsablePathOfFile(args[0]) - b, err := pkg.GetBackpackFromFile(p) + b, err := pkg.GetPackFromFile(p) if err != nil { log.Fatalf("Error parsing the backpack: %s", err) } diff --git a/cmd/utils.go b/cmd/utils.go index 583513a..66fb9e4 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -75,8 +75,8 @@ func getAUsablePathOfFile(v string) string { } } -func getBackpackFromCLIInput(cmd *cobra.Command, args []string) pkg.Backpack { - b := pkg.Backpack{} +func getPackFromCLIInput(cmd *cobra.Command, args []string) pkg.Pack { + b := pkg.Pack{} readFromDir, err := cmd.Flags().GetBool("unpacked") if err != nil { @@ -87,15 +87,15 @@ func getBackpackFromCLIInput(cmd *cobra.Command, args []string) pkg.Backpack { // get a file from URL or Path p := getAUsablePathOfFile(args[0]) - b, err = pkg.GetBackpackFromFile(p) + b, err = pkg.GetPackFromFile(p) if err != nil { - log.Fatalf("Error parsing the backpack: %s", err) + log.Fatalf("Error parsing the pack: %s", err) } } else { // If we have to read from directory instead args[0] is a path - d, err := pkg.GetBackpackFromDirectory(args[0]) + d, err := pkg.GetPackFromDirectory(args[0]) if err != nil { - log.Fatalf("Error parsing the unpacked backpack: %s", err) + log.Fatalf("Error parsing the unpacked pack: %s", err) } b = *d } diff --git a/pkg/backpack.go b/pkg/pack.go similarity index 93% rename from pkg/backpack.go rename to pkg/pack.go index 6dd0bf5..6e97800 100644 --- a/pkg/backpack.go +++ b/pkg/pack.go @@ -7,9 +7,9 @@ import ( "github.com/hashicorp/go-multierror" ) -// Backpack is the structure of the package/file that will use to export, share +// Pack is the structure of the package/file that will use to export, share // exchange templates, docs and configuration -type Backpack struct { +type Pack struct { Name string `yaml:"name"` Version string `yaml:"version"` // Please use semver Dependencies map[string]string `yaml:",omitempty"` // URLs for dependencies? TBD @@ -39,7 +39,7 @@ type Backpack struct { // SortTemplates is used to ensure that files names sorting is respected. // This is useful to define an "order" to follow when applying resources if that // is needed. -func (b *Backpack) SortTemplates() { +func (b *Pack) SortTemplates() { nm := make(FilesMapType, len(b.Templates)) sk := make([]string, 0, len(b.Templates)) @@ -59,7 +59,7 @@ func (b *Backpack) SortTemplates() { } // FilesMapType is useful type to specify what kind of Mapping we are using to -// store files in the backpack. +// store files in the pack. type FilesMapType map[string][]byte func decodeB64FilesMap(ra FilesMapType) (x FilesMapType, err error) { diff --git a/pkg/backpack_file.go b/pkg/pack_file.go similarity index 71% rename from pkg/backpack_file.go rename to pkg/pack_file.go index 36511a2..db8acf2 100644 --- a/pkg/backpack_file.go +++ b/pkg/pack_file.go @@ -7,8 +7,9 @@ import ( "github.com/vmihailenco/msgpack" ) -// GetBackpackFromFile will read and get a Backpack from a file path -func GetBackpackFromFile(path string) (b Backpack, err error) { +// GetPackFromFile will read and get a Pack from a file path and return as a +// Pack struct +func GetPackFromFile(path string) (b Pack, err error) { bb, err := ioutil.ReadFile(path) if err != nil { return @@ -16,33 +17,33 @@ func GetBackpackFromFile(path string) (b Backpack, err error) { err = msgpack.Unmarshal(bb, &b) if err != nil { - return Backpack{}, err + return Pack{}, err } // Decode Templates to Base64 b.Templates, err = decodeB64FilesMap(b.Templates) if err != nil { - return Backpack{}, err + return Pack{}, err } b.SortTemplates() // Decode Documentation b.Documentation, err = decodeB64FilesMap(b.Documentation) if err != nil { - return Backpack{}, err + return Pack{}, err } // Decode Default Values b.DefaultValues, err = base64.StdEncoding.DecodeString(string(b.DefaultValues)) if err != nil { - return Backpack{}, err + return Pack{}, err } return } -// WriteBackpackToFile will write a Backpack to file -func WriteBackpackToFile(b Backpack, path string) (err error) { +// WritePackToFile will write a Pack to file +func WritePackToFile(b Pack, path string) (err error) { // Encode to base64 b.Templates, _ = encodeB64FilesMap(b.Templates) b.Documentation, _ = encodeB64FilesMap(b.Documentation) diff --git a/pkg/backpack_file_test.go b/pkg/pack_file_test.go similarity index 77% rename from pkg/backpack_file_test.go rename to pkg/pack_file_test.go index 517a4c2..72b0c34 100644 --- a/pkg/backpack_file_test.go +++ b/pkg/pack_file_test.go @@ -6,20 +6,20 @@ import ( "testing" ) -func TestBackpackWrite(t *testing.T) { +func TestPackWrite(t *testing.T) { tmpFile, err := ioutil.TempFile(os.TempDir(), "backpack-") defer os.Remove(tmpFile.Name()) if err != nil { t.Fatal(err) } - b := Backpack{ + b := Pack{ Name: "hello-world", Version: "0.1.0", DefaultValues: []byte(`datacenters: ["dc1", "dc2"]`), } - err = WriteBackpackToFile(b, tmpFile.Name()) + err = WritePackToFile(b, tmpFile.Name()) if err != nil { t.Error(err) } diff --git a/pkg/backpack_pack.go b/pkg/pack_pack.go similarity index 87% rename from pkg/backpack_pack.go rename to pkg/pack_pack.go index 082423d..c2eb1e0 100644 --- a/pkg/backpack_pack.go +++ b/pkg/pack_pack.go @@ -35,10 +35,10 @@ func getAllFileWithExtension(ext, basePath string) (FilesMapType, error) { return tempMap, nil } -// GetBackpackFromDirectory will look in a given path for backpack.yaml and .nomad -// files to Backpack them together. -func GetBackpackFromDirectory(dirPath string) (b *Backpack, err error) { - b = &Backpack{} +// GetPackFromDirectory will look in a given path for backpack.yaml and .nomad +// files to pack them together in a Pack struct. +func GetPackFromDirectory(dirPath string) (b *Pack, err error) { + b = &Pack{} // Get the backpack.yaml file bpBytes, err := ioutil.ReadFile(filepath.Join(dirPath, "backpack.yaml")) diff --git a/pkg/backpack_pack_test.go b/pkg/pack_pack_test.go similarity index 87% rename from pkg/backpack_pack_test.go rename to pkg/pack_pack_test.go index 9ba6339..1ac1588 100644 --- a/pkg/backpack_pack_test.go +++ b/pkg/pack_pack_test.go @@ -9,13 +9,13 @@ import ( "gopkg.in/yaml.v2" ) -func TestBackpackPackDirectory(t *testing.T) { +func TestPackPackDirectory(t *testing.T) { // extract the test file name _, filename, _, _ := runtime.Caller(0) bundlePackageGoDir := filepath.Dir(filename) bundleTestDirPath := filepath.Join(bundlePackageGoDir, "../test_files/backpack/") - b, err := GetBackpackFromDirectory(bundleTestDirPath) + b, err := GetPackFromDirectory(bundleTestDirPath) assert.NoError(t, err) assert.Equal(t, "redis", b.Name) diff --git a/pkg/backpack_unpack.go b/pkg/pack_unpack.go similarity index 84% rename from pkg/backpack_unpack.go rename to pkg/pack_unpack.go index 854bac0..926eace 100644 --- a/pkg/backpack_unpack.go +++ b/pkg/pack_unpack.go @@ -8,8 +8,8 @@ import ( "gopkg.in/yaml.v2" ) -// UnpackBackpackInDirectory will write the Backpack's backpack into a directory. -func UnpackBackpackInDirectory(b *Backpack, dirPath string) (err error) { +// UnpackInDirectory will extract files of a pack into a directory. +func UnpackInDirectory(b *Pack, dirPath string) (err error) { // Unpack Templates for n, f := range b.Templates { terr := ioutil.WriteFile(filepath.Join(dirPath, n), f, 0744) diff --git a/pkg/backpack_unpack_test.go b/pkg/pack_unpack_test.go similarity index 88% rename from pkg/backpack_unpack_test.go rename to pkg/pack_unpack_test.go index 827c4b4..8f62234 100644 --- a/pkg/backpack_unpack_test.go +++ b/pkg/pack_unpack_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/assert" ) -func TestBackpackUnpack(t *testing.T) { +func TestPackUnpack(t *testing.T) { // extract the test file name _, filename, _, _ := runtime.Caller(0) bundlePackageGoDir := filepath.Dir(filename) @@ -22,11 +22,11 @@ func TestBackpackUnpack(t *testing.T) { assert.NoError(t, err) // Get the bundle - b, err := GetBackpackFromFile(filepath.Join(bundleTestDirPath, "redis.backpack")) + b, err := GetPackFromFile(filepath.Join(bundleTestDirPath, "redis.backpack")) assert.NoError(t, err) t.Logf("Temp dir: %s", tempDir) - err = UnpackBackpackInDirectory(&b, tempDir) + err = UnpackInDirectory(&b, tempDir) assert.NoError(t, err) expectations := map[string]string{ diff --git a/templating/build.go b/templating/build.go index 05e7154..5b847ac 100644 --- a/templating/build.go +++ b/templating/build.go @@ -12,9 +12,9 @@ import ( "gitlab.com/qm64/backpack/pkg" ) -// BuildHCL will gather the Backpack templates, the default values and -// custom values to generate proper HCL that can be sent to nomad -func BuildHCL(bpk *pkg.Backpack, cv pkg.ValuesType) (o map[string][]byte, err error) { +// BuildHCL will gather the pack templates, the default values and custom values +// to generate proper HCL that can be sent to nomad +func BuildHCL(bpk *pkg.Pack, cv pkg.ValuesType) (o map[string][]byte, err error) { // Get the default map properly from the raw bytes that contains comments dvm := map[string]interface{}{} err = yaml.Unmarshal(bpk.DefaultValues, dvm) diff --git a/templating/build_test.go b/templating/build_test.go index 16bbb64..408b1e3 100644 --- a/templating/build_test.go +++ b/templating/build_test.go @@ -8,7 +8,7 @@ import ( ) func TestBuildHCL(t *testing.T) { - bp := pkg.Backpack{ + bp := pkg.Pack{ Name: "test-backpack", Version: "0.1.0", Templates: map[string][]byte{ diff --git a/test_files/backpack/README.md b/test_files/backpack/README.md index 26cde11..260bf74 100644 --- a/test_files/backpack/README.md +++ b/test_files/backpack/README.md @@ -1,3 +1,3 @@ # Documentation -The documentation for this backpack is also part of the test! \ No newline at end of file +The documentation for this pack is also part of the test! \ No newline at end of file