Compare commits
5 Commits
v0.17.0
...
export_fun
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
02b8692d7f | ||
|
|
02f7b2006a | ||
|
|
ae676258ac | ||
|
|
dbe5639fd0 | ||
|
|
65040f9fb6 |
27
cmd/qliksense/export.go
Normal file
27
cmd/qliksense/export.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/qlik-oss/sense-installer/pkg/qliksense"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func exportCmd(q *qliksense.Qliksense) *cobra.Command {
|
||||
filePath := q.QliksenseHome
|
||||
c := &cobra.Command{
|
||||
Use: "export",
|
||||
Short: "export files for corresponding context",
|
||||
Long: `exports all context files in zip format`,
|
||||
Example: `qliksense export <context_name>`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
if len(args) != 0 {
|
||||
context := args[0]
|
||||
return q.ExportContext(context, filePath)
|
||||
}
|
||||
return nil
|
||||
},
|
||||
}
|
||||
f := c.Flags()
|
||||
f.StringVarP(&filePath, "output", "o", "", "Output Directory")
|
||||
return c
|
||||
}
|
||||
@@ -202,6 +202,9 @@ func rootCmd(p *qliksense.Qliksense) *cobra.Command {
|
||||
// add uninstall command
|
||||
cmd.AddCommand(uninstallCmd(p))
|
||||
|
||||
// add export command
|
||||
cmd.AddCommand(exportCmd(p))
|
||||
|
||||
// add crds
|
||||
cmd.AddCommand(crdsCmd)
|
||||
crdsCmd.AddCommand(crdsViewCmd(p))
|
||||
|
||||
71
pkg/qliksense/export.go
Normal file
71
pkg/qliksense/export.go
Normal file
@@ -0,0 +1,71 @@
|
||||
package qliksense
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (q *Qliksense) ExportContext(context string, output string) error {
|
||||
qliksenseContextsDir := filepath.Join(q.QliksenseHome, QliksenseContextsDir)
|
||||
qliksenseContextFile := filepath.Join(qliksenseContextsDir, context)
|
||||
qliksenseSecretsDir := filepath.Join(q.QliksenseHome, QliksenseSecretsDir, QliksenseContextsDir)
|
||||
qliksenseSecretsFile := filepath.Join(qliksenseSecretsDir, context)
|
||||
// files := []string{qliksenseContextFile, qliksenseSecretsFile}
|
||||
|
||||
fmt.Println(q.QliksenseHome)
|
||||
fmt.Println(qliksenseSecretsFile)
|
||||
fmt.Println(qliksenseContextFile)
|
||||
|
||||
filename := "result.zip"
|
||||
destinationFile, err := os.Create(output + "/" + filename)
|
||||
var folders []string
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
folders = append(folders, qliksenseContextFile, qliksenseSecretsFile)
|
||||
if err := RecursiveZip(folders, destinationFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RecursiveZip(pathToZip []string, destinationFile *os.File) error {
|
||||
s myZip := zip.NewWriter(destinationFile)
|
||||
for _, element := range pathToZip {
|
||||
err := filepath.Walk(element, func(filePath string, info os.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
relPath := strings.TrimPrefix(filePath, element)
|
||||
zipFile, err := myZip.Create(relPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fsFile, err := os.Open(filePath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = io.Copy(zipFile, fsFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})xs
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
err := myZip.Close()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user