Skip to content

Commit

Permalink
Worked on tmp directory paths and command line for validation.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnbdz committed Aug 17, 2024
1 parent b31774f commit fd0d07c
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 153 deletions.
26 changes: 8 additions & 18 deletions collection/cmd/init.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package cmd

import (
"fmt"
"github.com/AmadlaOrg/hery/collection/validation"
"github.com/AmadlaOrg/hery/storage"
"github.com/spf13/cobra"
"log"
"os"
)

var InitCmd = &cobra.Command{
Expand All @@ -18,33 +16,25 @@ var InitCmd = &cobra.Command{
log.Fatal("Missing collection name.")
}

arg := args[0]
collectionName := args[0]

// Validate the collection name that is pass in `arg`
if validation.Name(arg) {
if validation.Name(collectionName) {
log.Fatal("Collection name is required or is in the wrong format.")
}

// Retrieve storage path
storageService := storage.NewStorageService()
storagePath, err := storageService.Main()
paths, err := storageService.Paths(collectionName)
if err != nil {
log.Fatal(err)
}

// Full path to the target directory
targetDir := fmt.Sprintf("%s/%s", storagePath, arg)

// Check if the directory exists
if _, err := os.Stat(targetDir); os.IsNotExist(err) {
// Create the directory
err = os.MkdirAll(fmt.Sprintf("%s/entity", targetDir), os.ModePerm)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Directory '%s' with subdirectory 'entity' created.\n", targetDir)
} else {
fmt.Printf("Directory '%s' already exists.\n", targetDir)
err = storageService.MakePaths(*paths)
if err != nil {
return
}

log.Printf("Collection '%s' created within the storage: '%s'.", collectionName, paths.Storage)
},
}
15 changes: 11 additions & 4 deletions entity/cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"github.com/AmadlaOrg/hery/entity"
"github.com/AmadlaOrg/hery/entity/get"
entityValidation "github.com/AmadlaOrg/hery/entity/validation"
"github.com/AmadlaOrg/hery/storage"
"github.com/spf13/cobra"
Expand All @@ -25,6 +24,12 @@ var ValidateCmd = &cobra.Command{
log.Fatal(err)
}
return
} else if isValidateAll && isRm {
err := cmd.Help()
if err != nil {
log.Fatal(err)
}
return
}

concoct(cmd, args, func(collectionName string, paths *storage.AbsPaths, args []string) {
Expand All @@ -38,8 +43,10 @@ var ValidateCmd = &cobra.Command{
log.Fatal("too many entity URIs (the limit is 60)")
}

storageService := storage.NewStorageService()

// Replace paths with temporary directory before .<collectionName>
newPaths, err := storage.ReplaceWithTempDir(paths, collectionName)
newPaths, err := storageService.TmpPaths(collectionName)
if err != nil {
println("error")
log.Fatal(err)
Expand All @@ -55,11 +62,11 @@ var ValidateCmd = &cobra.Command{
println(newPaths.Entities)
println(newPaths.Cache)

getService := get.NewGetService()
/*getService := get.NewGetService()
err = getService.Get(collectionName, paths, args)
if err != nil {
log.Fatalf("Error getting entity: %s", err)
}
}*/
}

println(args)
Expand Down
159 changes: 159 additions & 0 deletions storage/mock_Storage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit fd0d07c

Please sign in to comment.