cleaning up manager, tying it to add files
This commit is contained in:
BIN
client/.gvc/gvc.db
Normal file
BIN
client/.gvc/gvc.db
Normal file
Binary file not shown.
6
client/.gvc/gvclog.log
Normal file
6
client/.gvc/gvclog.log
Normal file
@@ -0,0 +1,6 @@
|
||||
{"level":"warn","module":"database","message":"No existing databse found. initialising new database"}
|
||||
{"level":"info","message":"Creating new Manager..."}
|
||||
{"level":"info","message":"Creating new Manager..."}
|
||||
{"level":"warn","module":"database","message":"no file found"}
|
||||
{"level":"info","message":"The file was [not found], so continuing to create it in the database"}
|
||||
{"level":"info","message":"added file: client.go at path: client.go with hash: \ufffd\ufffd\u0001{\ufffd[Ȼ[8\ufffdR!\ufffd\ufffdB at time: %!s(func() string=0x68c5b0)"}
|
@@ -11,7 +11,7 @@ import (
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
config "github.com/deranjer/gvc/client/clientconfig"
|
||||
"github.com/deranjer/gvc/common"
|
||||
"github.com/deranjer/gvc/common/database"
|
||||
"github.com/deranjer/gvc/common/manager"
|
||||
"github.com/deranjer/store"
|
||||
"github.com/rs/zerolog"
|
||||
)
|
||||
@@ -30,9 +30,9 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("Can't get working dir, permissions issue? %s", err)
|
||||
}
|
||||
|
||||
// Setting up a blank config to read the .toml file in if one exists
|
||||
var conf clientconfig.Gvcconfig
|
||||
var m *manager.Manager
|
||||
isRepo := validateRepo()
|
||||
if isRepo { // If repo folder exists, treat it like a repo and setup logging and database. If not a repo will not need any of this
|
||||
err := store.Load(configPath, &conf)
|
||||
@@ -60,7 +60,15 @@ func main() {
|
||||
clientlog := zerolog.New(logFile)
|
||||
clientlog.WithLevel(logLevel)
|
||||
// Check/Setup the database with logging
|
||||
database.NewDB(".gvc/gvc.db", &clientlog)
|
||||
//db, err := database.OpenOrCreateDB(".gvc/gvc.db", &clientlog)
|
||||
//if err != nil {
|
||||
// clientlog.Fatal().Msgf("Unable to open or create a database in the .gvc folder, fatal")
|
||||
//}
|
||||
informer := make(chan manager.OperatingMessage)
|
||||
m, err = manager.NewManager(rootPath, version, ".gvc/gvc.db", informer, &clientlog)
|
||||
if err != nil {
|
||||
clientlog.Fatal().Msgf("unable to create new manager object... %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize our new cli
|
||||
@@ -70,7 +78,7 @@ func main() {
|
||||
initCommand(cli, &conf)
|
||||
|
||||
// Adding all the "add" commands
|
||||
addCommands(cli, &conf)
|
||||
addCommands(cli, &conf, m)
|
||||
|
||||
// Adding the ignore commands
|
||||
ignoreCommands(cli, &conf)
|
||||
@@ -162,7 +170,7 @@ func initCommand(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
})
|
||||
}
|
||||
|
||||
func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig, m *manager.Manager) {
|
||||
//All the add commands and subcommands
|
||||
//The add subcommand
|
||||
addCmd := cli.NewSubCommand("add", "adds file(s)/folder(s) (recursively for folder) to repo")
|
||||
@@ -189,7 +197,7 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
}
|
||||
if file != "" { // if the file flag was used it won't be empty
|
||||
fmt.Println("adding file to tracked files: ", file)
|
||||
err := clientcmd.AddFiles(file, "file", conf.Ignores)
|
||||
err := clientcmd.AddFiles(file, "file", conf.Ignores, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -197,7 +205,7 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
}
|
||||
if folder != "" { // if the folder flag was used it won't be empty
|
||||
fmt.Println("adding contents of folder to tracked files: ", folder)
|
||||
err := clientcmd.AddFiles(folder, "folder", conf.Ignores)
|
||||
err := clientcmd.AddFiles(folder, "folder", conf.Ignores, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -205,7 +213,7 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
}
|
||||
if wildcard != "" { // if the wildcard flag was used it won't be empty
|
||||
fmt.Println("adding files with wildcard filter: ", wildcard)
|
||||
err := clientcmd.AddFiles(wildcard, "wildcard", conf.Ignores)
|
||||
err := clientcmd.AddFiles(wildcard, "wildcard", conf.Ignores, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -227,7 +235,7 @@ func addCommands(cli *clir.Cli, conf *clientconfig.Gvcconfig) {
|
||||
return fmt.Errorf("the 'all' subcommand does not accept additional arguments")
|
||||
}
|
||||
fmt.Println("adding all files recursively in directory to tracked files")
|
||||
err := clientcmd.AddFiles("", "all", conf.Ignores)
|
||||
err := clientcmd.AddFiles("", "all", conf.Ignores, m)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -7,10 +7,11 @@ import (
|
||||
|
||||
clientconfig "github.com/deranjer/gvc/client/clientconfig"
|
||||
"github.com/deranjer/gvc/common"
|
||||
"github.com/deranjer/gvc/common/manager"
|
||||
)
|
||||
|
||||
//AddFiles adds files to the repo, inputType specifies file, folder, wildcard or all
|
||||
func AddFiles(input string, inputType string, ignore common.FileTypes) error {
|
||||
func AddFiles(input string, inputType string, ignore common.FileTypes, m *manager.Manager) error {
|
||||
err := validateFileType(input, inputType) // Making sure that if the file flag was used a folder was not supplied and vice versa
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -30,9 +31,17 @@ func AddFiles(input string, inputType string, ignore common.FileTypes) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add file as it (or ext) is on the ignores list %s", input)
|
||||
}
|
||||
relativePath, err := filepath.Rel(workingDir, input)
|
||||
// absolute := filepath.IsAbs(input)
|
||||
// if absolute {
|
||||
// relativePath, err := filepath.Rel(workingDir, input)
|
||||
// if err != nil {
|
||||
// return fmt.Errorf("unable to create relative path for file: %s", err)
|
||||
// }
|
||||
// }
|
||||
relativePath := input //TODO: Figure out if path is corrrect?
|
||||
err = m.AddFileToRepo(relativePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create relative path for file: %s", err)
|
||||
return fmt.Errorf("unable to add file to repo: %s", err)
|
||||
}
|
||||
trackedFiles = append(trackedFiles, relativePath)
|
||||
fmt.Println("adding file: ", relativePath)
|
||||
@@ -63,6 +72,10 @@ func AddFiles(input string, inputType string, ignore common.FileTypes) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create relative path for file: %s", err)
|
||||
}
|
||||
err = m.AddFileToRepo(relativePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add file to repo: %s", err)
|
||||
}
|
||||
trackedFiles = append(trackedFiles, relativePath)
|
||||
return nil
|
||||
})
|
||||
@@ -98,6 +111,10 @@ func AddFiles(input string, inputType string, ignore common.FileTypes) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to create relative path for file: %s", err)
|
||||
}
|
||||
err = m.AddFileToRepo(relativePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add file to repo: %s", err)
|
||||
}
|
||||
trackedFiles = append(trackedFiles, relativePath)
|
||||
}
|
||||
return nil
|
||||
@@ -124,6 +141,10 @@ func AddFiles(input string, inputType string, ignore common.FileTypes) error {
|
||||
if relativePath == "." { //Ignoring current directory
|
||||
return nil
|
||||
}
|
||||
err = m.AddFileToRepo(relativePath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to add file to repo: %s", err)
|
||||
}
|
||||
trackedFiles = append(trackedFiles, relativePath)
|
||||
return nil
|
||||
})
|
||||
|
Reference in New Issue
Block a user