Skip to content

Commit

Permalink
Merge pull request #30 from cloud-barista/develop
Browse files Browse the repository at this point in the history
Merge `develop` branch into `main` branch
  • Loading branch information
yunkon-kim authored Nov 23, 2023
2 parents da31a05 + 2a9a85a commit 2453053
Show file tree
Hide file tree
Showing 62 changed files with 1,767 additions and 1,745 deletions.
739 changes: 0 additions & 739 deletions cmd/base.go

This file was deleted.

102 changes: 15 additions & 87 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ limitations under the License.
package cmd

import (
"github.com/cloud-barista/cm-data-mold/internal/logformatter"
"github.com/cloud-barista/cm-data-mold/pkg/dummy/semistructed"
"github.com/cloud-barista/cm-data-mold/pkg/dummy/structed"
"github.com/cloud-barista/cm-data-mold/pkg/dummy/unstructed"
"github.com/cloud-barista/cm-data-mold/internal/execfunc"
"github.com/cloud-barista/cm-data-mold/internal/log"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -37,96 +35,26 @@ Unstructured data: png,gif,txt,zip
Semi-structured data: json, xml
You must enter the data size in GB.`,
RunE: func(_ *cobra.Command, _ []string) error {
logrus.SetFormatter(&logformatter.CustomTextFormatter{CmdName: "create", JobName: "dummy create"})
logrus.Info("check directory paths")
if sqlSize != 0 {
logrus.Info("start sql generation")
if err := structed.GenerateRandomSQL(dstPath, sqlSize); err != nil {
logrus.Error("failed to generate sql")
return err
}
logrus.Infof("successfully generated sql : %s", dstPath)
Run: func(_ *cobra.Command, _ []string) {
logrus.SetFormatter(&log.CustomTextFormatter{CmdName: "create", JobName: "dummy create"})
if err := execfunc.DummyCreate(datamoldParams); err != nil {
logrus.Errorf("dummy create failed : %v", err)
}

if csvSize != 0 {
logrus.Info("start csv generation")
if err := structed.GenerateRandomCSV(dstPath, csvSize); err != nil {
logrus.Error("failed to generate csv")
return err
}
logrus.Infof("successfully generated csv : %s", dstPath)
}

if jsonSize != 0 {
logrus.Info("start json generation")
if err := semistructed.GenerateRandomJSON(dstPath, jsonSize); err != nil {
logrus.Error("failed to generate json")
return err
}
logrus.Infof("successfully generated json : %s", dstPath)
}

if xmlSize != 0 {
logrus.Info("start xml generation")
if err := semistructed.GenerateRandomXML(dstPath, xmlSize); err != nil {
logrus.Error("failed to generate xml")
return err
}
logrus.Infof("successfully generated xml : %s", dstPath)
}

if txtSize != 0 {
logrus.Info("start txt generation")
if err := unstructed.GenerateRandomTXT(dstPath, txtSize); err != nil {
logrus.Error("failed to generate txt")
return err
}
logrus.Infof("successfully generated txt : %s", dstPath)
}

if pngSize != 0 {
logrus.Info("start png generation")
if err := unstructed.GenerateRandomPNGImage(dstPath, pngSize); err != nil {
logrus.Error("failed to generate png")
return err
}
logrus.Infof("successfully generated png : %s", dstPath)
}

if gifSize != 0 {
logrus.Info("start gif generation")
if err := unstructed.GenerateRandomGIF(dstPath, gifSize); err != nil {
logrus.Error("failed to generate gif")
return err
}
logrus.Infof("successfully generated gif : %s", dstPath)
}

if zipSize != 0 {
logrus.Info("start zip generation")
if err := unstructed.GenerateRandomZIP(dstPath, zipSize); err != nil {
logrus.Error("failed to generate zip")
return err
}
logrus.Infof("successfully generated zip : %s", dstPath)
}
return nil
},
}

func init() {
rootCmd.AddCommand(createCmd)

createCmd.Flags().StringVarP(&dstPath, "dst-path", "d", "", "Directory path to create dummy data")
createCmd.Flags().StringVarP(&datamoldParams.DstPath, "dst-path", "d", "", "Directory path to create dummy data")
createCmd.MarkFlagRequired("dst-path")

createCmd.Flags().IntVarP(&sqlSize, "sql-size", "s", 0, "Total size of sql files")
createCmd.Flags().IntVarP(&csvSize, "csv-size", "c", 0, "Total size of csv files")
createCmd.Flags().IntVarP(&jsonSize, "json-size", "j", 0, "Total size of json files")
createCmd.Flags().IntVarP(&xmlSize, "xml-size", "x", 0, "Total size of xml files")
createCmd.Flags().IntVarP(&txtSize, "txt-size", "t", 0, "Total size of txt files")
createCmd.Flags().IntVarP(&pngSize, "png-size", "p", 0, "Total size of png files")
createCmd.Flags().IntVarP(&gifSize, "gif-size", "g", 0, "Total size of gif files")
createCmd.Flags().IntVarP(&zipSize, "zip-size", "z", 0, "Total size of zip files")
createCmd.Flags().IntVarP(&datamoldParams.SqlSize, "sql-size", "s", 0, "Total size of sql files")
createCmd.Flags().IntVarP(&datamoldParams.CsvSize, "csv-size", "c", 0, "Total size of csv files")
createCmd.Flags().IntVarP(&datamoldParams.JsonSize, "json-size", "j", 0, "Total size of json files")
createCmd.Flags().IntVarP(&datamoldParams.XmlSize, "xml-size", "x", 0, "Total size of xml files")
createCmd.Flags().IntVarP(&datamoldParams.TxtSize, "txt-size", "t", 0, "Total size of txt files")
createCmd.Flags().IntVarP(&datamoldParams.PngSize, "png-size", "p", 0, "Total size of png files")
createCmd.Flags().IntVarP(&datamoldParams.GifSize, "gif-size", "g", 0, "Total size of gif files")
createCmd.Flags().IntVarP(&datamoldParams.ZipSize, "zip-size", "z", 0, "Total size of zip files")
}
20 changes: 10 additions & 10 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package cmd
import (
"os"

"github.com/cloud-barista/cm-data-mold/internal/logformatter"
"github.com/cloud-barista/cm-data-mold/internal/log"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
Expand All @@ -34,24 +34,24 @@ which are CSP or local dummy data`,
var deleteDummyCmd = &cobra.Command{
Use: "dummy",

RunE: func(cmd *cobra.Command, args []string) error {
logrus.SetFormatter(&logformatter.CustomTextFormatter{CmdName: "delete"})
Run: func(cmd *cobra.Command, args []string) {
logrus.SetFormatter(&log.CustomTextFormatter{CmdName: "delete"})
logrus.WithFields(logrus.Fields{"jobName": "dummy delete"}).Info("start deleting dummy")
err := os.RemoveAll(dstPath)
if err != nil {

if err := os.RemoveAll(datamoldParams.DstPath); err != nil {
logrus.WithFields(logrus.Fields{"jobName": "dummy delete"}).Errorf("failed to delete dummy : %v", err)
return err
return
}
logrus.Infof("successfully deleted : %s\n", dstPath)
return nil
logrus.Infof("successfully deleted : %s\n", datamoldParams.DstPath)
return
},
}

func init() {
rootCmd.AddCommand(deleteCmd)
deleteCmd.AddCommand(deleteDummyCmd)

deleteCmd.PersistentFlags().BoolVarP(&taskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
deleteDummyCmd.Flags().StringVarP(&dstPath, "dst-path", "d", "", "Delete data in directory paths")
deleteCmd.PersistentFlags().BoolVarP(&datamoldParams.TaskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
deleteDummyCmd.Flags().StringVarP(&datamoldParams.DstPath, "dst-path", "d", "", "Delete data in directory paths")
deleteDummyCmd.MarkFlagRequired("dst-path")
}
6 changes: 3 additions & 3 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var exportCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(exportCmd)

exportCmd.PersistentFlags().StringVarP(&credentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
exportCmd.PersistentFlags().StringVarP(&dstPath, "dst-path", "d", "", "Directory path to export data")
exportCmd.PersistentFlags().BoolVarP(&taskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
exportCmd.PersistentFlags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
exportCmd.PersistentFlags().StringVarP(&datamoldParams.DstPath, "dst-path", "d", "", "Directory path to export data")
exportCmd.PersistentFlags().BoolVarP(&datamoldParams.TaskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
exportCmd.MarkFlagsRequiredTogether("credential-path", "dst-path")
}
6 changes: 3 additions & 3 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ var importCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(importCmd)

importCmd.PersistentFlags().StringVarP(&credentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
importCmd.PersistentFlags().StringVarP(&dstPath, "dst-path", "d", "", "Destination path where dummy data exists")
importCmd.PersistentFlags().BoolVarP(&taskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
importCmd.PersistentFlags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
importCmd.PersistentFlags().StringVarP(&datamoldParams.DstPath, "dst-path", "d", "", "Destination path where dummy data exists")
importCmd.PersistentFlags().BoolVarP(&datamoldParams.TaskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
importCmd.MarkFlagsRequiredTogether("credential-path", "dst-path")
}
4 changes: 2 additions & 2 deletions cmd/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var migrationCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(migrationCmd)
migrationCmd.PersistentFlags().BoolVarP(&taskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
migrationCmd.PersistentFlags().StringVarP(&credentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
migrationCmd.PersistentFlags().BoolVarP(&datamoldParams.TaskTarget, "task", "T", false, "Select a destination(src, dst) to work with in the credential-path")
migrationCmd.PersistentFlags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
migrationCmd.MarkFlagRequired("credential-path")
}
Loading

0 comments on commit 2453053

Please sign in to comment.