Skip to content

Commit

Permalink
refactoring : CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
heedaeshin committed Sep 6, 2024
1 parent dde3d56 commit dc4371c
Show file tree
Hide file tree
Showing 86 changed files with 995 additions and 355,953 deletions.
20 changes: 10 additions & 10 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Semi-structured data: json, xml
You must enter the data size in GB.`,
Run: func(_ *cobra.Command, _ []string) {
logrus.SetFormatter(&log.CustomTextFormatter{CmdName: "create", JobName: "dummy create"})
if err := execfunc.DummyCreate(datamoldParams); err != nil {
if err := execfunc.DummyCreate(commandTask); err != nil {
logrus.Errorf("dummy create failed : %v", err)
}
},
Expand All @@ -46,15 +46,15 @@ You must enter the data size in GB.`,
func init() {
rootCmd.AddCommand(createCmd)

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

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")
createCmd.Flags().StringVarP(&commandTask.SizeSQL, "sql-size", "s", "0", "Total size of sql files")
createCmd.Flags().StringVarP(&commandTask.SizeCSV, "csv-size", "c", "0", "Total size of csv files")
createCmd.Flags().StringVarP(&commandTask.SizeJSON, "json-size", "j", "0", "Total size of json files")
createCmd.Flags().StringVarP(&commandTask.SizeXML, "xml-size", "x", "0", "Total size of xml files")
createCmd.Flags().StringVarP(&commandTask.SizeTXT, "txt-size", "t", "0", "Total size of txt files")
createCmd.Flags().StringVarP(&commandTask.SizePNG, "png-size", "p", "0", "Total size of png files")
createCmd.Flags().StringVarP(&commandTask.SizeGIF, "gif-size", "g", "0", "Total size of gif files")
createCmd.Flags().StringVarP(&commandTask.SizeZIP, "zip-size", "z", "0", "Total size of zip files")
}
23 changes: 11 additions & 12 deletions cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,31 @@ import (
// deleteCmd represents the delete command
var deleteCmd = &cobra.Command{
Use: "delete",
Short: "Delete dummy data",
Short: "Delete local data",
Long: `Delete unstructured, semi-structured, and structured data,
which are CSP or local dummy data`,
}

var deleteDummyCmd = &cobra.Command{
Use: "dummy",
var deleteLocalCmd = &cobra.Command{
Use: "local",

Run: func(cmd *cobra.Command, args []string) {
logrus.SetFormatter(&log.CustomTextFormatter{CmdName: "delete"})
logrus.WithFields(logrus.Fields{"jobName": "dummy delete"}).Info("start deleting dummy")
logrus.WithFields(logrus.Fields{"jobName": "local delete"}).Info("start deleting local data")

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

},
}

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

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")
deleteLocalCmd.Flags().StringVarP(&commandTask.Directory, "dst-path", "d", "", "Delete data in directory paths")
deleteLocalCmd.MarkFlagRequired("dst-path")
}
7 changes: 3 additions & 4 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ var exportCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(exportCmd)

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")
exportCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
exportCmd.PersistentFlags().StringVarP(&commandTask.Directory, "dst-path", "d", "", "Directory path to export data")
exportCmd.MarkFlagsRequiredTogether("task-file-path", "dst-path")
}
7 changes: 3 additions & 4 deletions cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ var importCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(importCmd)

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")
importCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
importCmd.PersistentFlags().StringVarP(&commandTask.Directory, "dst-path", "d", "", "Destination path where dummy data exists")
importCmd.MarkFlagsRequiredTogether("task-file-path", "dst-path")
}
5 changes: 2 additions & 3 deletions cmd/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ var migrationCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(migrationCmd)
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")
migrationCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
migrationCmd.MarkFlagRequired("task-file-path")
}
31 changes: 17 additions & 14 deletions cmd/nrdbms.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,38 +27,41 @@ var importNRDBCmd = &cobra.Command{
Use: "nrdbms",
Aliases: []string{"ndb"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("nrdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.ImportNRDMFunc(&datamoldParams); err != nil {
auth.PreRun("nrdbms", &commandTask, cmd.Parent().Use)
if err := auth.ImportNRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var exportNRDBCmd = &cobra.Command{
Use: "nrdbms",
Use: "nrdbms",
Aliases: []string{"ndb"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("nrdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.ExportNRDMFunc(&datamoldParams); err != nil {
auth.PreRun("nrdbms", &commandTask, cmd.Parent().Use)
if err := auth.ExportNRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var migrationNRDBCmd = &cobra.Command{
Use: "nrdbms",
Use: "nrdbms",
Aliases: []string{"ndb"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("nrdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.MigrationNRDMFunc(&datamoldParams); err != nil {
auth.PreRun("nrdbms", &commandTask, cmd.Parent().Use)
if err := auth.MigrationNRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var deleteNRDBMSCmd = &cobra.Command{
Use: "nrdbms",
Use: "nrdbms",
Aliases: []string{"ndb"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("nrdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.DeleteNRDMFunc(&datamoldParams); err != nil {
auth.PreRun("nrdbms", &commandTask, cmd.Parent().Use)
if err := auth.DeleteNRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -70,7 +73,7 @@ func init() {
migrationCmd.AddCommand(migrationNRDBCmd)
deleteCmd.AddCommand(deleteNRDBMSCmd)

deleteNRDBMSCmd.Flags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
deleteNRDBMSCmd.Flags().StringArrayVarP(&datamoldParams.DeleteTableList, "delete-table-list", "D", []string{}, "List of table names to delete")
deleteNRDBMSCmd.MarkFlagsRequiredTogether("credential-path", "delete-table-list")
deleteNRDBMSCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
deleteNRDBMSCmd.Flags().StringArrayVarP(&commandTask.DeleteTableList, "delete-table-list", "D", []string{}, "List of table names to delete")
deleteNRDBMSCmd.MarkFlagsRequiredTogether("task-file-path", "delete-table-list")
}
32 changes: 18 additions & 14 deletions cmd/objectstorage.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,44 @@ import (
)

var importOSCmd = &cobra.Command{
Use: "objectstorage",
Use: "objectstorage",
Aliases: []string{"obj"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("objectstorage", &datamoldParams, cmd.Parent().Use)
if err := auth.ImportOSFunc(&datamoldParams); err != nil {
auth.PreRun("objectstorage", &commandTask, cmd.Parent().Use)
if err := auth.ImportOSFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var exportOSCmd = &cobra.Command{
Use: "objectstorage",
Use: "objectstorage",
Aliases: []string{"obj"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("objectstorage", &datamoldParams, cmd.Parent().Use)
if err := auth.ExportOSFunc(&datamoldParams); err != nil {
auth.PreRun("objectstorage", &commandTask, cmd.Parent().Use)
if err := auth.ExportOSFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var migrationOSCmd = &cobra.Command{
Use: "objectstorage",
Use: "objectstorage",
Aliases: []string{"obj"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("objectstorage", &datamoldParams, cmd.Parent().Use)
if err := auth.MigrationOSFunc(&datamoldParams); err != nil {
auth.PreRun("objectstorage", &commandTask, cmd.Parent().Use)
if err := auth.MigrationOSFunc(&commandTask); err != nil {
os.Exit(1)
}
},
}

var deleteOSCmd = &cobra.Command{
Use: "objectstorage",
Use: "objectstorage",
Aliases: []string{"obj"},
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("objectstorage", &datamoldParams, cmd.Parent().Use)
if err := auth.DeleteOSFunc(&datamoldParams); err != nil {
auth.PreRun("objectstorage", &commandTask, cmd.Parent().Use)
if err := auth.DeleteOSFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -68,6 +72,6 @@ func init() {
migrationCmd.AddCommand(migrationOSCmd)
deleteCmd.AddCommand(deleteOSCmd)

deleteOSCmd.Flags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
deleteOSCmd.MarkFlagRequired("credential-path")
deleteOSCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
deleteOSCmd.MarkFlagRequired("task-file-path")
}
22 changes: 11 additions & 11 deletions cmd/rdbms.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
var importRDBCmd = &cobra.Command{
Use: "rdbms",
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("rdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.ImportRDMFunc(&datamoldParams); err != nil {
auth.PreRun("rdbms", &commandTask, cmd.Parent().Use)
if err := auth.ImportRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -36,8 +36,8 @@ var importRDBCmd = &cobra.Command{
var exportRDBCmd = &cobra.Command{
Use: "rdbms",
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("rdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.ExportRDMFunc(&datamoldParams); err != nil {
auth.PreRun("rdbms", &commandTask, cmd.Parent().Use)
if err := auth.ExportRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -46,8 +46,8 @@ var exportRDBCmd = &cobra.Command{
var migrationRDBCmd = &cobra.Command{
Use: "rdbms",
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("rdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.MigrationRDMFunc(&datamoldParams); err != nil {
auth.PreRun("rdbms", &commandTask, cmd.Parent().Use)
if err := auth.MigrationRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -56,8 +56,8 @@ var migrationRDBCmd = &cobra.Command{
var deleteRDBMSCmd = &cobra.Command{
Use: "rdbms",
Run: func(cmd *cobra.Command, args []string) {
auth.PreRun("rdbms", &datamoldParams, cmd.Parent().Use)
if err := auth.DeleteRDMFunc(&datamoldParams); err != nil {
auth.PreRun("rdbms", &commandTask, cmd.Parent().Use)
if err := auth.DeleteRDMFunc(&commandTask); err != nil {
os.Exit(1)
}
},
Expand All @@ -69,7 +69,7 @@ func init() {
migrationCmd.AddCommand(migrationRDBCmd)
deleteCmd.AddCommand(deleteRDBMSCmd)

deleteRDBMSCmd.Flags().StringVarP(&datamoldParams.CredentialPath, "credential-path", "C", "", "Json file path containing the user's credentials")
deleteRDBMSCmd.Flags().StringArrayVarP(&datamoldParams.DeleteDBList, "delete-db-list", "D", []string{}, "List of db names to delete")
deleteRDBMSCmd.MarkFlagsRequiredTogether("credential-path", "delete-db-list")
deleteRDBMSCmd.PersistentFlags().StringVarP(&commandTask.TaskFilePath, "task-file-path", "f", "task.json", "Json file path containing the user's task")
deleteRDBMSCmd.Flags().StringArrayVarP(&commandTask.DeleteDBList, "delete-db-list", "D", []string{}, "List of db names to delete")
deleteRDBMSCmd.MarkFlagsRequiredTogether("task-file-path", "delete-db-list")
}
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ package cmd
import (
"os"

"github.com/cloud-barista/mc-data-manager/internal/auth"
"github.com/cloud-barista/mc-data-manager/internal/log"
"github.com/cloud-barista/mc-data-manager/models"
"github.com/spf13/cobra"
)

var datamoldParams auth.DatamoldParams
var commandTask models.CommandTask

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Expand Down
20 changes: 10 additions & 10 deletions cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var testCmd = &cobra.Command{
Long: `test-command`,
Run: func(_ *cobra.Command, _ []string) {
logrus.SetFormatter(&log.CustomTextFormatter{CmdName: "test", JobName: "test dummy create"})
if err := execfunc.DummyCreate(datamoldParams); err != nil {
if err := execfunc.DummyCreate(commandTask); err != nil {
logrus.Errorf("test dummy create failed : %v", err)
}
},
Expand All @@ -38,15 +38,15 @@ var testCmd = &cobra.Command{
func init() {
rootCmd.AddCommand(testCmd)

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

testCmd.Flags().IntVarP(&datamoldParams.SqlSize, "sql-size", "s", 0, "Total size of sql files")
testCmd.Flags().IntVarP(&datamoldParams.CsvSize, "csv-size", "c", 0, "Total size of csv files")
testCmd.Flags().IntVarP(&datamoldParams.JsonSize, "json-size", "j", 0, "Total size of json files")
testCmd.Flags().IntVarP(&datamoldParams.XmlSize, "xml-size", "x", 0, "Total size of xml files")
testCmd.Flags().IntVarP(&datamoldParams.TxtSize, "txt-size", "t", 0, "Total size of txt files")
testCmd.Flags().IntVarP(&datamoldParams.PngSize, "png-size", "p", 0, "Total size of png files")
testCmd.Flags().IntVarP(&datamoldParams.GifSize, "gif-size", "g", 0, "Total size of gif files")
testCmd.Flags().IntVarP(&datamoldParams.ZipSize, "zip-size", "z", 0, "Total size of zip files")
testCmd.Flags().StringVarP(&commandTask.SizeSQL, "sql-size", "s", "0", "Total size of sql files")
testCmd.Flags().StringVarP(&commandTask.SizeCSV, "csv-size", "c", "0", "Total size of csv files")
testCmd.Flags().StringVarP(&commandTask.SizeJSON, "json-size", "j", "0", "Total size of json files")
testCmd.Flags().StringVarP(&commandTask.SizeXML, "xml-size", "x", "0", "Total size of xml files")
testCmd.Flags().StringVarP(&commandTask.SizeTXT, "txt-size", "t", "0", "Total size of txt files")
testCmd.Flags().StringVarP(&commandTask.SizePNG, "png-size", "p", "0", "Total size of png files")
testCmd.Flags().StringVarP(&commandTask.SizeGIF, "gif-size", "g", "0", "Total size of gif files")
testCmd.Flags().StringVarP(&commandTask.SizeZIP, "zip-size", "z", "0", "Total size of zip files")
}
Loading

0 comments on commit dc4371c

Please sign in to comment.